[systemd-commits] 2 commits - src/libudev src/rfkill
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Dec 2 17:05:02 PST 2014
src/libudev/libudev-device.c | 7 +++++-
src/rfkill/rfkill.c | 47 +++++++++++++++++++++----------------------
2 files changed, 30 insertions(+), 24 deletions(-)
New commits:
commit 4844262f25a3ff6bd23de05a0a6f84a8e2983d74
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Dec 3 02:02:11 2014 +0100
rfkill: rework how we generate file names from rfkill devices
Generate the file name from ID_PATH plus the rfkill type (wlan,
bluetooth, ...) and ignore the rfkill device name, since it apparently
is not a stable identifier.
Also, ensure that devices disappearing don't result in broken services,
simply exit cleanly.
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
index 68729b0..5a90c77 100644
--- a/src/rfkill/rfkill.c
+++ b/src/rfkill/rfkill.c
@@ -28,8 +28,8 @@
int main(int argc, char *argv[]) {
_cleanup_udev_unref_ struct udev *udev = NULL;
_cleanup_udev_device_unref_ struct udev_device *device = NULL;
- _cleanup_free_ char *saved = NULL, *escaped_name = NULL, *escaped_path_id = NULL;
- const char *name, *path_id;
+ _cleanup_free_ char *saved = NULL, *escaped_type = NULL, *escaped_path_id = NULL;
+ const char *name, *type, *path_id;
int r;
if (argc != 3) {
@@ -55,25 +55,28 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
- errno = 0;
device = udev_device_new_from_subsystem_sysname(udev, "rfkill", argv[2]);
if (!device) {
- if (errno != 0)
- log_error_errno(errno, "Failed to get rfkill device '%s': %m", argv[2]);
- else
- log_oom();
-
- return EXIT_FAILURE;
+ log_debug_errno(errno, "Failed to get rfkill device '%s', ignoring: %m", argv[2]);
+ return EXIT_SUCCESS;
}
name = udev_device_get_sysattr_value(device, "name");
if (!name) {
- log_error("rfkill device has no name?");
- return EXIT_FAILURE;
+ log_error("rfkill device has no name? Ignoring device.");
+ return EXIT_SUCCESS;
+ }
+
+ log_debug("Operating on rfkill device '%s'.", name);
+
+ type = udev_device_get_sysattr_value(device, "type");
+ if (!type) {
+ log_error("rfkill device has no type? Ignoring device.");
+ return EXIT_SUCCESS;
}
- escaped_name = cescape(name);
- if (!escaped_name) {
+ escaped_type = cescape(type);
+ if (!escaped_type) {
log_oom();
return EXIT_FAILURE;
}
@@ -86,9 +89,9 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
- saved = strjoin("/var/lib/systemd/rfkill/", escaped_path_id, ":", escaped_name, NULL);
+ saved = strjoin("/var/lib/systemd/rfkill/", escaped_path_id, ":", escaped_type, NULL);
} else
- saved = strjoin("/var/lib/systemd/rfkill/", escaped_name, NULL);
+ saved = strjoin("/var/lib/systemd/rfkill/", escaped_type, NULL);
if (!saved) {
log_oom();
@@ -102,19 +105,17 @@ int main(int argc, char *argv[]) {
return EXIT_SUCCESS;
r = read_one_line_file(saved, &value);
+ if (r == -ENOENT)
+ return EXIT_SUCCESS;
if (r < 0) {
-
- if (r == -ENOENT)
- return EXIT_SUCCESS;
-
log_error_errno(r, "Failed to read %s: %m", saved);
return EXIT_FAILURE;
}
r = udev_device_set_sysattr_value(device, "soft", value);
if (r < 0) {
- log_error_errno(r, "Failed to write system attribute: %m");
- return EXIT_FAILURE;
+ log_debug_errno(r, "Failed to write 'soft' attribute on rfkill device, ignoring: %m");
+ return EXIT_SUCCESS;
}
} else if (streq(argv[1], "save")) {
@@ -122,8 +123,8 @@ int main(int argc, char *argv[]) {
value = udev_device_get_sysattr_value(device, "soft");
if (!value) {
- log_error_errno(r, "Failed to read system attribute: %m");
- return EXIT_FAILURE;
+ log_debug_errno(r, "Failed to read system attribute, ignoring device: %m");
+ return EXIT_SUCCESS;
}
r = write_string_file(saved, value);
commit 154e6f233af028cf76608d49a3b7ed8de61373d8
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Dec 3 01:59:42 2014 +0100
libudev: set errno properly in all error conditions of udev_device_new_from_syspath()
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index 5f196bd..16ee1f4 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -723,8 +723,13 @@ _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, con
return NULL;
} else {
/* everything else just needs to be a directory */
- if (stat(path, &statbuf) != 0 || !S_ISDIR(statbuf.st_mode))
+ if (stat(path, &statbuf) != 0)
return NULL;
+
+ if (!S_ISDIR(statbuf.st_mode)) {
+ errno = EISDIR;
+ return NULL;
+ }
}
udev_device = udev_device_new(udev);
More information about the systemd-commits
mailing list