From 2a4750c3e1022eff2a7a5006562e881fecb64f93 Mon Sep 17 00:00:00 2001 From: dongshengyuan <545258830@qq.com> Date: Mon, 13 Jul 2026 14:18:42 +0800 Subject: [PATCH] run: reject JSON output in scope mode Reproducer: sudo systemd-run --scope --json=short /bin/echo hi Before, systemd-run printed JSON metadata to stdout and then executed the scope command on the same stdout. The combined stream was not valid JSON, so reject --json= in scope mode. Follow-up for fe5a6c47af675bc0020c545d86fb103492e1d77c --- src/run/run.c | 4 ++++ test/units/TEST-74-AUX-UTILS.run.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/src/run/run.c b/src/run/run.c index e49e918b0f..57f2e66303 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -705,6 +705,10 @@ static int parse_argv(int argc, char *argv[]) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--no-block is not supported in --scope mode."); + if (arg_scope && sd_json_format_enabled(arg_json_format_flags)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "--json= is not supported in --scope mode."); + if (arg_stdio != ARG_STDIO_NONE) { if (with_trigger || arg_scope) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), diff --git a/test/units/TEST-74-AUX-UTILS.run.sh b/test/units/TEST-74-AUX-UTILS.run.sh index 0619a8995f..7d7b95687a 100755 --- a/test/units/TEST-74-AUX-UTILS.run.sh +++ b/test/units/TEST-74-AUX-UTILS.run.sh @@ -120,6 +120,7 @@ systemd-run --scope \ --property=RuntimeMaxSec=infinity \ true (! systemd-run --scope --ignore-failure false) +(! systemd-run --scope --json=short true) : "Transient scope (user daemon)" # FIXME: https://github.com/systemd/systemd/issues/27883