chiark / gitweb /
systemctl: delete REBOOT_PARAM_FILE if no parameter is specified
authorMichael Olbrich <m.olbrich@pengutronix.de>
Tue, 25 Mar 2014 13:15:44 +0000 (14:15 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 21 Apr 2014 13:58:53 +0000 (09:58 -0400)
And move it to sperate function.

src/shared/util.c
src/shared/util.h
src/systemctl/systemctl.c

index c20dff2f7cebaa0050a6478bc854b167e66c6323..b6285abb29fc3a9198bbe097fbf73c767161fa76 100644 (file)
@@ -6397,3 +6397,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;
+}
index 891848a1d86804ee5fcced672f5c69945fc105cc..5b060ef74f8e0a98725553d606170c46da3da837 100644 (file)
@@ -917,6 +917,8 @@ char* mount_test_option(const char *haystack, const char *needle);
 void hexdump(FILE *f, const void *p, size_t s);
 
 union file_handle_union {
-  struct file_handle handle;
-  char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ];
+        struct file_handle handle;
+        char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ];
 };
+
+int update_reboot_param_file(const char *param);
index 1b381f7a90680d6a661fcff02c2916601b4b5e7c..1717c1929ee15396f32ad039c04236bd38fbd2ce 100644 (file)
@@ -6018,13 +6018,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;