From: dongshengyuan <545258830@qq.com> Date: Mon, 13 Jul 2026 06:18:42 +0000 (+0800) Subject: run: reject JSON output in scope mode X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2a4750c3e1022eff2a7a5006562e881fecb64f93;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/run/run.c b/src/run/run.c index e49e918b0fc..57f2e66303e 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 0619a8995f7..7d7b95687ab 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