systemctl: quote command arguments in status output

The Process lines in systemctl status join argv with spaces, making
multi-word arguments ambiguous and empty arguments invisible.

Use quote_command_line() with SHELL_ESCAPE_EMPTY to retain argument
boundaries. Leave the formatted string NULL for an empty argv vector so
that strna() prints n/a. Cover whitespace, empty arguments and literal
dollar signs in TEST-26-SYSTEMCTL.

Fixes #43938.

(cherry picked from commit a83a0d2fc461091b16a699aeba07a82d71545c71)
This commit is contained in:
Jonghyun An
2026-10-16 17:24:50 +01:00
committed by Luca Boccassi
parent 17f3e1fb3b
commit 6eb23d3526
2 changed files with 11 additions and 1 deletions
+3 -1
View File
@@ -15,6 +15,7 @@
#include "cgroup-show.h"
#include "cpu-set-util.h"
#include "errno-util.h"
#include "escape.h"
#include "exec-util.h"
#include "exit-status.h"
#include "format-util.h"
@@ -643,7 +644,8 @@ static void print_status_info(
if (endswith(p->name, "Ex"))
continue;
argv = strv_join(p->argv, " ");
if (!strv_isempty(p->argv))
argv = quote_command_line(p->argv, SHELL_ESCAPE_EMPTY);
printf(" Process: "PID_FMT" %s=%s ", p->pid, p->name, strna(argv));
good = is_clean_exit(p->code, p->status, EXIT_CLEAN_DAEMON, NULL);
+8
View File
@@ -369,6 +369,14 @@ systemctl status "sys-devices-*-ttyS0.device"
systemctl status -- -.mount
systemctl status 1
# Exited commands are shown with argument boundaries preserved (#43938)
systemd-run --unit=status-quoting-test.service -p Type=oneshot -p RemainAfterExit=yes \
--expand-environment=no true "foo bar" "" "a\$b"
output="$(systemctl status --full --no-pager --lines=0 status-quoting-test.service)"
systemctl stop status-quoting-test.service
# shellcheck disable=SC2016
grep -F ' "foo bar" "" "a\$b" (code=exited, status=0/SUCCESS)' <<<"$output"
# --marked
systemctl restart "$UNIT_NAME"
systemctl set-property "$UNIT_NAME" "Markers=needs-reload needs-restart"