run: reject JSON output with verbose logs

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

Before, systemd-run printed JSON metadata to stdout while --verbose
also spawned journalctl output on stdout. The resulting stream mixed JSON
with journal lines, so reject the conflicting options.

Follow-up for 744ca8f616
This commit is contained in:
dongshengyuan
2026-07-14 12:03:22 +08:00
parent 2a4750c3e1
commit 7e76e93142
3 changed files with 23 additions and 12 deletions
+4
View File
@@ -616,6 +616,10 @@
</varlistentry>
</variablelist>
<para><option>--json=</option> may not be combined with <option>--scope</option>,
<option>--pty</option>, <option>--pty-late</option>, <option>--pipe</option>,
<option>--verbose</option>, or path, socket, or timer options.</para>
<para>All command line arguments after the first non-option argument become part of the command line of
the launched process.</para>
</refsect1>
+18 -12
View File
@@ -705,10 +705,6 @@ 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),
@@ -727,22 +723,32 @@ 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.");
if (sd_json_format_enabled(arg_json_format_flags)) {
if (arg_scope)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--json= is not supported in --scope mode.");
if (arg_stdio != ARG_STDIO_NONE)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--json= is not compatible with --pty/--pty-late/--pipe.");
if (arg_verbose)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--json= is not compatible with --verbose.");
if (with_trigger)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--json= is not compatible with path, socket or timer operations.");
}
if (arg_timer_property && !arg_with_timer)
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),
+1
View File
@@ -259,6 +259,7 @@ 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)
(! systemd-run --wait --verbose --json=short true)
(! SHELL=/bin/false systemd-run --quiet --shell)
(! systemd-run)