From 3b0652d1e6e10a9256df3035484f4d3f6369b1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 19 Oct 2026 13:12:54 +0200 Subject: [PATCH] journald: use common_parse_argv() Describe the program with COMMAND() and parse the command line with the shared helper, which adds -h/--help, --version, and --introspect-cli. The optional namespace argument is unchanged. Superfluous arguments are now rejected with "Too many arguments." instead of "This program takes one or no arguments.". The template unit is adjusted to use '-- %i' to pass the namespace name. I'm not convinced that using a namespace name starting with a dash is a good idea, but using '--' to disambiguate seems good in any case, so let's do that. We might want to adjust log_namespace_name_valid() separately. --- src/journal/journald.c | 17 ++++++++++++++--- test/units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + units/systemd-journald@.service.in | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/journal/journald.c b/src/journal/journald.c index ec095684df0..0783aacbd26 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -19,6 +19,15 @@ #include "string-util.h" #include "terminal-util.h" #include "time-util.h" +#include "verbs.h" + +COMMAND( + "systemd-journald\0", + "Collect and store log messages.", + .argspec = "[NAMESPACE]\0", + .man_pages = "systemd-journald.service(8)\0", + .option_namespace = "common", +); static int run(int argc, char *argv[]) { _cleanup_(manager_freep) Manager *m = NULL; @@ -32,10 +41,12 @@ static int run(int argc, char *argv[]) { LIBPCRE2_NOTE(suggested); LIBSELINUX_NOTE(recommended); - if (argc > 2) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes one or no arguments."); + char **args = NULL; + r = common_parse_argv_full(argc, argv, /* min_args= */ 0, /* max_args= */ 1, &args); + if (r <= 0) + return r; - namespace = argc > 1 ? empty_to_null(argv[1]) : NULL; + namespace = empty_to_null(args[0]); log_set_facility(LOG_SYSLOG); diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index 58f404ef3d8..60fc5b2c511 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -111,6 +111,7 @@ INTROSPECTABLE=( systemd-journal-gatewayd systemd-journal-remote systemd-journal-upload + systemd-journald systemd-keyutil systemd-localed systemd-logind diff --git a/units/systemd-journald@.service.in b/units/systemd-journald@.service.in index b705ce08ff5..507e214dc14 100644 --- a/units/systemd-journald@.service.in +++ b/units/systemd-journald@.service.in @@ -16,7 +16,7 @@ After=systemd-journald@%i.socket systemd-journald-varlink@%i.socket [Service] CapabilityBoundingSet=CAP_SYS_ADMIN CAP_DAC_OVERRIDE CAP_SYS_PTRACE CAP_CHOWN CAP_DAC_READ_SEARCH CAP_FOWNER CAP_SETUID CAP_SETGID CAP_MAC_OVERRIDE DevicePolicy=closed -ExecStart={{LIBEXECDIR}}/systemd-journald %i +ExecStart={{LIBEXECDIR}}/systemd-journald -- %i FileDescriptorStoreMax=4224 Group=systemd-journal IPAddressDeny=any