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

WaLyong Cho walyong.cho at samsung.com
Tue Nov 5 22:22:49 PST 2013



On 09/12/2013 02:20 AM, Lennart Poettering wrote:
> 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)

Sorry for my long silence.

You were right. Previous my patch did not pass the argument without
force option. So I modified according to your opinion. But I think we
have to keep some codes in systemctl for supporting forced reboot.

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

There are not any params specified. Any string can be used. That string
is used in kernel side.
http://lxr.linux.no/linux+v3.4/kernel/sys.c#L486

Sorry, there are no visible commits for Tizen in the web. But, for
simple example, fota, recovery, download and more are used in Tizen.
fota is used when restart to enter fota updated mode. In the mobile,
user can download firmware image by on air. And update device firmware
to downloaded. During this, reboot is performed. See
http://www.redbend.com/en/products-solutions/fota-updating for detail.
recovery is used for detecting hacked kernel. I am not sure that I can
explain more.
download is used to enter download mode. As you may know, most of
devices are downloaded(not installed) when the device is produced. At
this time, special boot mode is used to flush device.

I found similar codes in android.
https://github.com/CyanogenMod/android_system_core/blob/gingerbread/toolbox/reboot.c
https://github.com/CyanogenMod/android_system_core/blob/gingerbread/libreboot/reboot.c

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

According to man page of reboot. They called this 'arg'.
http://man7.org/linux/man-pages/man2/reboot.2.htm
I'm not sure which is more suitable word between 'param' and 'arg'. You
offered 'param', so I used also 'param'. Because, 'arg' can be confused
with argc/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:
> 
> 
> Lennart
> 

WaLyong
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-make-reboot-to-support-additional-command.patch
Type: text/x-diff
Size: 10283 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20131106/914c8853/attachment-0001.patch>


More information about the systemd-devel mailing list