]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: reject JSON output for trigger units
authordongshengyuan <545258830@qq.com>
Mon, 13 Jul 2026 06:16:55 +0000 (14:16 +0800)
committerdongshengyuan <545258830@qq.com>
Tue, 14 Jul 2026 04:03:22 +0000 (12:03 +0800)
Reproducer:
  unit=run-json-trigger-$(date +%s)
  sudo systemd-run --json=short --unit="$unit" \
      --on-active=30s \
      /bin/true

Before, trigger mode accepted --json=short but printed only human-readable
"Running timer as unit" and "Will run service" lines. Reject the option
until trigger mode has structured output.

Follow-up for fe5a6c47af675bc0020c545d86fb103492e1d77c

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

index 6754b80bcf392b8f5e8d2cb5af766d6fa06f1b90..e49e918b0fcc99c1c2d75801f8eeaa475526d7a2 100644 (file)
@@ -735,6 +735,10 @@ static int parse_argv(int argc, char *argv[]) {
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                        "--timer-property= has no effect without any other timer options.");
 
+        if (sd_json_format_enabled(arg_json_format_flags) && with_trigger)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "--json= is not compatible with path, socket or timer operations.");
+
         if (arg_wait) {
                 if (arg_no_block)
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
index a5c79ddb72e00f8626746cf1e9da397824150b62..0619a8995f728fbdeb274321fa03b811706b3af5 100755 (executable)
@@ -257,6 +257,7 @@ 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)
+(! systemd-run --json=short --on-active=30s true)
 (! SHELL=/bin/false systemd-run --quiet --shell)
 
 (! systemd-run)