]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: reject JSON output in scope mode
authordongshengyuan <545258830@qq.com>
Mon, 13 Jul 2026 06:18:42 +0000 (14:18 +0800)
committerdongshengyuan <545258830@qq.com>
Tue, 14 Jul 2026 04:03:22 +0000 (12:03 +0800)
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
test/units/TEST-74-AUX-UTILS.run.sh

index e49e918b0fcc99c1c2d75801f8eeaa475526d7a2..57f2e66303e13636e011d507fcdc143eb687e5bc 100644 (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),
index 0619a8995f728fbdeb274321fa03b811706b3af5..7d7b95687abbd333ae8f9520ce3d4fb06b9158fa 100755 (executable)
@@ -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