]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/backlight/backlight.c
tree-wide: sort includes
[thirdparty/systemd.git] / src / backlight / backlight.c
index 218dc0d8cd757d6cae782e770abefa08849f2135..a2da976bb61fbba84883cd37385424f35ebe4344 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "util.h"
-#include "mkdir.h"
+#include "alloc-util.h"
+#include "def.h"
+#include "escape.h"
 #include "fileio.h"
 #include "libudev.h"
+#include "mkdir.h"
+#include "parse-util.h"
+#include "proc-cmdline.h"
+#include "string-util.h"
 #include "udev-util.h"
-#include "def.h"
+#include "util.h"
 
 static struct udev_device *find_pci_or_platform_parent(struct udev_device *device) {
         struct udev_device *parent;
@@ -318,7 +323,7 @@ int main(int argc, char *argv[]) {
         device = udev_device_new_from_subsystem_sysname(udev, ss, sysname);
         if (!device) {
                 if (errno != 0)
-                        log_error("Failed to get backlight or LED device '%s:%s': %m", ss, sysname);
+                        log_error_errno(errno, "Failed to get backlight or LED device '%s:%s': %m", ss, sysname);
                 else
                         log_oom();
 
@@ -373,8 +378,9 @@ int main(int argc, char *argv[]) {
 
         if (streq(argv[1], "load")) {
                 _cleanup_free_ char *value = NULL;
+                const char *clamp;
 
-                if (!shall_restore_state())
+                if (shall_restore_state() == 0)
                         return EXIT_SUCCESS;
 
                 if (!validate_device(udev, device))
@@ -390,7 +396,9 @@ int main(int argc, char *argv[]) {
                         return EXIT_FAILURE;
                 }
 
-                clamp_brightness(device, &value, max_brightness);
+                clamp = udev_device_get_property_value(device, "ID_BACKLIGHT_CLAMP");
+                if (!clamp || parse_boolean(clamp) != 0) /* default to clamping */
+                        clamp_brightness(device, &value, max_brightness);
 
                 r = udev_device_set_sysattr_value(device, "brightness", value);
                 if (r < 0) {
@@ -412,7 +420,7 @@ int main(int argc, char *argv[]) {
                         return EXIT_FAILURE;
                 }
 
-                r = write_string_file(saved, value);
+                r = write_string_file(saved, value, WRITE_STRING_FILE_CREATE);
                 if (r < 0) {
                         log_error_errno(r, "Failed to write %s: %m", saved);
                         return EXIT_FAILURE;