chiark / gitweb /
basic: split out update_reboot_parameter_and_warn() into its own .c/.h files
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Feb 2018 16:54:35 +0000 (17:54 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:59:02 +0000 (07:59 +0200)
This is primarily preparation for a follow-up commit that adds a common
implementation of the other side of the reboot parameter file, i.e. the
code that reads the file and issues reboot() for it.

src/basic/meson.build
src/basic/reboot-util.c [new file with mode: 0644]
src/basic/reboot-util.h [new file with mode: 0644]
src/basic/util.c
src/basic/util.h

index cf0038b832b035e2e561889d13c7bffb77f52d88..33cfe8e531850f67c399ca4209bf8cc27e5a8931 100644 (file)
 #         ratelimit.h
 #         raw-clone.h
 #         raw-reboot.h
+#         reboot-util.c
+#         reboot-util.h
 #         refcnt.h
 #         replace-var.c
 #         replace-var.h
diff --git a/src/basic/reboot-util.c b/src/basic/reboot-util.c
new file mode 100644 (file)
index 0000000..2528d9b
--- /dev/null
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+//#include <errno.h>
+//#include <unistd.h>
+
+//#include "fileio.h"
+//#include "log.h"
+//#include "reboot-util.h"
+//#include "string-util.h"
+//#include "umask-util.h"
+
+int update_reboot_parameter_and_warn(const char *parameter) {
+        int r;
+
+        if (isempty(parameter)) {
+                if (unlink("/run/systemd/reboot-param") < 0) {
+                        if (errno == ENOENT)
+                                return 0;
+
+                        return log_warning_errno(errno, "Failed to unlink reboot parameter file: %m");
+                }
+
+                return 0;
+        }
+
+        RUN_WITH_UMASK(0022) {
+                r = write_string_file("/run/systemd/reboot-param", parameter,
+                                      WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
+                if (r < 0)
+                        return log_warning_errno(r, "Failed to write reboot parameter file: %m");
+        }
+
+        return 0;
+}
diff --git a/src/basic/reboot-util.h b/src/basic/reboot-util.h
new file mode 100644 (file)
index 0000000..6f1d24c
--- /dev/null
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#pragma once
+
+int update_reboot_parameter_and_warn(const char *parameter);
index 9c7e6c0ad40eb00cf9e63a65c56b7ce892372ae9..5133d9b1ec134c40957fd2dfb2fefee080958325 100644 (file)
@@ -526,30 +526,7 @@ uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) {
 }
 
 #if 0 /// UNNEEDED by elogind
-int update_reboot_parameter_and_warn(const char *param) {
-        int r;
-
-        if (isempty(param)) {
-                if (unlink("/run/systemd/reboot-param") < 0) {
-                        if (errno == ENOENT)
-                                return 0;
-
-                        return log_warning_errno(errno, "Failed to unlink reboot parameter file: %m");
-                }
-
-                return 0;
-        }
-
-        RUN_WITH_UMASK(0022) {
-                r = write_string_file("/run/systemd/reboot-param", param, WRITE_STRING_FILE_CREATE);
-                if (r < 0)
-                        return log_warning_errno(r, "Failed to write reboot parameter file: %m");
-        }
-
-        return 0;
-}
 #endif // 0
-
 int version(void) {
         puts(PACKAGE_STRING "\n"
              SYSTEMD_FEATURES);
index de042509f88618d65083aa70cfbef96cd91981ce..2c2651e4805821de0be7a539a235cf130eba3848 100644 (file)
@@ -197,9 +197,7 @@ uint64_t system_tasks_max(void);
 uint64_t system_tasks_max_scale(uint64_t v, uint64_t max);
 
 #if 0 /// UNNEEDED by elogind
-int update_reboot_parameter_and_warn(const char *param);
 #endif // 0
-
 int version(void);
 
 #if 0 /// UNNEEDED by elogind