From: Lennart Poettering Date: Wed, 21 Feb 2018 16:54:35 +0000 (+0100) Subject: basic: split out update_reboot_parameter_and_warn() into its own .c/.h files X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fc145f67d8597dea9bd9bfcacac1e6fec533051d;p=elogind.git 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. --- diff --git a/src/basic/meson.build b/src/basic/meson.build index cf0038b83..33cfe8e53 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -159,6 +159,8 @@ # 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 index 000000000..2528d9bbe --- /dev/null +++ b/src/basic/reboot-util.c @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +//#include +//#include + +//#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 index 000000000..6f1d24c1f --- /dev/null +++ b/src/basic/reboot-util.h @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +int update_reboot_parameter_and_warn(const char *parameter); diff --git a/src/basic/util.c b/src/basic/util.c index 9c7e6c0ad..5133d9b1e 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -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); diff --git a/src/basic/util.h b/src/basic/util.h index de042509f..2c2651e48 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -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