options: introduce OPTION_COMMON_VERSION_WITH_V and version_only()

The man page udevadm(8) have explicitly documented that the option -V is
a short form of --version. Let's not hide the short form in the help
message.

This introduces OPTION_COMMON_VERSION_WITH_V then use it in udevadm,
udevd, and run0.

Alos, this moves print_version() to build.c, and renames it to
version_only(). Now the function is also used in udevd amd test-libudev.

With this change, the -V option is hidden only in dmi_memory_id and
scsi_id. So, this removes the OPTION_COMMON_VERSION_WITH_HIDDEN_V macro
and explicitly list the hidden option in their code.
This commit is contained in:
Yu Watanabe
2026-08-29 07:40:35 +09:00
parent 39cf979007
commit 69a54c37ac
22 changed files with 62 additions and 53 deletions
+6
View File
@@ -280,3 +280,9 @@ int version(void) {
b ?: systemd_features);
return 0;
}
int version_only(void) {
/* Used by udev. Dracut relies on the version being a single integer */
puts(PROJECT_VERSION_STR);
return 0;
}
+1
View File
@@ -6,3 +6,4 @@
extern const char* const systemd_features;
int version(void);
int version_only(void);
+3 -4
View File
@@ -5,6 +5,7 @@
#include "sd-json.h"
#include "build.h"
#include "devnum-util.h"
#include "fd-util.h"
#include "libudev-list-internal.h"
@@ -15,7 +16,6 @@
#include "string-util.h"
#include "tests.h"
#include "verbs.h"
#include "version.h"
static bool arg_monitor = false;
@@ -426,9 +426,8 @@ static int parse_args(int argc, char *argv[], const char **syspath, const char *
OPTION_COMMON_HELP:
return command_print_help();
OPTION('V', "version", NULL, "Show package version"):
printf("%s\n", GIT_VERSION);
return 0;
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('p', "syspath", "PATH", "Syspath to test"):
*syspath = opts.arg;
+1 -1
View File
@@ -786,7 +786,7 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_help_name("run0");
OPTION('V', "version", NULL, "Show package version"):
OPTION_COMMON_VERSION_WITH_V:
return version();
OPTION_COMMON_NO_ASK_PASSWORD:
+4 -5
View File
@@ -95,6 +95,10 @@ assert_cc(sizeof(Option) % sizeof(void*) == 0);
#define OPTION_COMMON_VERSION \
OPTION_LONG("version", NULL, "Show package version")
/* A form used in udev, udevadm, and run0. */
#define OPTION_COMMON_VERSION_WITH_V \
OPTION('V', "version", NULL, "Show package version")
#define OPTION_COMMON_INTROSPECT_CLI \
/* This option is internal-only for now and not shown in --help */ \
OPTION_LONG("introspect-cli", NULL, /* help= */ NULL)
@@ -177,11 +181,6 @@ assert_cc(sizeof(Option) % sizeof(void*) == 0);
"Allows the certificate to be loaded from an OpenSSL provider " \
"(file, provider:PROVIDER)")
/* A form used in udev code for compatibility. -V is accepted but not documented. */
#define OPTION_COMMON_VERSION_WITH_HIDDEN_V \
OPTION_COMMON_VERSION: {} \
OPTION_SHORT('V', NULL, /* help= */ NULL)
#define OPTION_COMMON_RESOLVE_NAMES \
OPTION('N', "resolve-names", "MODE", \
"When to resolve users and groups (early, late, or never)")
+2 -1
View File
@@ -661,7 +661,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_help();
OPTION_COMMON_VERSION_WITH_HIDDEN_V:
OPTION_COMMON_VERSION: {}
OPTION_SHORT('V', NULL, /* help= */ NULL): /* -V is accepted but not documented. */
return version();
OPTION('F', "from-dump", "FILE",
+2 -1
View File
@@ -225,7 +225,8 @@ static int set_options(int argc, char **argv, char *maj_min_dev) {
OPTION_COMMON_HELP:
return command_print_help();
OPTION_COMMON_VERSION_WITH_HIDDEN_V:
OPTION_COMMON_VERSION: {}
OPTION_SHORT('V', NULL, /* help= */ NULL): /* -V is accepted but not documented. */
return version();
OPTION('d', "device", "PATH", "Device node for SG_IO commands"):
+3 -4
View File
@@ -4,6 +4,7 @@
#include "sd-json.h"
#include "build.h"
#include "conf-parser.h"
#include "cpu-set-util.h"
#include "daemon-util.h"
@@ -26,7 +27,6 @@
#include "udev-util.h"
#include "udev-worker.h"
#include "verbs.h"
#include "version.h"
#define WORKER_NUM_MAX UINT64_C(2048)
@@ -177,9 +177,8 @@ static int parse_argv(int argc, char *argv[], UdevConfig *config) {
OPTION_COMMON_HELP:
return command_print_help_name("systemd-udevd");
OPTION('V', "version", NULL, "Show package version"):
printf("%s\n", GIT_VERSION);
return 0;
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('d', "daemon", NULL, "Detach and run in the background"):
arg_daemonize = true;
+3 -2
View File
@@ -3,6 +3,7 @@
#include "sd-json.h"
#include "alloc-util.h"
#include "build.h"
#include "conf-files.h"
#include "log.h"
#include "options.h"
@@ -36,8 +37,8 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) {
OPTION_COMMON_HELP:
return command_print_verb_help("cat");
OPTION_COMMON_VERSION_WITH_HIDDEN_V:
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION_LONG("root", "PATH",
"Operate on an alternate filesystem root"):
+3 -2
View File
@@ -4,6 +4,7 @@
#include "sd-json.h"
#include "build.h"
#include "creds-util.h"
#include "log.h"
#include "options.h"
@@ -62,8 +63,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("control");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('e', "exit", NULL, "Instruct the daemon to cleanup and exit"):
arg_exit = true;
+3 -2
View File
@@ -2,6 +2,7 @@
#include "sd-json.h"
#include "build.h"
#include "hwdb-util.h"
#include "log.h"
#include "options.h"
@@ -28,8 +29,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("hwdb");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('u', "update", NULL, "Update the hardware database"):
arg_update = true;
+3 -2
View File
@@ -12,6 +12,7 @@
#include "alloc-util.h"
#include "ansi-color.h"
#include "build.h"
#include "device-enumerator-private.h"
#include "device-private.h"
#include "device-util.h"
@@ -977,8 +978,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("info");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('q', "query", "TYPE", "Query device information:"): {}
OPTION_HELP_VERBATIM(" name", "- name of device node"): {}
+3 -2
View File
@@ -6,6 +6,7 @@
#include "sd-json.h"
#include "build.h"
#include "blockdev-util.h"
#include "device-util.h"
#include "fd-util.h"
@@ -51,8 +52,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("lock");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('d', "device", "DEVICE", "Block device to lock"): {} /* fall through */
OPTION('b', "backing", "FILE", "File whose backing block device to lock"): {
+3 -2
View File
@@ -5,6 +5,7 @@
#include "sd-json.h"
#include "alloc-util.h"
#include "build.h"
#include "device-monitor-private.h"
#include "device-private.h"
#include "device-util.h"
@@ -115,8 +116,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("monitor");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('e', "environment", NULL, /* help= */ NULL): {} /* hidden alias for -p */
OPTION('p', "property", NULL, "Print the event properties"):
+3 -2
View File
@@ -13,6 +13,7 @@
#include "sd-messages.h"
#include "alloc-util.h"
#include "build.h"
#include "bus-util.h"
#include "options.h"
#include "path-util.h"
@@ -45,8 +46,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("settle");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('t', "timeout", "SEC", "Maximum time to wait for events"):
r = parse_sec(opts.arg, &arg_timeout_usec);
+3 -2
View File
@@ -2,6 +2,7 @@
#include "sd-json.h"
#include "build.h"
#include "device-private.h"
#include "device-util.h"
#include "log.h"
@@ -37,8 +38,8 @@ static int parse_argv(int argc, char *argv[]) {
udev_builtin_list();
return 0;
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('a', "action", "ACTION|help", "Set action string"):
r = parse_device_action(opts.arg, &arg_action);
+3 -2
View File
@@ -10,6 +10,7 @@
#include "sd-json.h"
#include "alloc-util.h"
#include "build.h"
#include "device-private.h"
#include "log.h"
#include "options.h"
@@ -49,8 +50,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("test");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('a', "action", "ACTION|help", "Set action string"):
r = parse_device_action(opts.arg, &arg_action);
+3 -2
View File
@@ -7,6 +7,7 @@
#include "sd-json.h"
#include "alloc-util.h"
#include "build.h"
#include "device-enumerator-private.h"
#include "device-private.h"
#include "device-util.h"
@@ -337,8 +338,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("trigger");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('v', "verbose", NULL, "Print the list of devices while running"):
arg_verbose = true;
+3 -2
View File
@@ -6,6 +6,7 @@
#include "alloc-util.h"
#include "ansi-color.h"
#include "build.h"
#include "conf-files.h"
#include "errno-util.h"
#include "log.h"
@@ -41,8 +42,8 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) {
OPTION_COMMON_HELP:
return command_print_verb_help("verify");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION_COMMON_RESOLVE_NAMES:
r = parse_resolve_name_timing(opts.arg, &arg_resolve_name_timing);
+3 -2
View File
@@ -6,6 +6,7 @@
#include "sd-event.h"
#include "sd-json.h"
#include "build.h"
#include "device-monitor-private.h"
#include "device-util.h"
#include "event-util.h"
@@ -314,8 +315,8 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_HELP:
return command_print_verb_help("wait");
OPTION('V', "version", NULL, "Show package version"):
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('t', "timeout", "SEC", "Maximum time to wait for the device"):
r = parse_sec(opts.arg, &arg_timeout_usec);
+4 -11
View File
@@ -1,10 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include <stdio.h>
#include "sd-json.h"
#include "argv-util.h"
#include "build.h"
#include "dlopen-note.h"
#include "label-util.h"
#include "main-func.h"
@@ -49,7 +48,7 @@ UDEVADM_VERB(verb_hwdb_main, "hwdb", NULL, VERB_DEPRE
VERB_NOARG(verb_version_main, "version", /* help= */ NULL);
static int verb_version_main(int argc, char *argv[], uintptr_t _data, void *userdata) {
return print_version();
return version_only();
}
static int parse_argv(int argc, char *argv[], char ***remaining_args) {
@@ -67,8 +66,8 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) {
OPTION_COMMON_HELP:
return command_print_help_name("udevadm");
OPTION_COMMON_VERSION_WITH_HIDDEN_V:
return print_version();
OPTION_COMMON_VERSION_WITH_V:
return version_only();
OPTION('d', "debug", NULL, "Enable debug logging"):
log_set_max_level(LOG_DEBUG);
@@ -82,12 +81,6 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) {
return 1; /* work to do */
}
int print_version(void) {
/* Dracut relies on the version being a single integer */
puts(PROJECT_VERSION_STR);
return 0;
}
static int run(int argc, char *argv[]) {
char **args = NULL;
int r;
-2
View File
@@ -17,5 +17,3 @@ int verb_builtin_main(int argc, char *argv[], uintptr_t _data, void *userdata);
int verb_verify_main(int argc, char *argv[], uintptr_t _data, void *userdata);
int verb_wait_main(int argc, char *argv[], uintptr_t _data, void *userdata);
int verb_lock_main(int argc, char *argv[], uintptr_t _data, void *userdata);
int print_version(void);