summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-03 02:02:11 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-03 02:04:55 +0100
commit4844262f25a3ff6bd23de05a0a6f84a8e2983d74 (patch)
treefd67b639efcd42d11fae49ac3de5c6352e3aaa0e /src
parent154e6f233af028cf76608d49a3b7ed8de61373d8 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/rfkill/rfkill.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
index 68729b0c0..5a90c778f 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);