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 fe5a6c47af
This commit is contained in:
dongshengyuan
2026-07-14 12:03:22 +08:00
parent 3fa641d01f
commit 2a4750c3e1
2 changed files with 5 additions and 0 deletions
+4
View File
@@ -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),
+1
View File
@@ -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