[systemd-commits] 3 commits - .gitignore TODO rules/99-systemd.rules.in src/backlight src/rfkill

Lennart Poettering lennart at kemper.freedesktop.org
Mon Oct 14 10:02:56 PDT 2013


 .gitignore                |    1 +
 TODO                      |    2 --
 rules/99-systemd.rules.in |    6 +++---
 src/backlight/backlight.c |   29 ++++++++++++++++++++++++++---
 src/rfkill/rfkill.c       |   40 ++++++++++++++++------------------------
 5 files changed, 46 insertions(+), 32 deletions(-)

New commits:
commit 690018ab40dc9435d609f92c5eca9b1b847668c6
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Oct 14 19:02:11 2013 +0200

    git: add test-ellipsize to files to ignore by git

diff --git a/.gitignore b/.gitignore
index 587b6d0..5e63b2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -106,6 +106,7 @@
 /test-daemon
 /test-date
 /test-device-nodes
+/test-ellipsize
 /test-engine
 /test-env-replace
 /test-event
diff --git a/TODO b/TODO
index 3926fe5..3f8c305 100644
--- a/TODO
+++ b/TODO
@@ -50,8 +50,6 @@ Features:
 
 * "systemctl cat" or "systemctl view" command or or so, that cats the backing unit file of a service, plus its drop-ins and shows them in a pager
 
-* rfkill,backlight: we probably should use a path ID of some kind rather than the sysname as file name to store status in
-
 * rfkill,backlight: we probably should run the load tools inside of the udev rules so that the state is properly initialized by the time other software sees it
 
 * Add a new Distribute=$NUMBER key to socket units that makes use of SO_REUSEPORT to distribute network traffic on $NUMBER instances

commit be3f52f4ed02a9256b1577719677b32a17b525ac
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Oct 14 19:01:09 2013 +0200

    backlight: include ID_PATH in file names for backlight settings
    
    Much like for rfkill devices we should provide some stability regarding
    enumeration order, hence include the stable bits of the device path in
    the file name we store settings under.

diff --git a/rules/99-systemd.rules.in b/rules/99-systemd.rules.in
index 8e87780..a620354 100644
--- a/rules/99-systemd.rules.in
+++ b/rules/99-systemd.rules.in
@@ -54,8 +54,8 @@ ACTION=="add", SUBSYSTEM=="net", KERNEL!="lo", RUN+="@rootlibexecdir@/systemd-sy
 # Pull in backlight save/restore for all backlight devices and
 # keyboard backlights
 
-ACTION=="add", SUBSYSTEM=="backlight", TAG+="systemd", ENV{SYSTEMD_WANTS}+="systemd-backlight at backlight:$name.service"
-ACTION=="add", SUBSYSTEM=="leds", KERNEL=="*kbd_backlight", TAG+="systemd", ENV{SYSTEMD_WANTS}+="systemd-backlight at leds:$name.service"
+ACTION=="add", SUBSYSTEM=="backlight", TAG+="systemd", IMPORT{builtin}="path_id", ENV{SYSTEMD_WANTS}+="systemd-backlight at backlight:$name.service"
+ACTION=="add", SUBSYSTEM=="leds", KERNEL=="*kbd_backlight", TAG+="systemd", IMPORT{builtin}="path_id", ENV{SYSTEMD_WANTS}+="systemd-backlight at leds:$name.service"
 
 # Pull in rfkill save/restore for all rfkill devices
 
diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c
index 51a67a0..e8cdad6 100644
--- a/src/backlight/backlight.c
+++ b/src/backlight/backlight.c
@@ -195,8 +195,8 @@ static bool validate_device(struct udev *udev, struct udev_device *device) {
 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, *ss = NULL;
-        const char *sysname;
+        _cleanup_free_ char *saved = NULL, *ss = NULL, *escaped_ss = NULL, *escaped_sysname = NULL, *escaped_path_id = NULL;
+        const char *sysname, *path_id;
         int r;
 
         if (argc != 3) {
@@ -252,7 +252,30 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        saved = strjoin("/var/lib/systemd/backlight/", ss, ":", sysname, NULL);
+        escaped_ss = cescape(ss);
+        if (!escaped_ss) {
+                log_oom();
+                return EXIT_FAILURE;
+        }
+
+        escaped_sysname = cescape(sysname);
+        if (!escaped_sysname) {
+                log_oom();
+                return EXIT_FAILURE;
+        }
+
+        path_id = udev_device_get_property_value(device, "ID_PATH");
+        if (path_id) {
+                escaped_path_id = cescape(path_id);
+                if (!escaped_path_id) {
+                        log_oom();
+                        return EXIT_FAILURE;
+                }
+
+                saved = strjoin("/var/lib/systemd/backlight/", escaped_path_id, ":", escaped_ss, ":", escaped_sysname, NULL);
+        } else
+                saved = strjoin("/var/lib/systemd/backlight/", escaped_ss, ":", escaped_sysname, NULL);
+
         if (!saved) {
                 log_oom();
                 return EXIT_FAILURE;
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
index ad1d63d..812cf40 100644
--- a/src/rfkill/rfkill.c
+++ b/src/rfkill/rfkill.c
@@ -86,7 +86,7 @@ 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_name, NULL);
         } else
                 saved = strjoin("/var/lib/systemd/rfkill/", escaped_name, NULL);
 

commit f6f738db7273f8a2092ac372852f37f2a34cea17
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Oct 14 18:52:07 2013 +0200

    rfkill: use ID_PATH as identifier for rfkill state files
    
    Let's include the stable device path for the rfkill devices in the name
    of the file we store the rfkill state in, so that we have some stability
    regarding enumeration order.

diff --git a/rules/99-systemd.rules.in b/rules/99-systemd.rules.in
index 2ffe744..8e87780 100644
--- a/rules/99-systemd.rules.in
+++ b/rules/99-systemd.rules.in
@@ -59,7 +59,7 @@ ACTION=="add", SUBSYSTEM=="leds", KERNEL=="*kbd_backlight", TAG+="systemd", ENV{
 
 # Pull in rfkill save/restore for all rfkill devices
 
-ACTION=="add", SUBSYSTEM=="rfkill", TAG+="systemd", ENV{SYSTEMD_WANTS}+="systemd-rfkill at rfkill:$name.service"
+ACTION=="add", SUBSYSTEM=="rfkill", TAG+="systemd", IMPORT{builtin}="path_id", ENV{SYSTEMD_WANTS}+="systemd-rfkill@$name.service"
 
 # Asynchronously mount file systems implemented by these modules as
 # soon as they are loaded.
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
index 9153652..ad1d63d 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, *ss = NULL, *escaped_name = NULL;
-        const char *sysname, *name;
+        _cleanup_free_ char *saved = NULL, *escaped_name = NULL, *escaped_path_id = NULL;
+        const char *name, *path_id;
         int r;
 
         if (argc != 3) {
@@ -55,30 +55,11 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        sysname = strchr(argv[2], ':');
-        if (!sysname) {
-                log_error("Requires pair of subsystem and sysname for specifying rfkill device.");
-                return EXIT_FAILURE;
-        }
-
-        ss = strndup(argv[2], sysname - argv[2]);
-        if (!ss) {
-                log_oom();
-                return EXIT_FAILURE;
-        }
-
-        sysname++;
-
-        if (!streq(ss, "rfkill")) {
-                log_error("Not a rfkill device: '%s:%s'", ss, sysname);
-                return EXIT_FAILURE;
-        }
-
         errno = 0;
-        device = udev_device_new_from_subsystem_sysname(udev, ss, sysname);
+        device = udev_device_new_from_subsystem_sysname(udev, "rfkill", argv[2]);
         if (!device) {
                 if (errno != 0)
-                        log_error("Failed to get rfkill device '%s:%s': %m", ss, sysname);
+                        log_error("Failed to get rfkill device '%s': %m", argv[2]);
                 else
                         log_oom();
 
@@ -97,7 +78,18 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        saved = strjoin("/var/lib/systemd/rfkill/", escaped_name, NULL);
+        path_id = udev_device_get_property_value(device, "ID_PATH");
+        if (path_id) {
+                escaped_path_id = cescape(path_id);
+                if (!escaped_path_id) {
+                        log_oom();
+                        return EXIT_FAILURE;
+                }
+
+                saved = strjoin("/var/lib/systemd/rfkill/", escaped_path_id, "-", escaped_name, NULL);
+        } else
+                saved = strjoin("/var/lib/systemd/rfkill/", escaped_name, NULL);
+
         if (!saved) {
                 log_oom();
                 return EXIT_FAILURE;



More information about the systemd-commits mailing list