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

Lennart Poettering lennart at poettering.net
Wed Sep 11 10:20:34 PDT 2013


On Tue, 13.08.13 03:01, WaLyong Cho (fyd0706 at gmail.com) wrote:

> 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.

Hmm, interesting stuff. 

> @@ -5200,9 +5204,19 @@ static int halt_parse_argv(int argc, char *argv[]) {
>                  }
>          }
>  

Note that halt is not called during normal shutdown, but is only a
compat fallback for the old sysv "halt" command. If you want this to
work we probably need to come up with a way to pass the string from
systemctl to the final systemd-shutdown process.

(A bit of background: systemctl normally will just tell PID 1 to
shutdown cleanly, via D-Bus. As last step of that PID 1 will execute the
special systemd-shutdown binary -- which will then also run as PID 1 --
which will do some final shutdown steps and then invoke the reboot()
syscall -- see src/core/shutdown.c for details)

So, before we continue with this, could you point me to some
docs/commits/code which explain a bit how the new reboot() syscall
semantics work? i.e. what the possible params are and such?

One way to implement this could be to add add a new parameter to
systemctl which is written to /run/systemd/reboot-param or so if
specified. systemd-shutdown would then look for that file and pass it to
the reboot() syscall.

> -        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:


Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list