summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorRuediger Meier2017-06-19 20:52:50 +0200
committerRuediger Meier2017-06-26 14:38:24 +0200
commit6e1eda6f229f87b77471ce6eb7cbf0ede7c8029e (patch)
tree5e74a0cd99493e934780db2b434c75e995a6bd17 /sys-utils
parentmisc: never use usage(ERROR) (diff)
downloadkernel-qcow2-util-linux-6e1eda6f229f87b77471ce6eb7cbf0ede7c8029e.tar.gz
kernel-qcow2-util-linux-6e1eda6f229f87b77471ce6eb7cbf0ede7c8029e.tar.xz
kernel-qcow2-util-linux-6e1eda6f229f87b77471ce6eb7cbf0ede7c8029e.zip
misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/blkdiscard.c9
-rw-r--r--sys-utils/chcpu.c13
-rw-r--r--sys-utils/chmem.c13
-rw-r--r--sys-utils/dmesg.c13
-rw-r--r--sys-utils/fsfreeze.c17
-rw-r--r--sys-utils/fstrim.c9
-rw-r--r--sys-utils/ipcmk.c14
-rw-r--r--sys-utils/ipcrm.c9
-rw-r--r--sys-utils/losetup.c10
-rw-r--r--sys-utils/lscpu.c13
-rw-r--r--sys-utils/lsmem.c11
-rw-r--r--sys-utils/mount.c25
-rw-r--r--sys-utils/mountpoint.c13
-rw-r--r--sys-utils/pivot_root.c22
-rw-r--r--sys-utils/setsid.c13
-rw-r--r--sys-utils/swapoff.c13
-rw-r--r--sys-utils/swapon.c14
-rw-r--r--sys-utils/switch_root.c19
-rw-r--r--sys-utils/tunelp.c21
-rw-r--r--sys-utils/umount.c10
20 files changed, 169 insertions, 112 deletions
diff --git a/sys-utils/blkdiscard.c b/sys-utils/blkdiscard.c
index 7f2db58b1..e6a9dce5c 100644
--- a/sys-utils/blkdiscard.c
+++ b/sys-utils/blkdiscard.c
@@ -77,8 +77,9 @@ static void print_stats(int act, char *path, uint64_t stats[])
}
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] <device>\n"), program_invocation_short_name);
@@ -99,7 +100,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("blkdiscard(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
@@ -136,7 +137,7 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, "hVsvo:l:p:z", longopts, NULL)) != -1) {
switch(c) {
case 'h':
- usage(stdout);
+ usage();
break;
case 'V':
printf(UTIL_LINUX_VERSION);
@@ -174,7 +175,7 @@ int main(int argc, char **argv)
if (optind != argc) {
warnx(_("unexpected number of arguments"));
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
fd = open(path, O_WRONLY);
diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c
index 30afa457c..c0f568073 100644
--- a/sys-utils/chcpu.c
+++ b/sys-utils/chcpu.c
@@ -232,8 +232,9 @@ static void cpu_parse(char *cpu_string, cpu_set_t *cpu_set, size_t setsize)
errx(EXIT_FAILURE, _("failed to parse CPU list: %s"), cpu_string);
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fprintf(out, _(
"\nUsage:\n"
" %s [options]\n"), program_invocation_short_name);
@@ -251,7 +252,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
" -r, --rescan trigger rescan of cpus\n"
" -V, --version output version information and exit\n"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
@@ -316,7 +317,7 @@ int main(int argc, char *argv[])
cpu_parse(argv[optind - 1], cpu_set, setsize);
break;
case 'h':
- usage(stdout);
+ usage();
case 'p':
if (strcmp("horizontal", argv[optind - 1]) == 0)
cmd = CMD_CPU_DISPATCH_HORIZONTAL;
@@ -337,8 +338,10 @@ int main(int argc, char *argv[])
}
}
- if ((argc == 1) || (argc != optind))
- usage(stderr);
+ if ((argc == 1) || (argc != optind)) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
switch (cmd) {
case CMD_CPU_ENABLE:
diff --git a/sys-utils/chmem.c b/sys-utils/chmem.c
index 44733bf76..7f7be6ab6 100644
--- a/sys-utils/chmem.c
+++ b/sys-utils/chmem.c
@@ -234,8 +234,9 @@ static void parse_parameter(struct chmem_desc *desc, char *param)
errx(EXIT_FAILURE, _("Invalid range: %s"), param);
}
-static void __attribute__((__noreturn__)) chmem_usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] [SIZE|RANGE|BLOCKRANGE]\n"), program_invocation_short_name);
@@ -253,7 +254,7 @@ static void __attribute__((__noreturn__)) chmem_usage(FILE *out)
fprintf(out, USAGE_MAN_TAIL("chmem(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -300,7 +301,7 @@ int main(int argc, char **argv)
desc->use_blocks = 1;
break;
case 'h':
- chmem_usage(stdout);
+ usage();
break;
case 'v':
desc->verbose = 1;
@@ -313,8 +314,10 @@ int main(int argc, char **argv)
}
}
- if ((argc == 1) || (argc != optind + 1) || (cmd == CMD_NONE))
- chmem_usage(stderr);
+ if ((argc == 1) || (argc != optind + 1) || (cmd == CMD_NONE)) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
parse_parameter(desc, argv[optind]);
diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index 37639ebe5..cd5da90f4 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -266,8 +266,9 @@ static int set_level_color(int log_level, const char *mesg, size_t mesgsz)
return id >= 0 ? 0 : -1;
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
size_t i;
fputs(USAGE_HEADER, out);
@@ -320,7 +321,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
_(level_names[i].help));
fputs(USAGE_SEPARATOR, out);
fprintf(out, USAGE_MAN_TAIL("dmesg(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
/*
@@ -1422,7 +1423,7 @@ int main(int argc, char *argv[])
ctl.pager = 1;
break;
case 'h':
- usage(stdout);
+ usage();
break;
case 'k':
ctl.fltr_fac = 1;
@@ -1487,8 +1488,10 @@ int main(int argc, char *argv[])
}
}
- if (argc != optind)
- usage(stderr);
+ if (argc != optind) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
if ((is_timefmt(&ctl, RELTIME) ||
is_timefmt(&ctl, CTIME) ||
diff --git a/sys-utils/fsfreeze.c b/sys-utils/fsfreeze.c
index b1fa4fa8c..8b0d5d10e 100644
--- a/sys-utils/fsfreeze.c
+++ b/sys-utils/fsfreeze.c
@@ -33,9 +33,10 @@ enum fs_operation {
UNFREEZE
};
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
- fprintf(out, USAGE_HEADER);
+ FILE *out = stdout;
+ fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] <mountpoint>\n"), program_invocation_short_name);
@@ -45,12 +46,12 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_OPTIONS, out);
fputs(_(" -f, --freeze freeze the filesystem\n"), out);
fputs(_(" -u, --unfreeze unfreeze the filesystem\n"), out);
- fprintf(out, USAGE_SEPARATOR);
- fprintf(out, USAGE_HELP);
- fprintf(out, USAGE_VERSION);
+ fputs(USAGE_SEPARATOR, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("fsfreeze(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -85,7 +86,7 @@ int main(int argc, char **argv)
switch(c) {
case 'h':
- usage(stdout);
+ usage();
break;
case 'f':
action = FREEZE;
@@ -109,7 +110,7 @@ int main(int argc, char **argv)
if (optind != argc) {
warnx(_("unexpected number of arguments"));
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
fd = open(path, O_RDONLY);
diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
index c400a61b5..698f30a93 100644
--- a/sys-utils/fstrim.c
+++ b/sys-utils/fstrim.c
@@ -244,8 +244,9 @@ static int fstrim_all(struct fstrim_range *rangetpl, int verbose)
return EXIT_SUCCESS;
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] <mount point>\n"), program_invocation_short_name);
@@ -264,7 +265,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("fstrim(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -298,7 +299,7 @@ int main(int argc, char **argv)
all = 1;
break;
case 'h':
- usage(stdout);
+ usage();
break;
case 'V':
printf(UTIL_LINUX_VERSION);
@@ -332,7 +333,7 @@ int main(int argc, char **argv)
if (optind != argc) {
warnx(_("unexpected number of arguments"));
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
if (all)
diff --git a/sys-utils/ipcmk.c b/sys-utils/ipcmk.c
index f18baf00d..c6d322cbf 100644
--- a/sys-utils/ipcmk.c
+++ b/sys-utils/ipcmk.c
@@ -60,8 +60,9 @@ static int create_sem(int nsems, int permission)
return semget(key, nsems, permission | IPC_CREAT);
}
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
@@ -79,7 +80,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("ipcmk(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -121,7 +122,7 @@ int main(int argc, char **argv)
permission = strtoul(optarg, NULL, 8);
break;
case 'h':
- usage(stdout);
+ usage();
break;
case 'V':
printf(UTIL_LINUX_VERSION);
@@ -131,9 +132,10 @@ int main(int argc, char **argv)
}
}
- if(!ask_shm && !ask_msg && !ask_sem)
- usage(stderr);
-
+ if(!ask_shm && !ask_msg && !ask_sem) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
if (ask_shm) {
int shmid;
if (-1 == (shmid = create_shm(size, permission)))
diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c
index 5b71f7d81..a60919d9b 100644
--- a/sys-utils/ipcrm.c
+++ b/sys-utils/ipcrm.c
@@ -44,8 +44,9 @@ typedef enum type_id {
static int verbose = 0;
/* print the usage */
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %1$s [options]\n"
" %1$s shm|msg|sem <id>...\n"), program_invocation_short_name);
@@ -68,7 +69,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("ipcrm(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static int remove_id(int type, int iskey, int id)
@@ -158,7 +159,7 @@ static int deprecated_main(int argc, char **argv)
if (argc < 3) {
warnx(_("not enough arguments"));
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
if (remove_arg_list(type, argc - 2, &argv[2]))
@@ -401,7 +402,7 @@ int main(int argc, char **argv)
verbose = 1;
break;
case 'h':
- usage(stdout);
+ usage();
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 9ff547edb..593d3b536 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -375,8 +375,9 @@ done:
return rc;
}
-static void usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
size_t i;
fputs(USAGE_HEADER, out);
@@ -427,7 +428,7 @@ static void usage(FILE *out)
fprintf(out, USAGE_MAN_TAIL("losetup(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static void warn_size(const char *filename, uint64_t size)
@@ -653,7 +654,7 @@ int main(int argc, char **argv)
act = A_FIND_FREE;
break;
case 'h':
- usage(stdout);
+ usage();
break;
case 'J':
json = 1;
@@ -860,7 +861,8 @@ int main(int argc, char **argv)
loopcxt_get_device(&lc));
break;
default:
- usage(stderr);
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
break;
}
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 2871f7131..2504da2e0 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -2044,8 +2044,9 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
scols_unref_table(tb);
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
size_t i;
fputs(USAGE_HEADER, out);
@@ -2074,7 +2075,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fprintf(out, USAGE_MAN_TAIL("lscpu(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
@@ -2130,7 +2131,7 @@ int main(int argc, char *argv[])
cpu_modifier_specified = 1;
break;
case 'h':
- usage(stdout);
+ usage();
case 'J':
mod->json = 1;
break;
@@ -2173,8 +2174,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (argc != optind)
- usage(stderr);
+ if (argc != optind) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
/* set default cpu display mode if none was specified */
if (!mod->online && !mod->offline) {
diff --git a/sys-utils/lsmem.c b/sys-utils/lsmem.c
index 891be36f7..4efd29632 100644
--- a/sys-utils/lsmem.c
+++ b/sys-utils/lsmem.c
@@ -363,8 +363,9 @@ static void read_basic_info(struct lsmem *lsmem)
lsmem->have_nodes = 1;
}
-static void __attribute__((__noreturn__)) lsmem_usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
unsigned int i;
fputs(USAGE_HEADER, out);
@@ -449,7 +450,7 @@ int main(int argc, char **argv)
lsmem->bytes = 1;
break;
case 'h':
- lsmem_usage(stdout);
+ usage();
break;
case 'J':
lsmem->json = 1;
@@ -493,8 +494,10 @@ int main(int argc, char **argv)
}
}
- if (argc != optind)
- lsmem_usage(stderr);
+ if (argc != optind) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
if (lsmem->want_table + lsmem->want_summary == 0)
errx(EXIT_FAILURE, _("options --{raw,json,pairs} and --summary=only are mutually exclusive"));
diff --git a/sys-utils/mount.c b/sys-utils/mount.c
index ffe294e3f..b46634c7c 100644
--- a/sys-utils/mount.c
+++ b/sys-utils/mount.c
@@ -384,8 +384,9 @@ static int has_remount_flag(struct libmnt_context *cxt)
return mflags & MS_REMOUNT;
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(
" %1$s [-lhV]\n"
@@ -460,7 +461,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fprintf(out, USAGE_MAN_TAIL("mount(8)"));
- exit(out == stderr ? MNT_EX_USAGE : MNT_EX_SUCCESS);
+ exit(MNT_EX_SUCCESS);
}
int main(int argc, char **argv)
@@ -571,7 +572,7 @@ int main(int argc, char **argv)
mnt_context_enable_fork(cxt, TRUE);
break;
case 'h':
- usage(stdout);
+ usage();
break;
case 'i':
mnt_context_disable_helpers(cxt, TRUE);
@@ -694,8 +695,10 @@ int main(int argc, char **argv)
!mnt_context_get_target(cxt) &&
!argc &&
!all) {
- if (oper || mnt_context_get_options(cxt))
- usage(stderr);
+ if (oper || mnt_context_get_options(cxt)) {
+ warnx(_("bad usage"));
+ errtryhelp(MNT_EX_USAGE);
+ }
print_all(cxt, types, show_labels);
goto done;
}
@@ -705,8 +708,10 @@ int main(int argc, char **argv)
if (mnt_context_is_restricted(cxt) && types)
exit_non_root("types");
- if (oper && (types || all || mnt_context_get_source(cxt)))
- usage(stderr);
+ if (oper && (types || all || mnt_context_get_source(cxt))) {
+ warnx(_("bad usage"));
+ errtryhelp(MNT_EX_USAGE);
+ }
if (types && (all || strchr(types, ',') ||
strncmp(types, "no", 2) == 0))
@@ -772,8 +777,10 @@ int main(int argc, char **argv)
mnt_context_set_source(cxt, argv[0]);
mnt_context_set_target(cxt, argv[1]);
- } else
- usage(stderr);
+ } else {
+ warnx(_("bad usage"));
+ errtryhelp(MNT_EX_USAGE);
+ }
if (mnt_context_is_restricted(cxt))
sanitize_paths(cxt);
diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c
index ab0951f9b..d07077252 100644
--- a/sys-utils/mountpoint.c
+++ b/sys-utils/mountpoint.c
@@ -111,8 +111,9 @@ static int print_devno(const struct mountpoint_control *ctl)
return 0;
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %1$s [-qd] /path/to/directory\n"
@@ -130,7 +131,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("mountpoint(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -167,7 +168,7 @@ int main(int argc, char **argv)
ctl.dev_devno = 1;
break;
case 'h':
- usage(stdout);
+ usage();
break;
case 'V':
printf(UTIL_LINUX_VERSION);
@@ -177,8 +178,10 @@ int main(int argc, char **argv)
}
}
- if (optind + 1 != argc)
- usage(stderr);
+ if (optind + 1 != argc) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
ctl.path = argv[optind];
diff --git a/sys-utils/pivot_root.c b/sys-utils/pivot_root.c
index acc105621..ee6fd3c19 100644
--- a/sys-utils/pivot_root.c
+++ b/sys-utils/pivot_root.c
@@ -27,20 +27,21 @@
#define pivot_root(new_root,put_old) syscall(SYS_pivot_root,new_root,put_old)
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
- fprintf(out, USAGE_HEADER);
+ FILE *out = stdout;
+ fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] new_root put_old\n"),
program_invocation_short_name);
fputs(USAGE_SEPARATOR, out);
fputs(_("Change the root filesystem.\n"), out);
- fprintf(out, USAGE_OPTIONS);
- fprintf(out, USAGE_HELP);
- fprintf(out, USAGE_VERSION);
+ fputs(USAGE_OPTIONS, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("pivot_root(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -63,14 +64,15 @@ int main(int argc, char **argv)
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case 'h':
- usage(stdout);
+ usage();
default:
errtryhelp(EXIT_FAILURE);
}
- if (argc != 3)
- usage(stderr);
-
+ if (argc != 3) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
if (pivot_root(argv[1], argv[2]) < 0)
err(EXIT_FAILURE, _("failed to change root from `%s' to `%s'"),
argv[1], argv[2]);
diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c
index ecc32ef41..891d8a6b7 100644
--- a/sys-utils/setsid.c
+++ b/sys-utils/setsid.c
@@ -25,8 +25,9 @@
#include "nls.h"
#include "closestream.h"
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(
" %s [options] <program> [arguments ...]\n"),
@@ -43,7 +44,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("setsid(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -78,13 +79,15 @@ int main(int argc, char **argv)
status = 1;
break;
case 'h':
- usage(stdout);
+ usage();
default:
errtryhelp(EXIT_FAILURE);
}
- if (argc - optind < 1)
- usage(stderr);
+ if (argc - optind < 1) {
+ warnx(_("no command specified"));
+ errtryhelp(EXIT_FAILURE);
+ }
if (getpgrp() == getpid()) {
pid = fork();
diff --git a/sys-utils/swapoff.c b/sys-utils/swapoff.c
index aab6dfb8d..da2e268d7 100644
--- a/sys-utils/swapoff.c
+++ b/sys-utils/swapoff.c
@@ -116,8 +116,9 @@ static int swapoff_by(const char *name, const char *value, int quiet)
return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(value);
}
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] [<spec>]\n"), program_invocation_short_name);
@@ -141,7 +142,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
" <file> name of file to be used\n"), out);
fprintf(out, USAGE_MAN_TAIL("swapoff(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static int swapoff_all(void)
@@ -207,7 +208,7 @@ int main(int argc, char *argv[])
++all;
break;
case 'h': /* help */
- usage(stdout);
+ usage();
break;
case 'v': /* be chatty */
++verbose;
@@ -227,8 +228,10 @@ int main(int argc, char *argv[])
}
argv += optind;
- if (!all && !numof_labels() && !numof_uuids() && *argv == NULL)
- usage(stderr);
+ if (!all && !numof_labels() && !numof_uuids() && *argv == NULL) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
mnt_init_debug(0);
mntcache = mnt_new_cache();
diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c
index a46633b16..5242b96f4 100644
--- a/sys-utils/swapon.c
+++ b/sys-utils/swapon.c
@@ -782,9 +782,11 @@ static int swapon_all(struct swapon_ctl *ctl)
}
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
size_t i;
+
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] [<spec>]\n"), program_invocation_short_name);
@@ -829,7 +831,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fprintf(out, " %-5s %s\n", infos[i].name, _(infos[i].help));
fprintf(out, USAGE_MAN_TAIL("swapon(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
@@ -895,7 +897,7 @@ int main(int argc, char *argv[])
ctl.all = 1;
break;
case 'h': /* help */
- usage(stdout);
+ usage();
break;
case 'o':
options = optarg;
@@ -980,8 +982,10 @@ int main(int argc, char *argv[])
return status;
}
- if (ctl.props.no_fail && !ctl.all)
- usage(stderr);
+ if (ctl.props.no_fail && !ctl.all) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
if (ctl.all)
status |= swapon_all(&ctl);
diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c
index 7bd07783e..dff334253 100644
--- a/sys-utils/switch_root.c
+++ b/sys-utils/switch_root.c
@@ -198,8 +198,9 @@ static int switchroot(const char *newroot)
return 0;
}
-static void __attribute__((__noreturn__)) usage(FILE *output)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *output = stdout;
fputs(USAGE_HEADER, output);
fprintf(output, _(" %s [options] <newrootdir> <init> <args to init>\n"),
program_invocation_short_name);
@@ -212,7 +213,7 @@ static void __attribute__((__noreturn__)) usage(FILE *output)
fputs(USAGE_VERSION, output);
fprintf(output, USAGE_MAN_TAIL("switch_root(8)"));
- exit(output == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
@@ -233,19 +234,23 @@ int main(int argc, char *argv[])
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case 'h':
- usage(stdout);
+ usage();
default:
errtryhelp(EXIT_FAILURE);
}
- if (argc < 3)
- usage(stderr);
+ if (argc < 3) {
+ warnx(_("not enough arguments"));
+ errtryhelp(EXIT_FAILURE);
+ }
newroot = argv[1];
init = argv[2];
initargs = &argv[2];
- if (!*newroot || !*init)
- usage(stderr);
+ if (!*newroot || !*init) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
if (switchroot(newroot))
errx(EXIT_FAILURE, _("failed. Sorry."));
diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c
index 2749dd1c8..99da3f3f6 100644
--- a/sys-utils/tunelp.c
+++ b/sys-utils/tunelp.c
@@ -87,8 +87,9 @@ struct command {
struct command *next;
};
-static void __attribute__((__noreturn__)) print_usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] <device>\n"), program_invocation_short_name);
@@ -115,7 +116,7 @@ static void __attribute__((__noreturn__)) print_usage(FILE *out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("tunelp(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
@@ -148,8 +149,10 @@ int main(int argc, char **argv)
strutils_set_exitcode(EXIT_LP_BADVAL);
- if (argc < 2)
- print_usage(stderr);
+ if (argc < 2) {
+ warnx(_("not enough arguments"));
+ errtryhelp(EXIT_FAILURE);
+ }
cmdst = cmds = xmalloc(sizeof(struct command));
cmds->next = NULL;
@@ -158,7 +161,7 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, "t:c:w:a:i:ho:C:sq:rT:vV", longopts, NULL)) != -1) {
switch (c) {
case 'h':
- print_usage(stdout);
+ usage();
break;
case 'i':
cmds->op = LPSETIRQ;
@@ -246,8 +249,10 @@ int main(int argc, char **argv)
}
}
- if (optind != argc - 1)
- print_usage(stderr);
+ if (optind != argc - 1) {
+ warnx(_("no device specified"));
+ errtryhelp(EXIT_FAILURE);
+ }
filename = xstrdup(argv[optind]);
fd = open(filename, O_WRONLY | O_NONBLOCK, 0);
@@ -263,7 +268,7 @@ int main(int argc, char **argv)
if (!S_ISCHR(statbuf.st_mode)) {
warnx(_("%s not an lp device"), filename);
- print_usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
/* Allow for binaries compiled under a new kernel to work on
* the old ones The irq argument to ioctl isn't touched by
diff --git a/sys-utils/umount.c b/sys-utils/umount.c
index 57140a660..17d94be10 100644
--- a/sys-utils/umount.c
+++ b/sys-utils/umount.c
@@ -71,8 +71,9 @@ static void __attribute__((__noreturn__)) print_version(void)
fputs(")\n", stdout);
exit(MNT_EX_SUCCESS);
}
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(
" %1$s [-hV]\n"
@@ -105,7 +106,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("umount(8)"));
- exit(out == stderr ? MNT_EX_USAGE : MNT_EX_SUCCESS);
+ exit(MNT_EX_SUCCESS);
}
static void __attribute__((__noreturn__)) exit_non_root(const char *option)
@@ -479,7 +480,7 @@ int main(int argc, char **argv)
mnt_context_enable_force(cxt, TRUE);
break;
case 'h':
- usage(stdout);
+ usage();
break;
case 'i':
mnt_context_disable_helpers(cxt, TRUE);
@@ -525,7 +526,8 @@ int main(int argc, char **argv)
rc = umount_all(cxt);
} else if (argc < 1) {
- usage(stderr);
+ warnx(_("bad usage"));
+ errtryhelp(MNT_EX_USAGE);
} else if (alltargets) {
while (argc--)