summaryrefslogtreecommitdiffstats
path: root/misc-utils
diff options
context:
space:
mode:
authorKarel Zak2012-06-19 13:01:29 +0200
committerKarel Zak2012-06-19 13:01:29 +0200
commit8acc8979c48775af37bcab5e8f787d9569144e17 (patch)
tree6c2c95511fb92e396771590c977ea95d5f8a6208 /misc-utils
parentpo: add *.h stuff to POTFILES (diff)
parentmore: fix pointer wrap around compiler warnings (diff)
downloadkernel-qcow2-util-linux-8acc8979c48775af37bcab5e8f787d9569144e17.tar.gz
kernel-qcow2-util-linux-8acc8979c48775af37bcab5e8f787d9569144e17.tar.xz
kernel-qcow2-util-linux-8acc8979c48775af37bcab5e8f787d9569144e17.zip
Merge branch '2012wk24' of git://github.com/kerolasa/lelux-utiliteetit
* '2012wk24' of git://github.com/kerolasa/lelux-utiliteetit: (24 commits) more: fix pointer wrap around compiler warnings more: fix search repetition regression lscpu: values in /proc/bus/pci/devices are always unsigned scriptreplay: fix compiler format warning lib/mbsalign: abort() when non-expected case is encountered mkfs.cramfs: disallow unknown command line options fsck.cramfs: disallow unknown command line options setarch: disallow unknown command line options hexdump: print sensible message when all input file arguments fail mount: (new) use exclusive_option() dmesg: use exclusive_option() wipefs: use exclusive_option() wdctl: correct manual section reference wdctl: use exclusive_option() prlimit: use exclusive_option() lscpu: use exclusive_option() losetup: use exclusive_option() chcpu: use exclusive_option() lsblk: use exclusive_option() findmnt: use exclusive_option() ...
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/blkid.c20
-rw-r--r--misc-utils/findmnt.c38
-rw-r--r--misc-utils/lsblk.c32
-rw-r--r--misc-utils/wipefs.c13
4 files changed, 64 insertions, 39 deletions
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 840cfe4f6..579ad279f 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -44,6 +44,9 @@ extern int optind;
#define STRTOXX_EXIT_CODE BLKID_EXIT_OTHER /* strtoxx_or_err() */
#include "strutils.h"
+#define OPTUTILS_EXIT_CODE BLKID_EXIT_OTHER /* exclusive_option() */
+#include "optutils.h"
+
#include "closestream.h"
#include "ttyutils.h"
@@ -672,6 +675,13 @@ int main(int argc, char **argv)
int c;
uintmax_t offset = 0, size = 0;
+ enum {
+ EXCL_NONE,
+ EXCL_NAMES,
+ EXCL_USAGE
+ };
+ int excl_opt = EXCL_NONE;
+
show[0] = NULL;
atexit(close_stdout);
@@ -692,17 +702,11 @@ int main(int argc, char **argv)
search_type = strdup("LABEL");
break;
case 'n':
- if (fltr_usage) {
- fprintf(stderr, "error: -u and -n options are mutually exclusive\n");
- exit(BLKID_EXIT_OTHER);
- }
+ exclusive_option(&excl_opt, EXCL_NAMES, "-{u,n}");
fltr_type = list_to_types(optarg, &fltr_flag);
break;
case 'u':
- if (fltr_type) {
- fprintf(stderr, "error: -u and -n options are mutually exclusive\n");
- exit(BLKID_EXIT_OTHER);
- }
+ exclusive_option(&excl_opt, EXCL_USAGE, "-{u,n}");
fltr_usage = list_to_usage(optarg, &fltr_flag);
break;
case 'U':
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index eab224ab1..c4cebf8fa 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -42,6 +42,7 @@
#include "tt.h"
#include "strutils.h"
#include "xalloc.h"
+#include "optutils.h"
/* flags */
enum {
@@ -1010,12 +1011,6 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-static void __attribute__((__noreturn__))
-errx_mutually_exclusive(const char *opts)
-{
- errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
-}
-
int main(int argc, char *argv[])
{
struct libmnt_table *tb = NULL;
@@ -1024,6 +1019,20 @@ int main(int argc, char *argv[])
int i, c, rc = -1, timeout = -1;
int ntabfiles = 0, tabtype = 0;
+ enum {
+ EXCL_NONE,
+
+ EXCL_FSTAB,
+ EXCL_KERNEL,
+ EXCL_MTAB,
+
+ EXCL_RAW,
+ EXCL_LIST,
+ EXCL_PAIRS
+ };
+ int excl_fmk = EXCL_NONE;
+ int excl_rlP = EXCL_NONE;
+
/* table.h */
struct tt *tt = NULL;
@@ -1136,37 +1145,34 @@ int main(int argc, char *argv[])
tt_flags &= ~TT_FL_TREE;
break;
case 'P':
+ exclusive_option(&excl_rlP, EXCL_PAIRS, "--{raw,list,pairs}");
tt_flags |= TT_FL_EXPORT;
tt_flags &= ~TT_FL_TREE;
break;
case 'm': /* mtab */
- if (tabtype)
- errx_mutually_exclusive("--{fstab,mtab,kernel}");
+ exclusive_option(&excl_fmk, EXCL_MTAB, "--{fstab,mtab,kernel}");
tabtype = TABTYPE_MTAB;
tt_flags &= ~TT_FL_TREE;
break;
case 's': /* fstab */
- if (tabtype)
- errx_mutually_exclusive("--{fstab,mtab,kernel}");
+ exclusive_option(&excl_fmk, EXCL_FSTAB, "--{fstab,mtab,kernel}");
tabtype = TABTYPE_FSTAB;
tt_flags &= ~TT_FL_TREE;
break;
case 'k': /* kernel (mountinfo) */
- if (tabtype)
- errx_mutually_exclusive("--{fstab,mtab,kernel}");
+ exclusive_option(&excl_fmk, EXCL_KERNEL, "--{fstab,mtab,kernel}");
tabtype = TABTYPE_KERNEL;
break;
case 't':
set_match(COL_FSTYPE, optarg);
break;
case 'r':
+ exclusive_option(&excl_rlP, EXCL_RAW, "--{raw,list,pairs}");
tt_flags &= ~TT_FL_TREE; /* disable the default */
tt_flags |= TT_FL_RAW; /* enable raw */
break;
case 'l':
- if ((tt_flags & TT_FL_RAW) && (tt_flags & TT_FL_EXPORT))
- errx_mutually_exclusive("--{raw,list,pairs}");
-
+ exclusive_option(&excl_rlP, EXCL_LIST, "--{raw,list,pairs}");
tt_flags &= ~TT_FL_TREE; /* disable the default */
break;
case 'n':
@@ -1224,7 +1230,7 @@ int main(int argc, char *argv[])
if (flags & FL_POLL) {
if (tabtype != TABTYPE_KERNEL)
- errx_mutually_exclusive("--{poll,fstab,mtab}");
+ exclusive_option(&tabtype, tabtype + 1, "--{poll,fstab,mtab}");
if (ntabfiles > 1)
errx(EXIT_FAILURE, _("--poll accepts only one file, but more specified by --tab-file"));
}
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index bd5e6b782..f635a4a13 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -60,6 +60,7 @@
#include "sysfs.h"
#include "closestream.h"
#include "mangle.h"
+#include "optutils.h"
/* column IDs */
enum {
@@ -1138,12 +1139,6 @@ static void __attribute__((__noreturn__)) help(FILE *out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-static void __attribute__((__noreturn__))
-errx_mutually_exclusive(const char *opts)
-{
- errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
-}
-
static void check_sysdevblock(void)
{
if (access(_PATH_SYS_DEVBLOCK, R_OK) != 0)
@@ -1157,6 +1152,19 @@ int main(int argc, char *argv[])
int tt_flags = TT_FL_TREE;
int i, c, status = EXIT_FAILURE;
+ enum {
+ EXCL_NONE,
+
+ EXCL_RAW,
+ EXCL_LIST,
+ EXCL_PAIRS,
+
+ EXCL_ALL,
+ EXCL_EXCLUDE
+ };
+ int excl_rlP = EXCL_NONE;
+ int excl_ae = EXCL_NONE;
+
static const struct option longopts[] = {
{ "all", 0, 0, 'a' },
{ "bytes", 0, 0, 'b' },
@@ -1189,6 +1197,7 @@ int main(int argc, char *argv[])
while((c = getopt_long(argc, argv, "abdDe:fhlnmo:PirstV", longopts, NULL)) != -1) {
switch(c) {
case 'a':
+ exclusive_option(&excl_ae, EXCL_ALL, "--{all,exclude}");
lsblk->all_devices = 1;
break;
case 'b':
@@ -1205,15 +1214,14 @@ int main(int argc, char *argv[])
columns[ncolumns++] = COL_DZERO;
break;
case 'e':
+ exclusive_option(&excl_ae, EXCL_EXCLUDE, "--{all,exclude}");
parse_excludes(optarg);
break;
case 'h':
help(stdout);
break;
case 'l':
- if ((tt_flags & TT_FL_RAW)|| (tt_flags & TT_FL_EXPORT))
- errx_mutually_exclusive("--{raw,list,export}");
-
+ exclusive_option(&excl_rlP, EXCL_LIST, "--{raw,list,pairs}");
tt_flags &= ~TT_FL_TREE; /* disable the default */
break;
case 'n':
@@ -1227,6 +1235,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
break;
case 'P':
+ exclusive_option(&excl_rlP, EXCL_PAIRS, "--{raw,list,pairs}");
tt_flags |= TT_FL_EXPORT;
tt_flags &= ~TT_FL_TREE; /* disable the default */
break;
@@ -1234,6 +1243,7 @@ int main(int argc, char *argv[])
tt_flags |= TT_FL_ASCII;
break;
case 'r':
+ exclusive_option(&excl_rlP, EXCL_RAW, "--{raw,list,pairs}");
tt_flags &= ~TT_FL_TREE; /* disable the default */
tt_flags |= TT_FL_RAW; /* enable raw */
break;
@@ -1286,9 +1296,7 @@ int main(int argc, char *argv[])
columns[ncolumns++] = COL_TARGET;
}
- if (nexcludes && lsblk->all_devices)
- errx_mutually_exclusive("--{all,exclude}");
- else if (!nexcludes)
+ if (!nexcludes)
excludes[nexcludes++] = 1; /* default: ignore RAM disks */
mnt_init_debug(0);
diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c
index 259ca3766..f10b5ee4e 100644
--- a/misc-utils/wipefs.c
+++ b/misc-utils/wipefs.c
@@ -39,6 +39,7 @@
#include "match.h"
#include "c.h"
#include "closestream.h"
+#include "optutils.h"
struct wipe_desc {
loff_t offset; /* magic string offset */
@@ -382,6 +383,13 @@ main(int argc, char **argv)
int c, all = 0, has_offset = 0, noact = 0, quiet = 0;
int mode = WP_MODE_PRETTY;
+ enum {
+ EXCL_NONE,
+ EXCL_ALL,
+ EXCL_OFFSET
+ };
+ int excl_any = EXCL_NONE;
+
static const struct option longopts[] = {
{ "all", 0, 0, 'a' },
{ "help", 0, 0, 'h' },
@@ -402,6 +410,7 @@ main(int argc, char **argv)
while ((c = getopt_long(argc, argv, "ahno:pqt:V", longopts, NULL)) != -1) {
switch(c) {
case 'a':
+ exclusive_option(&excl_any, EXCL_ALL, "--{all,offset}");
all++;
break;
case 'h':
@@ -411,6 +420,7 @@ main(int argc, char **argv)
noact++;
break;
case 'o':
+ exclusive_option(&excl_any, EXCL_OFFSET, "--{all,offset}");
wp0 = add_offset(wp0, strtosize_or_err(optarg,
_("invalid offset argument")), 1);
has_offset++;
@@ -434,9 +444,6 @@ main(int argc, char **argv)
}
}
- if (wp0 && all)
- errx(EXIT_FAILURE, _("--offset and --all are mutually exclusive"));
-
if (optind == argc)
usage(stderr);