From: dongshengyuan <545258830@qq.com> Date: Mon, 13 Jul 2026 06:16:55 +0000 (+0800) Subject: run: reject JSON output for trigger units X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3fa641d01fc559a4d1c73dcc72bdc7ebe9d08200;p=thirdparty%2Fsystemd.git run: reject JSON output for trigger units 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 --- diff --git a/src/run/run.c b/src/run/run.c index 6754b80bcf3..e49e918b0fc 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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), diff --git a/test/units/TEST-74-AUX-UTILS.run.sh b/test/units/TEST-74-AUX-UTILS.run.sh index a5c79ddb72e..0619a8995f7 100755 --- a/test/units/TEST-74-AUX-UTILS.run.sh +++ b/test/units/TEST-74-AUX-UTILS.run.sh @@ -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)