summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-03-13 18:12:04 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-03-16 16:46:44 +0100
commit5356761da67aa5c11f784c3ba9ac8d8f6e55048b (patch)
tree970588a1d900622bc063c410f42ae905de55db3c /src/udev
parentbd36d0281ab41bfea932931e913809ee1e6195ed (diff)
downloadsystemd-5356761da67aa5c11f784c3ba9ac8d8f6e55048b.tar.gz
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.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/ata_id/ata_id.c11
-rw-r--r--src/udev/cdrom_id/cdrom_id.c18
-rw-r--r--src/udev/dmi_memory_id/dmi_memory_id.c11
-rw-r--r--src/udev/fido_id/fido_id.c9
-rw-r--r--src/udev/mtd_probe/mtd_probe.c9
-rw-r--r--src/udev/v4l_id/v4l_id.c9
6 files changed, 48 insertions, 19 deletions
diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c
index ec472feada..7760d248cf 100644
--- a/src/udev/ata_id/ata_id.c
+++ b/src/udev/ata_id/ata_id.c
@@ -23,6 +23,7 @@
#include <sys/types.h>
#include <unistd.h>
+#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 3d58100f3e..5b5fbd0109 100644
--- a/src/udev/cdrom_id/cdrom_id.c
+++ b/src/udev/cdrom_id/cdrom_id.c
@@ -10,6 +10,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
+#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] <device>\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 1345289219..dd46113137 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 <getopt.h>
#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 11f5320d2b..e01f37d04c 100644
--- a/src/udev/fido_id/fido_id.c
+++ b/src/udev/fido_id/fido_id.c
@@ -15,6 +15,7 @@
#include <sys/types.h>
#include <unistd.h>
+#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 513491ed6c..1035320490 100644
--- a/src/udev/mtd_probe/mtd_probe.c
+++ b/src/udev/mtd_probe/mtd_probe.c
@@ -30,6 +30,7 @@
#include <unistd.h>
#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 98075db0ce..1d176a387e 100644
--- a/src/udev/v4l_id/v4l_id.c
+++ b/src/udev/v4l_id/v4l_id.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <linux/videodev2.h>
+#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: