]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
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)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Feb 2018 09:46:12 +0000 (10:46 +0100)
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
src/core/emergency-action.c
src/systemctl/systemctl.c

index 811085eec106895938934badc6c96d713916758f..c71599db7b6702b57ab8817dec3ccf00600eb050 100644 (file)
@@ -158,6 +158,8 @@ basic_sources = files('''
         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..68910a6
--- /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 c7f1513f3ebf5735ec791824f80074162914a8c2..7863a14fb29495c905d950a094851df4898bf5ec 100644 (file)
@@ -518,29 +518,6 @@ uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) {
         return m / max;
 }
 
-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;
-}
-
 int version(void) {
         puts(PACKAGE_STRING "\n"
              SYSTEMD_FEATURES);
index 9d1b10756b29b565d6d1a5b2399aa9563cc22377..6f8d8bef34ed8cc900574dbde1eacc60c2b3c6e3 100644 (file)
@@ -186,8 +186,6 @@ uint64_t physical_memory_scale(uint64_t v, uint64_t max);
 uint64_t system_tasks_max(void);
 uint64_t system_tasks_max_scale(uint64_t v, uint64_t max);
 
-int update_reboot_parameter_and_warn(const char *param);
-
 int version(void);
 
 int str_verscmp(const char *s1, const char *s2);
index be3ca8f20d1c799341a0c9de37cba25d5c2c9fdd..3d37a986bc6298047aa59eb6edde77d2bfe542e7 100644 (file)
@@ -25,6 +25,7 @@
 #include "bus-util.h"
 #include "emergency-action.h"
 #include "raw-reboot.h"
+#include "reboot-util.h"
 #include "special.h"
 #include "string-table.h"
 #include "terminal-util.h"
index 800f862938954c5659c7a58f5cf615a8ca653f57..0d3d0d0daa51bb35af786e73fc9a42750a8b6b20 100644 (file)
@@ -73,6 +73,7 @@
 #include "path-util.h"
 #include "process-util.h"
 #include "raw-reboot.h"
+#include "reboot-util.h"
 #include "rlimit-util.h"
 #include "set.h"
 #include "sigbus.h"