shutdown: copy shutdown verb so shutdown scripts receive $1

The arg_verb was copying the pointer to the shutdown verb, but that
pointer was being overwritten. When the shutdown scripts run, the forked
child calls rename_process() which overwrites argv, so the scripts got
an empty $1 instead of reboot, poweroff, etc.

Make a copy of the verb with strdup() so it is not affected.

Fixes: #44087

Follow-up for: 4927588993
This commit is contained in:
abdurrafay3 authored and Yu Watanabe committed 2026-10-11 04:23:42 +09:00
1 parent fd30937468
commit e6b62f2b3a
1 file changed
+8 -4
+8 -4
View File
@@ -58,10 +58,12 @@
#define SYNC_TIMEOUT_USEC (10*USEC_PER_SEC)
#define DEFAULT_MINIMUM_UPTIME_USEC (15U * USEC_PER_SEC)
static const char *arg_verb = NULL;
static char *arg_verb = NULL;
static uint8_t arg_exit_code = 0;
static usec_t arg_timeout = DEFAULT_TIMEOUT_USEC;
STATIC_DESTRUCTOR_REGISTER(arg_verb, freep);
COMMAND(
"systemd-shutdown\0",
"Execute the final phase of system shutdown.",
@@ -157,9 +159,11 @@ static int parse_argv(int argc, char *argv[]) {
break;
OPTION_POSITIONAL:
if (!arg_verb)
arg_verb = opts.arg;
else
if (!arg_verb) {
arg_verb = strdup(opts.arg);
if (!arg_verb)
return log_oom();
} else
log_warning("Got extraneous argument, ignoring.");
break;
}