diff --git a/src/basic/build.c b/src/basic/build.c index 965d4f5a36..2da23c3d0d 100644 --- a/src/basic/build.c +++ b/src/basic/build.c @@ -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; +} diff --git a/src/basic/build.h b/src/basic/build.h index 3f1211e708..949c0209a9 100644 --- a/src/basic/build.h +++ b/src/basic/build.h @@ -6,3 +6,4 @@ extern const char* const systemd_features; int version(void); +int version_only(void); diff --git a/src/libudev/test-libudev.c b/src/libudev/test-libudev.c index 2c09e59d62..46b22940af 100644 --- a/src/libudev/test-libudev.c +++ b/src/libudev/test-libudev.c @@ -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; diff --git a/src/run/run.c b/src/run/run.c index 104c77768a..b4b5df1634 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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: diff --git a/src/shared/options.h b/src/shared/options.h index 83e72188b4..f98ab6ccf7 100644 --- a/src/shared/options.h +++ b/src/shared/options.h @@ -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)") diff --git a/src/udev/dmi_memory_id/dmi_memory_id.c b/src/udev/dmi_memory_id/dmi_memory_id.c index 3a7b22941e..ac6d42f35d 100644 --- a/src/udev/dmi_memory_id/dmi_memory_id.c +++ b/src/udev/dmi_memory_id/dmi_memory_id.c @@ -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", diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c index 7f1267d09d..9792d0bf73 100644 --- a/src/udev/scsi_id/scsi_id.c +++ b/src/udev/scsi_id/scsi_id.c @@ -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"): diff --git a/src/udev/udev-config.c b/src/udev/udev-config.c index 0733f41872..3a1a8ea9ea 100644 --- a/src/udev/udev-config.c +++ b/src/udev/udev-config.c @@ -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; diff --git a/src/udev/udevadm-cat.c b/src/udev/udevadm-cat.c index 936455c24a..a55b7d9b64 100644 --- a/src/udev/udevadm-cat.c +++ b/src/udev/udevadm-cat.c @@ -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"): diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index d1c0ac4e6d..393cc800a6 100644 --- a/src/udev/udevadm-control.c +++ b/src/udev/udevadm-control.c @@ -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; diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 143a3a621d..776efc19a1 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -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; diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index 4fb9735e47..a4fd2ccd7e 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -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"): {} diff --git a/src/udev/udevadm-lock.c b/src/udev/udevadm-lock.c index f0cc57e43c..a36ee61681 100644 --- a/src/udev/udevadm-lock.c +++ b/src/udev/udevadm-lock.c @@ -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"): { diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index ef936cb7d1..a49aa44714 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -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"): diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index dfd00e4b0d..43d82f2b27 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -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); diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 384c53a8b7..a4e2245d7f 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -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); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index a496f81b99..7af0decaaf 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -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); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index bd1d3267d4..9eeef37ffe 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -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; diff --git a/src/udev/udevadm-verify.c b/src/udev/udevadm-verify.c index d850315ca8..a97c0f4e76 100644 --- a/src/udev/udevadm-verify.c +++ b/src/udev/udevadm-verify.c @@ -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); diff --git a/src/udev/udevadm-wait.c b/src/udev/udevadm-wait.c index cdee4c8c58..97928779f5 100644 --- a/src/udev/udevadm-wait.c +++ b/src/udev/udevadm-wait.c @@ -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); diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c index 359c04b30f..e320acccb2 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -1,10 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include - #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; diff --git a/src/udev/udevadm.h b/src/udev/udevadm.h index 2af2bc646b..c7f18bf0d6 100644 --- a/src/udev/udevadm.h +++ b/src/udev/udevadm.h @@ -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);