[systemd-devel] [PATCH] [RFC] Make reboot to support additional command

WaLyong Cho fyd0706 at gmail.com
Mon Aug 12 11:01:25 PDT 2013


From: WaLyong Cho <walyong.cho at samsung.com>

reboot syscall can be performed with additional argument. In some of
system, this functionality can be useful to ask next boot mode to
bootloader.
---
 src/systemctl/systemctl.c |   28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index a635891..5b46350 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <linux/reboot.h>
+#include <sys/syscall.h>
 #include <sys/reboot.h>
 #include <stdio.h>
 #include <getopt.h>
@@ -133,6 +135,7 @@ static char *arg_user = NULL;
 static unsigned arg_lines = 10;
 static OutputMode arg_output = OUTPUT_SHORT;
 static bool arg_plain = false;
+static char *arg_reboot = NULL;
 
 static bool private_bus = false;
 
@@ -4703,7 +4706,7 @@ static int systemctl_help(void) {
 
 static int halt_help(void) {
 
-        printf("%s [OPTIONS...]\n\n"
+        printf("%s [OPTIONS...]%s\n\n"
                "%s the system.\n\n"
                "     --help      Show this help\n"
                "     --halt      Halt the machine\n"
@@ -4714,6 +4717,7 @@ static int halt_help(void) {
                "  -d --no-wtmp   Don't write wtmp record\n"
                "     --no-wall   Don't send wall message before halt/power-off/reboot\n",
                program_invocation_short_name,
+               arg_action == ACTION_REBOOT   ? " <command>" : "",
                arg_action == ACTION_REBOOT   ? "Reboot" :
                arg_action == ACTION_POWEROFF ? "Power off" :
                                                "Halt");
@@ -5200,9 +5204,19 @@ static int halt_parse_argv(int argc, char *argv[]) {
                 }
         }
 
-        if (optind < argc) {
-                log_error("Too many arguments.");
-                return -EINVAL;
+        if (arg_action == ACTION_REBOOT) {
+                /* reboot allow just one argument for his command string */
+                if (optind+1 == argc)
+                        arg_reboot = strdup(argv[argc-1]);
+                else if (optind+1 < argc) {
+                        log_error("Too many arguments.");
+                        return -EINVAL;
+                }
+        } else {
+                if (optind < argc) {
+                        log_error("Too many arguments.");
+                        return -EINVAL;
+                }
         }
 
         return 1;
@@ -5949,7 +5963,11 @@ static _noreturn_ void halt_now(enum action a) {
 
         case ACTION_REBOOT:
                 log_info("Rebooting.");
-                reboot(RB_AUTOBOOT);
+                if (arg_reboot)
+                        syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
+                                LINUX_REBOOT_CMD_RESTART2, arg_reboot);
+                else
+                        reboot(RB_AUTOBOOT);
                 break;
 
         default:
-- 
1.7.9.5



More information about the systemd-devel mailing list