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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek committed 2026-10-21 22:08:12 +02:00
1 parent 76e9c87e25
commit 3b0652d1e6
3 files changed
+16 -4

No files matched your search

+14 -3
View File
@@ -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);
@@ -111,6 +111,7 @@ INTROSPECTABLE=(
systemd-journal-gatewayd
systemd-journal-remote
systemd-journal-upload
systemd-journald
systemd-keyutil
systemd-localed
systemd-logind
+1 -1
View File
@@ -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