summaryrefslogtreecommitdiff
path: root/src/basic/reboot-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-21 17:54:35 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:59:02 +0200
commitfc145f67d8597dea9bd9bfcacac1e6fec533051d (patch)
treefca2157d851fce381928efa5298fbf0132e7986c /src/basic/reboot-util.c
parent608b07b67bf9f097cec658e15d0adbff5f18985b (diff)
basic: split out update_reboot_parameter_and_warn() into its own .c/.h files
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.
Diffstat (limited to 'src/basic/reboot-util.c')
-rw-r--r--src/basic/reboot-util.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/basic/reboot-util.c b/src/basic/reboot-util.c
new file mode 100644
index 000000000..2528d9bbe
--- /dev/null
+++ b/src/basic/reboot-util.c
@@ -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;
+}