summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-07 16:53:37 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-12 13:43:32 +0200
commit27c06cb516c3b87c34f2a1c2c227152997d05c8c (patch)
treea778f0a66e75528b6ee47e2b0c82668352176127 /src/basic
parent8612da973d30c5a9530fa1b6b3d449147b5a3324 (diff)
core: rework reboot parameter logic a bit
Always warn if something fails, and clarify that the involved utility functions do so in their name. Drop the REBOOT_PARAM_FILE macro. We don't do this for other flag file paths like this, so don't do this for this one either. The path isn't configurable anyway, hence let's make this easier to read by avoiding this one indirection.
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/def.h2
-rw-r--r--src/basic/util.c26
-rw-r--r--src/basic/util.h2
3 files changed, 18 insertions, 12 deletions
diff --git a/src/basic/def.h b/src/basic/def.h
index 963343eb7d..1a7a0f4928 100644
--- a/src/basic/def.h
+++ b/src/basic/def.h
@@ -41,8 +41,6 @@
#define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
#define SIGNALS_IGNORE SIGPIPE
-#define REBOOT_PARAM_FILE "/run/systemd/reboot-param"
-
#ifdef HAVE_SPLIT_USR
#define KBD_KEYMAP_DIRS \
"/usr/share/keymaps/\0" \
diff --git a/src/basic/util.c b/src/basic/util.c
index 6996527ec4..957b0e1ff1 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -778,16 +778,24 @@ uint64_t physical_memory(void) {
return (uint64_t) mem * (uint64_t) page_size();
}
-int update_reboot_param_file(const char *param) {
- int r = 0;
+int update_reboot_parameter_and_warn(const char *param) {
+ int r;
- if (param) {
- RUN_WITH_UMASK(0022)
- r = write_string_file(REBOOT_PARAM_FILE, param, WRITE_STRING_FILE_CREATE);
- if (r < 0)
- return log_error_errno(r, "Failed to write reboot param to "REBOOT_PARAM_FILE": %m");
- } else
- (void) unlink(REBOOT_PARAM_FILE);
+ 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;
}
diff --git a/src/basic/util.h b/src/basic/util.h
index 286db05159..1c032c15c9 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -184,6 +184,6 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
uint64_t physical_memory(void);
-int update_reboot_param_file(const char *param);
+int update_reboot_parameter_and_warn(const char *param);
int version(void);