]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: reject JSON output with stdio forwarding
authordongshengyuan <545258830@qq.com>
Mon, 13 Jul 2026 06:14:33 +0000 (14:14 +0800)
committerdongshengyuan <545258830@qq.com>
Tue, 14 Jul 2026 04:03:22 +0000 (12:03 +0800)
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 fe5a6c47af675bc0020c545d86fb103492e1d77c

src/run/run.c
test/units/TEST-74-AUX-UTILS.run.sh

index 5d95ee8a22a6bac11ac3ea98d788e46caee8fd36..6754b80bcf392b8f5e8d2cb5af766d6fa06f1b90 100644 (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.");
index acd7bc5b6c914d590f965db3de612f5f694b2ab3..a5c79ddb72e00f8626746cf1e9da397824150b62 100755 (executable)
@@ -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)