From 1500b689a2fca1abaed9ea2bc51f4c74385da2c3 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] quotacheck: 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 path argument is unchanged. Superfluous arguments are rejected with "Too many arguments." instead of "This program expects one or no arguments.". --- src/quotacheck/quotacheck.c | 20 ++++++++++++++----- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index 0865e007181..4a46c490b22 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -10,6 +10,15 @@ #include "process-util.h" #include "string-table.h" #include "string-util.h" +#include "verbs.h" + +COMMAND( + "systemd-quotacheck\0", + "Check file system quotas.", + .argspec = "[PATH]\0", + .man_pages = "systemd-quotacheck@.service(8)\0", + .option_namespace = "common", +); typedef enum QuotaCheckMode { QUOTA_CHECK_AUTO, @@ -69,9 +78,10 @@ static int run(int argc, char *argv[]) { log_setup(); - if (argc > 2) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "This program expects 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; umask(0022); @@ -97,8 +107,8 @@ static int run(int argc, char *argv[]) { } _cleanup_free_ char *path = NULL; - if (argc == 2) { - path = strdup(argv[1]); + if (args[0]) { + path = strdup(args[0]); if (!path) return log_oom(); } diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index 23cc104a4d4..5e2753b0354 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -139,6 +139,7 @@ INTROSPECTABLE=( systemd-pstore systemd-pty-forward systemd-pull + systemd-quotacheck systemd-random-seed systemd-remount-fs systemd-repart