From 7093a70b514529d6912125b6f8955e49105ba24c Mon Sep 17 00:00:00 2001 From: Jan Polensky Date: Mon, 23 Mar 2026 18:52:14 +0100 Subject: [PATCH] dasdinfo: Drop obsolete kernel check and use errx() for arg errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the uname()/sscanf()-based kernel version gate (Linux < 2.6), which is long obsolete and does not belong in user-space argument validation. While touching the code, replace the repeated warnx() + exit(1) pattern with errx(EXIT_FAILURE, ...) in the option sanity checks to reduce boilerplate and keep error paths consistent. Behaviour is unchanged for supported environments; the version gate is dropped because it is obsolete. Reviewed-by: Jan Höppner Signed-off-by: Jan Polensky Signed-off-by: Jan Höppner --- dasdinfo/dasdinfo.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/dasdinfo/dasdinfo.c b/dasdinfo/dasdinfo.c index f643bc06..4b848dc5 100644 --- a/dasdinfo/dasdinfo.c +++ b/dasdinfo/dasdinfo.c @@ -550,8 +550,6 @@ static int dinfo_get_uid_from_devnode(char **uidfile, char *devnode) int main(int argc, char *argv[]) { - struct utsname uname_buf; - int version, release; char *uidfile = NULL; char *device = NULL; char *readbuf = NULL; @@ -616,29 +614,14 @@ int main(int argc, char *argv[]) } } - uname(&uname_buf); - sscanf(uname_buf.release, "%d.%d", &version, &release); - if (strcmp(uname_buf.sysname, "Linux") || - version < 2 || (version == 2 && release < 6)) { - warnx("%s %d.%d is not supported", uname_buf.sysname, - version, release); - exit(1); - } + if (!busid && !blockdev && !devnode) + errx(EXIT_FAILURE, "Error: please specify a device using either -b, -i or -d"); - if (!busid && !blockdev && !devnode) { - warnx("Error: please specify a device using either -b, -i or -d"); - exit(1); - } + if ((busid && blockdev) || (busid && devnode) || (blockdev && devnode)) + errx(EXIT_FAILURE, "Error: please specify device only once, either -b, -i or -d"); - if ((busid && blockdev) || (busid && devnode) || (blockdev && devnode)) { - warnx("Error: please specify device only once, either -b, -i or -d"); - exit(1); - } - - if (!print_uid && !print_extended_uid && !print_vlabel) { - warnx("Error: no action specified (e.g. -u)"); - exit(1); - } + if (!print_uid && !print_extended_uid && !print_vlabel) + errx(EXIT_FAILURE, "Error: no action specified (e.g. -u)"); readbuf = dinfo_malloc(RD_BUFFER_SIZE); if (!readbuf)