]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: make write_mode take a path
authorMike Yuan <me@yhndnzj.com>
Wed, 27 Mar 2024 11:45:08 +0000 (19:45 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 28 Mar 2024 09:16:25 +0000 (17:16 +0800)
Similar to the previous commit, preparation
for adding support for /sys/power/mem_sleep.

src/sleep/sleep.c

index bdba4284bf146e060e22bcbbda6ce3557f813142..72489b31a0d487d54d02c0a8e6489a93c6ad063a 100644 (file)
@@ -151,22 +151,22 @@ static int write_state(int fd, char * const *states) {
         return r;
 }
 
-static int write_mode(char * const *modes) {
-        int r = 0;
+static int write_mode(const char *path, char * const *modes) {
+        int r, ret = 0;
 
-        STRV_FOREACH(mode, modes) {
-                int k;
+        assert(path);
 
-                k = write_string_file("/sys/power/disk", *mode, WRITE_STRING_FILE_DISABLE_BUFFER);
-                if (k >= 0) {
-                        log_debug("Using sleep disk mode '%s'.", *mode);
+        STRV_FOREACH(mode, modes) {
+                r = write_string_file(path, *mode, WRITE_STRING_FILE_DISABLE_BUFFER);
+                if (r >= 0) {
+                        log_debug("Using sleep mode '%s' for %s.", *mode, path);
                         return 0;
                 }
 
-                RET_GATHER(r, log_debug_errno(k, "Failed to write '%s' to /sys/power/disk: %m", *mode));
+                RET_GATHER(ret, log_debug_errno(r, "Failed to write '%s' to %s: %m", *mode, path));
         }
 
-        return r;
+        return ret;
 }
 
 static int lock_all_homes(void) {
@@ -259,7 +259,7 @@ static int execute(
                                 goto fail;
                 }
 
-                r = write_mode(sleep_config->modes[operation]);
+                r = write_mode("/sys/power/disk", sleep_config->modes[operation]);
                 if (r < 0) {
                         log_error_errno(r, "Failed to write mode to /sys/power/disk: %m");
                         goto fail;