summaryrefslogtreecommitdiffstats
path: root/misc-utils/lsblk.c
diff options
context:
space:
mode:
authorKarel Zak2012-06-19 17:41:35 +0200
committerKarel Zak2012-06-19 17:41:35 +0200
commit2dc03af7f0336e0f1d21acee064f1c7c4ed9d53e (patch)
treee1ad79a4849e05f046dab804acaad640863c4c06 /misc-utils/lsblk.c
parentlibmount: improve ifdef HAVE_LIBSELINUX stuff (diff)
downloadkernel-qcow2-util-linux-2dc03af7f0336e0f1d21acee064f1c7c4ed9d53e.tar.gz
kernel-qcow2-util-linux-2dc03af7f0336e0f1d21acee064f1c7c4ed9d53e.tar.xz
kernel-qcow2-util-linux-2dc03af7f0336e0f1d21acee064f1c7c4ed9d53e.zip
lsblk: fix usage, improve exclude/include lists parsing
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r--misc-utils/lsblk.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 0bcdbfcee..fcc1acffa 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -142,7 +142,7 @@ static struct colinfo infos[] = {
struct lsblk {
struct tt *tt; /* output table */
- unsigned int all_devices:1; /* print all devices, icluding empty */
+ unsigned int all_devices:1; /* print all devices, including empty */
unsigned int bytes:1; /* print SIZE in bytes */
unsigned int inverse:1; /* print inverse dependencies */
unsigned int nodeps:1; /* don't print slaves/holders */
@@ -1100,8 +1100,10 @@ leave:
return status;
}
-static void parse_excludes(const char *str)
+static void parse_excludes(const char *str0)
{
+ const char *str = str0;
+
while (str && *str) {
char *end = NULL;
unsigned long n;
@@ -1109,8 +1111,10 @@ static void parse_excludes(const char *str)
errno = 0;
n = strtoul(str, &end, 10);
- if (end == str || (errno != 0 && (n == ULONG_MAX || n == 0)))
- err(EXIT_FAILURE, _("failed to parse list '%s'"), str);
+ if (end == str || (end && *end && *end != ','))
+ errx(EXIT_FAILURE, _("failed to parse list '%s'"), str0);
+ if (errno != 0 && (n == ULONG_MAX || n == 0))
+ err(EXIT_FAILURE, _("failed to parse list '%s'"), str0);
excludes[nexcludes++] = n;
if (nexcludes == ARRAY_SIZE(excludes))
@@ -1118,12 +1122,15 @@ static void parse_excludes(const char *str)
errx(EXIT_FAILURE, _("the list of excluded devices is "
"too large (limit is %d devices)"),
(int)ARRAY_SIZE(excludes));
+
str = end && *end ? end + 1 : NULL;
}
}
-static void parse_includes(const char *str)
+static void parse_includes(const char *str0)
{
+ const char *str = str0;
+
while (str && *str) {
char *end = NULL;
unsigned long n;
@@ -1131,8 +1138,10 @@ static void parse_includes(const char *str)
errno = 0;
n = strtoul(str, &end, 10);
- if (end == str || (errno != 0 && (n == ULONG_MAX || n == 0)))
- err(EXIT_FAILURE, _("failed to parse list '%s'"), str);
+ if (end == str || (end && *end && *end != ','))
+ errx(EXIT_FAILURE, _("failed to parse list '%s'"), str0);
+ if (errno != 0 && (n == ULONG_MAX || n == 0))
+ err(EXIT_FAILURE, _("failed to parse list '%s'"), str0);
includes[nincludes++] = n;
if (nincludes == ARRAY_SIZE(includes))
@@ -1159,7 +1168,7 @@ static void __attribute__((__noreturn__)) help(FILE *out)
" -d, --nodeps don't print slaves or holders\n"
" -D, --discard print discard capabilities\n"
" -e, --exclude <list> exclude devices by major number (default: RAM disks)\n"
- " -i, --include <list> show only devices with specified major numbers\n"
+ " -I, --include <list> show only devices with specified major numbers\n"
" -f, --fs output info about filesystems\n"
" -h, --help usage information (this)\n"
" -i, --ascii use ascii characters only\n"