From 088a53dea71ed689d7af63c262332400f93f7e09 Mon Sep 17 00:00:00 2001 From: abdurrafay3 Date: Fri, 9 Oct 2026 21:11:13 +0800 Subject: [PATCH] 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 (cherry picked from commit e6b62f2b3a564fcfb282dc4729eb9a5565e87ba9) --- src/shutdown/shutdown.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index 720d06434f..08703f7e03 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -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; }