[systemd-devel] [PATCH 1/2] systemctl: delete REBOOT_PARAM_FILE if no parameter is specified

Michael Olbrich m.olbrich at pengutronix.de
Tue Mar 25 06:15:44 PDT 2014


And move it to sperate function.
---
 src/shared/util.c         | 16 ++++++++++++++++
 src/shared/util.h         |  2 ++
 src/systemctl/systemctl.c |  9 +++------
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index ffe6624..0260d17 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6391,3 +6391,19 @@ void hexdump(FILE *f, const void *p, size_t s) {
                 s -= 16;
         }
 }
+
+int update_reboot_param_file(const char *param)
+{
+        int r = 0;
+
+        if (param) {
+
+                r = write_string_file(REBOOT_PARAM_FILE, param);
+                if (r < 0)
+                        log_error("Failed to write reboot param to "
+                                  REBOOT_PARAM_FILE": %s", strerror(-r));
+        } else
+                unlink(REBOOT_PARAM_FILE);
+
+        return r;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 90464c9..a557f70 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -922,3 +922,5 @@ uint64_t physical_memory(void);
 char* mount_test_option(const char *haystack, const char *needle);
 
 void hexdump(FILE *f, const void *p, size_t s);
+
+int update_reboot_param_file(const char *param);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0887bc3..89de20e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5973,13 +5973,10 @@ static int halt_parse_argv(int argc, char *argv[]) {
                 }
         }
 
-        if (arg_action == ACTION_REBOOT && argc == optind + 1) {
-                r = write_string_file(REBOOT_PARAM_FILE, argv[optind]);
-                if (r < 0) {
-                        log_error("Failed to write reboot param to "
-                                  REBOOT_PARAM_FILE": %s", strerror(-r));
+        if (arg_action == ACTION_REBOOT && (argc == optind || argc == optind + 1)) {
+                r = update_reboot_param_file(argc == optind + 1 ? argv[optind] : NULL);
+                if (r < 0)
                         return r;
-                }
         } else if (optind < argc) {
                 log_error("Too many arguments.");
                 return -EINVAL;
-- 
1.9.1



More information about the systemd-devel mailing list