#15773 add --reboot-argument to systemctl reboot

This commit is contained in:
laydervus 2020-05-29 13:15:34 -04:00 committed by layderv
parent 42ba8d25ad
commit dae710bef1
3 changed files with 42 additions and 10 deletions

4
NEWS
View File

@ -349,6 +349,10 @@ CHANGES WITH 246 in spe:
the default) an address from any acquire delegated prefix is
automatically chosen and assigned to the interface.
* "systemctl reboot" takes the option "--reboot-argument=".
The optional positional argument to "systemctl reboot" is now
being deprecated in favor of this option.
CHANGES WITH 245:
* A new tool "systemd-repart" has been added, that operates as an

View File

@ -1295,7 +1295,7 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
</listitem>
</varlistentry>
<varlistentry>
<term><command>reboot</command> <optional><replaceable>arg</replaceable></optional></term>
<term><command>reboot</command></term>
<listitem>
<para>Shut down and reboot the system. This is mostly equivalent to <command>systemctl start reboot.target
@ -1311,11 +1311,9 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
<command>systemctl</command> itself, and the system manager is not contacted. This means the command should
succeed even when the system manager has crashed.</para>
<para>If the optional argument <replaceable>arg</replaceable> is given, it will be passed as the optional
<para>If the switch <option>--reboot-argument=</option> is given, it will be passed as the optional
argument to the <citerefentry><refentrytitle>reboot</refentrytitle><manvolnum>2</manvolnum></citerefentry>
system call. The value is architecture and firmware specific. As an example, <literal>recovery</literal>
might be used to trigger system recovery, and <literal>fota</literal> might be used to trigger a
<quote>firmware over the air</quote> update.</para>
system call.</para>
</listitem>
</varlistentry>
@ -2117,6 +2115,16 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
</listitem>
</varlistentry>
<varlistentry>
<term><option>--reboot-argument=</option></term>
<listitem>
<para>This switch is used with <command>reboot</command>. The value is architecture and firmware specific. As an example, <literal>recovery</literal>
might be used to trigger system recovery, and <literal>fota</literal> might be used to trigger a
<quote>firmware over the air</quote> update.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--plain</option></term>

View File

@ -130,6 +130,7 @@ static const char *arg_kill_who = NULL;
static int arg_signal = SIGTERM;
static char *arg_root = NULL;
static usec_t arg_when = 0;
static const char *arg_reboot_argument = NULL;
static enum action {
ACTION_SYSTEMCTL,
ACTION_HALT,
@ -3556,10 +3557,23 @@ static int start_special(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
if (a == ACTION_REBOOT && argc > 1) {
r = update_reboot_parameter_and_warn(argv[1], false);
if (r < 0)
return r;
if (a == ACTION_REBOOT) {
const char *arg = NULL;
if (argc > 1) {
if (arg_reboot_argument)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Both --reboot-argument= and positional argument passed to reboot command, refusing.");
log_notice("Positional argument to reboot command is deprecated, please use --reboot-argument= instead. Accepting anyway.");
arg = argv[1];
} else
arg = arg_reboot_argument;
if (arg) {
r = update_reboot_parameter_and_warn(arg, false);
if (r < 0)
return r;
}
} else if (a == ACTION_KEXEC) {
r = load_kexec_kernel();
@ -7708,7 +7722,7 @@ static int systemctl_help(void) {
" emergency Enter system emergency mode\n"
" halt Shut down and halt the system\n"
" poweroff Shut down and power-off the system\n"
" reboot [ARG] Shut down and reboot the system\n"
" reboot Shut down and reboot the system\n"
" kexec Shut down and reboot the system with kexec\n"
" exit [EXIT_CODE] Request user instance or container exit\n"
" switch-root ROOT [INIT] Change to a different root file system\n"
@ -8026,6 +8040,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
ARG_WITH_DEPENDENCIES,
ARG_WAIT,
ARG_WHAT,
ARG_REBOOT_ARG,
};
static const struct option options[] = {
@ -8079,6 +8094,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
{ "message", required_argument, NULL, ARG_MESSAGE },
{ "show-transaction", no_argument, NULL, 'T' },
{ "what", required_argument, NULL, ARG_WHAT },
{ "reboot-argument", required_argument, NULL, ARG_REBOOT_ARG },
{}
};
@ -8474,6 +8490,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
break;
}
case ARG_REBOOT_ARG:
arg_reboot_argument = optarg;
break;
case '.':
/* Output an error mimicking getopt, and print a hint afterwards */
log_error("%s: invalid option -- '.'", program_invocation_name);