From: Zbigniew Jędrzejewski-Szmek Date: Mon, 13 Mar 2023 17:12:04 +0000 (+0100) Subject: udev: implement --version in all builtins X-Git-Tag: v254-rc1~936^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5356761da67aa5c11f784c3ba9ac8d8f6e55048b;p=thirdparty%2Fsystemd.git udev: implement --version in all builtins Those are separate binaries, and occasionally people will get a misplaced binary that doesn't match the rest of the installed system and be confused, so it good to be able to check the version. It is also nice to have the same interface in all binaries. Note that we usually use a separate 'enum ARG_VERSION = 0x100' for an option without a short name. We can use a less verbose approach of simply taking any unused letter, which works just as well and even the compiler would warn us if we tried to use the letter in another place. This way we avoid a few lines of boilerplate. The help texts are adjusted to have an empty line between the synopsis and option list, and no empty lines after the option list. --- diff --git a/man/udevadm.xml b/man/udevadm.xml index 503ec810918..e520c98143a 100644 --- a/man/udevadm.xml +++ b/man/udevadm.xml @@ -739,6 +739,7 @@ + diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index ec472feada3..7760d248cfb 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -23,6 +23,7 @@ #include #include +#include "build.h" #include "device-nodes.h" #include "fd-util.h" #include "log.h" @@ -361,8 +362,9 @@ static int disk_identify(int fd, static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { - { "export", no_argument, NULL, 'x' }, - { "help", no_argument, NULL, 'h' }, + { "export", no_argument, NULL, 'x' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, {} }; int c; @@ -375,9 +377,12 @@ static int parse_argv(int argc, char *argv[]) { case 'h': printf("%s [OPTIONS...] DEVICE\n\n" " -x --export Print values as environment keys\n" - " -h --help Show this help text\n", + " -h --help Show this help text\n" + " --version Show package version\n", program_invocation_short_name); return 0; + case 'v': + return version(); case '?': return -EINVAL; default: diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 3d58100f3e5..5b5fbd0109a 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -10,6 +10,7 @@ #include #include +#include "build.h" #include "fd-util.h" #include "main-func.h" #include "memory-util.h" @@ -897,13 +898,13 @@ static void print_properties(const Context *c) { } static int help(void) { - printf("Usage: %s [options] \n" - " -l --lock-media lock the media (to enable eject request events)\n" - " -u --unlock-media unlock the media\n" - " -e --eject-media eject the media\n" - " -d --debug print debug messages to stderr\n" - " -h --help print this help text\n" - "\n", + printf("%s [OPTIONS...] DEVICE\n\n" + " -l --lock-media Lock the media (to enable eject request events)\n" + " -u --unlock-media Unlock the media\n" + " -e --eject-media Eject the media\n" + " -d --debug Print debug messages to stderr\n" + " -h --help Show this help text\n" + " --version Show package version\n", program_invocation_short_name); return 0; @@ -916,6 +917,7 @@ static int parse_argv(int argc, char *argv[]) { { "eject-media", no_argument, NULL, 'e' }, { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, {} }; int c; @@ -938,6 +940,8 @@ static int parse_argv(int argc, char *argv[]) { break; case 'h': return help(); + case 'v': + return version(); case '?': return -EINVAL; default: diff --git a/src/udev/dmi_memory_id/dmi_memory_id.c b/src/udev/dmi_memory_id/dmi_memory_id.c index 1345289219e..dd46113137c 100644 --- a/src/udev/dmi_memory_id/dmi_memory_id.c +++ b/src/udev/dmi_memory_id/dmi_memory_id.c @@ -45,6 +45,7 @@ #include #include "alloc-util.h" +#include "build.h" #include "fileio.h" #include "main-func.h" #include "string-util.h" @@ -638,9 +639,10 @@ static int legacy_decode(const uint8_t *buf, const char *devmem, bool no_file_of } static int help(void) { - printf("Usage: %s [options]\n" - " -F,--from-dump FILE read DMI information from a binary file\n" - " -h,--help print this help text\n\n", + printf("%s [OPTIONS...]\n\n" + " -F --from-dump FILE Read DMI information from a binary file\n" + " -h --help Show this help text\n" + " --version Show package version\n", program_invocation_short_name); return 0; } @@ -650,6 +652,7 @@ static int parse_argv(int argc, char * const *argv) { { "from-dump", required_argument, NULL, 'F' }, { "version", no_argument, NULL, 'V' }, { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, {} }; int c; @@ -666,6 +669,8 @@ static int parse_argv(int argc, char * const *argv) { return help(); case '?': return -EINVAL; + case 'v': + return version(); default: assert_not_reached(); } diff --git a/src/udev/fido_id/fido_id.c b/src/udev/fido_id/fido_id.c index 11f5320d2bb..e01f37d04c4 100644 --- a/src/udev/fido_id/fido_id.c +++ b/src/udev/fido_id/fido_id.c @@ -15,6 +15,7 @@ #include #include +#include "build.h" #include "device-private.h" #include "device-util.h" #include "fd-util.h" @@ -30,7 +31,8 @@ static const char *arg_device = NULL; static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, {} }; int c; @@ -39,9 +41,12 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': printf("%s [OPTIONS...] SYSFS_PATH\n\n" - " -h --help Show this help text\n", + " -h --help Show this help text\n" + " --version Show package version\n", program_invocation_short_name); return 0; + case 'v': + return version(); case '?': return -EINVAL; default: diff --git a/src/udev/mtd_probe/mtd_probe.c b/src/udev/mtd_probe/mtd_probe.c index 513491ed6cf..1035320490a 100644 --- a/src/udev/mtd_probe/mtd_probe.c +++ b/src/udev/mtd_probe/mtd_probe.c @@ -30,6 +30,7 @@ #include #include "alloc-util.h" +#include "build.h" #include "fd-util.h" #include "main-func.h" #include "mtd_probe.h" @@ -38,7 +39,8 @@ static const char *arg_device = NULL; static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, {} }; int c; @@ -47,9 +49,12 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { case 'h': printf("%s /dev/mtd[n]\n\n" - " -h --help Show this help text\n", + " -h --help Show this help text\n" + " --version Show package version\n", program_invocation_short_name); return 0; + case 'v': + return version(); case '?': return -EINVAL; default: diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c index 98075db0ce2..1d176a387e5 100644 --- a/src/udev/v4l_id/v4l_id.c +++ b/src/udev/v4l_id/v4l_id.c @@ -26,6 +26,7 @@ #include #include +#include "build.h" #include "fd-util.h" #include "main-func.h" @@ -33,7 +34,8 @@ static const char *arg_device = NULL; static int parse_argv(int argc, char *argv[]) { static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, {} }; int c; @@ -43,9 +45,12 @@ static int parse_argv(int argc, char *argv[]) { case 'h': printf("%s [OPTIONS...] DEVICE\n\n" "Video4Linux device identification.\n\n" - " -h --help Show this help text\n", + " -h --help Show this help text\n" + " --version Show package version\n", program_invocation_short_name); return 0; + case 'v': + return version(); case '?': return -EINVAL; default: