run: reject JSON output with stdio forwarding

Reproducer:
  sudo systemd-run --wait --pipe --json=short /bin/echo hi

Before, systemd-run wrote its JSON metadata to stdout and then passed
the command stdout through the same stream. The combined output was not
valid machine-readable JSON, so reject the conflicting modes.

Follow-up for fe5a6c47af
This commit is contained in:
dongshengyuan
2026-07-14 12:03:22 +08:00
parent df3a08b244
commit ecf38b0e22
2 changed files with 5 additions and 0 deletions
+4
View File
@@ -723,6 +723,10 @@ static int parse_argv(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--pty-late is not compatible with --service-type=oneshot.");
if (sd_json_format_enabled(arg_json_format_flags) && arg_stdio != ARG_STDIO_NONE)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--json= is not compatible with --pty/--pty-late/--pipe.");
if (arg_scope && with_trigger)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Path, socket or timer options are not supported in --scope mode.");
+1
View File
@@ -256,6 +256,7 @@ systemd-run --wait --pty true
systemd-run --wait --machine=.host --pty true
systemd-run --json=short true | jq . >/dev/null
systemd-run --json=pretty true | jq . >/dev/null
(! systemd-run --wait --pipe --json=short true)
(! SHELL=/bin/false systemd-run --quiet --shell)
(! systemd-run)