Harald Hoyer fe20ad
From 3437438503da8aa7e0549dde61f10f2bb0fb5805 Mon Sep 17 00:00:00 2001
Harald Hoyer fe20ad
From: Lennart Poettering <lennart@poettering.net>
Harald Hoyer fe20ad
Date: Wed, 14 Aug 2013 02:55:57 +0200
Harald Hoyer fe20ad
Subject: [PATCH] backlight: instead of syspath use sysname for identifying
Harald Hoyer fe20ad
 backlight devices
Harald Hoyer fe20ad
Harald Hoyer fe20ad
This makes the description string of the backlight service a bit nicer.
Harald Hoyer fe20ad
---
Harald Hoyer fe20ad
 rules/99-systemd.rules.in           |  2 +-
Harald Hoyer fe20ad
 src/backlight/backlight.c           | 10 ++++++++--
Harald Hoyer fe20ad
 units/systemd-backlight@.service.in |  6 +++---
Harald Hoyer fe20ad
 3 files changed, 12 insertions(+), 6 deletions(-)
Harald Hoyer fe20ad
Harald Hoyer fe20ad
diff --git a/rules/99-systemd.rules.in b/rules/99-systemd.rules.in
Harald Hoyer fe20ad
index ac4bc86..bbb7d0c 100644
Harald Hoyer fe20ad
--- a/rules/99-systemd.rules.in
Harald Hoyer fe20ad
+++ b/rules/99-systemd.rules.in
Harald Hoyer fe20ad
@@ -53,7 +53,7 @@ ACTION=="add", SUBSYSTEM=="net", KERNEL!="lo", RUN+="@rootlibexecdir@/systemd-sy
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 # Pull in backlight save/restore for all firmware backlight devices
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-ACTION=="add", SUBSYSTEM=="backlight", ATTR{type}=="firmware", TAG+="systemd", ENV{SYSTEMD_WANTS}+="systemd-backlight@sys%p.service"
Harald Hoyer fe20ad
+ACTION=="add", SUBSYSTEM=="backlight", ATTR{type}=="firmware", TAG+="systemd", ENV{SYSTEMD_WANTS}+="systemd-backlight@$name.service"
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 # Asynchronously mount file systems implemented by these modules as
Harald Hoyer fe20ad
 # soon as they are loaded.
Harald Hoyer fe20ad
diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c
Harald Hoyer fe20ad
index 3378907..1ef0b45 100644
Harald Hoyer fe20ad
--- a/src/backlight/backlight.c
Harald Hoyer fe20ad
+++ b/src/backlight/backlight.c
Harald Hoyer fe20ad
@@ -54,9 +54,15 @@ int main(int argc, char *argv[]) {
Harald Hoyer fe20ad
                 goto finish;
Harald Hoyer fe20ad
         }
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-        device = udev_device_new_from_syspath(udev, argv[2]);
Harald Hoyer fe20ad
+        errno = 0;
Harald Hoyer fe20ad
+        device = udev_device_new_from_subsystem_sysname(udev, "backlight", argv[2]);
Harald Hoyer fe20ad
         if (!device) {
Harald Hoyer fe20ad
-                r = log_oom();
Harald Hoyer fe20ad
+                if (errno != 0) {
Harald Hoyer fe20ad
+                        log_error("Failed to get backlight device: %m");
Harald Hoyer fe20ad
+                        r = -errno;
Harald Hoyer fe20ad
+                } else
Harald Hoyer fe20ad
+                        r = log_oom();
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
                 goto finish;
Harald Hoyer fe20ad
         }
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
diff --git a/units/systemd-backlight@.service.in b/units/systemd-backlight@.service.in
Harald Hoyer fe20ad
index 14b1219..b0e75db 100644
Harald Hoyer fe20ad
--- a/units/systemd-backlight@.service.in
Harald Hoyer fe20ad
+++ b/units/systemd-backlight@.service.in
Harald Hoyer fe20ad
@@ -6,7 +6,7 @@
Harald Hoyer fe20ad
 #  (at your option) any later version.
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 [Unit]
Harald Hoyer fe20ad
-Description=Load/Save Screen Backlight Brightness of %f
Harald Hoyer fe20ad
+Description=Load/Save Screen Backlight Brightness of %I
Harald Hoyer fe20ad
 Documentation=man:systemd-backlight@.service(8)
Harald Hoyer fe20ad
 DefaultDependencies=no
Harald Hoyer fe20ad
 RequiresMountsFor=/var/lib/backlight
Harald Hoyer fe20ad
@@ -17,5 +17,5 @@ Before=sysinit.target shutdown.target
Harald Hoyer fe20ad
 [Service]
Harald Hoyer fe20ad
 Type=oneshot
Harald Hoyer fe20ad
 RemainAfterExit=yes
Harald Hoyer fe20ad
-ExecStart=@rootlibexecdir@/systemd-backlight load %f
Harald Hoyer fe20ad
-ExecStop=@rootlibexecdir@/systemd-backlight save %f
Harald Hoyer fe20ad
+ExecStart=@rootlibexecdir@/systemd-backlight load %I
Harald Hoyer fe20ad
+ExecStop=@rootlibexecdir@/systemd-backlight save %I