]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: never use usage(stderr)
authorRuediger Meier <ruediger.meier@ga-group.nl>
Mon, 19 Jun 2017 18:52:50 +0000 (20:52 +0200)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Mon, 26 Jun 2017 12:38:24 +0000 (14:38 +0200)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
45 files changed:
disk-utils/addpart.c
disk-utils/delpart.c
disk-utils/fdformat.c
disk-utils/fdisk.c
disk-utils/fsck.minix.c
disk-utils/isosize.c
disk-utils/mkfs.bfs.c
disk-utils/mkfs.c
disk-utils/mkfs.minix.c
disk-utils/mkswap.c
disk-utils/partx.c
disk-utils/resizepart.c
disk-utils/swaplabel.c
libsmartcols/samples/fromfile.c
login-utils/chfn.c
login-utils/chsh.c
misc-utils/cal.c
misc-utils/look.c
misc-utils/rename.c
misc-utils/wipefs.c
schedutils/ionice.c
schedutils/taskset.c
sys-utils/blkdiscard.c
sys-utils/chcpu.c
sys-utils/chmem.c
sys-utils/dmesg.c
sys-utils/fsfreeze.c
sys-utils/fstrim.c
sys-utils/ipcmk.c
sys-utils/ipcrm.c
sys-utils/losetup.c
sys-utils/lscpu.c
sys-utils/lsmem.c
sys-utils/mount.c
sys-utils/mountpoint.c
sys-utils/pivot_root.c
sys-utils/setsid.c
sys-utils/swapoff.c
sys-utils/swapon.c
sys-utils/switch_root.c
sys-utils/tunelp.c
sys-utils/umount.c
term-utils/mesg.c
term-utils/setterm.c
text-utils/col.c

index f99e9bc9cd7250f35164aaad617dce2044d200e7..07f4ca9a10da0b6a1ae048ef0232fb3dee1d4dc1 100644 (file)
@@ -8,8 +8,9 @@
 #include "partx.h"
 #include "strutils.h"
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s <disk device> <partition number> <start> <length>\n"),
                program_invocation_short_name);
@@ -21,7 +22,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("addpart(8)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -44,13 +45,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 != 5)
-               usage(stderr);
+       if (argc != 5) {
+               warnx(_("not enough arguments"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        if ((fd = open(argv[1], O_RDONLY)) < 0)
                err(EXIT_FAILURE, _("cannot open %s"), argv[1]);
index 1f82b58e9d0f8af2b62534319c18c6242d87e2ad..7f347c8863ff19402a4e582e23da48f958d96c1f 100644 (file)
@@ -8,8 +8,9 @@
 #include "partx.h"
 #include "strutils.h"
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s <disk device> <partition number>\n"),
                program_invocation_short_name);
@@ -21,7 +22,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("delpart(8)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -44,13 +45,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(_("not enough arguments"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
 
        if ((fd = open(argv[1], O_RDONLY)) < 0)
index 60d61dcf88ef4c0b7992d48a17dacd6d39d57d37..4b5ed5690ca7ac40f6bed0b52eaad9173e430024 100644 (file)
@@ -138,8 +138,9 @@ static void verify_disk(int ctrl, unsigned int track_from, unsigned int track_to
        printf(_("done\n"));
 }
 
-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);
@@ -159,7 +160,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("fdformat(8)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -207,7 +208,7 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        exit(EXIT_SUCCESS);
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -215,8 +216,10 @@ int main(int argc, char **argv)
        argc -= optind;
        argv += optind;
 
-       if (argc < 1)
-               usage(stderr);
+       if (argc < 1) {
+               warnx(_("no device specified"));
+               errtryhelp(EXIT_FAILURE);
+       }
        if (stat(argv[0], &st) < 0)
                err(EXIT_FAILURE, _("stat of %s failed"), argv[0]);
        if (!S_ISBLK(st.st_mode))
index 832ae49591c9f91dfb423f4ea323afc57649ce26..afd9680766eecafa47764218a515a3a5bf13dce7 100644 (file)
@@ -749,8 +749,10 @@ void follow_wipe_mode(struct fdisk_context *cxt)
                        fdisk_get_collision(cxt));
 }
 
-static void __attribute__ ((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
+
        fputs(USAGE_HEADER, out);
 
        fprintf(out,
@@ -789,7 +791,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
        list_available_columns(out);
 
        fprintf(out, USAGE_MAN_TAIL("fdisk(8)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 
@@ -852,7 +854,7 @@ int main(int argc, char **argv)
                        size_t sz = strtou32_or_err(optarg,
                                        _("invalid sector size argument"));
                        if (sz != 512 && sz != 1024 && sz != 2048 && sz != 4096)
-                               usage(stderr);
+                               errx(EXIT_FAILURE, _("invalid sector size argument"));
                        fdisk_save_user_sector_size(cxt, sz, sz);
                        break;
                }
@@ -879,10 +881,8 @@ int main(int argc, char **argv)
                                        fdisk_dos_enable_compatible(lb, TRUE);
                                else if (strcmp(p, "nondos") == 0)
                                        fdisk_dos_enable_compatible(lb, FALSE);
-                               else {
-                                       warnx(_("unknown compatibility mode '%s'"), p);
-                                       usage(stderr);
-                               }
+                               else
+                                       errx(EXIT_FAILURE, _("unknown compatibility mode '%s'"), p);
                        }
                        /* use default if no optarg specified */
                        break;
@@ -929,7 +929,7 @@ int main(int argc, char **argv)
                        if (optarg && *optarg == '=')
                                optarg++;
                        if (fdisk_set_unit(cxt, optarg) != 0)
-                               usage(stderr);
+                               errx(EXIT_FAILURE, _("unsupported unit"));
                        break;
                case 'V': /* preferred for util-linux */
                case 'v': /* for backward compatibility only */
@@ -946,7 +946,7 @@ int main(int argc, char **argv)
                                errx(EXIT_FAILURE, _("unsupported wipe mode"));
                        break;
                case 'h':
-                       usage(stdout);
+                       usage();
                case OPT_BYTES:
                        fdisk_set_size_unit(cxt, FDISK_SIZEUNIT_BYTES);
                        break;
@@ -985,9 +985,10 @@ int main(int argc, char **argv)
 
        case ACT_SHOWSIZE:
                /* deprecated */
-               if (argc - optind <= 0)
-                       usage(stderr);
-
+               if (argc - optind <= 0) {
+                       warnx(_("bad usage"));
+                       errtryhelp(EXIT_FAILURE);
+               }
                for (i = optind; i < argc; i++) {
                        uintmax_t blks = get_dev_blocks(argv[i]);
 
@@ -999,8 +1000,10 @@ int main(int argc, char **argv)
                break;
 
        case ACT_FDISK:
-               if (argc-optind != 1)
-                       usage(stderr);
+               if (argc-optind != 1) {
+                       warnx(_("bad usage"));
+                       errtryhelp(EXIT_FAILURE);
+               }
 
                /* Here starts interactive mode, use fdisk_{warn,info,..} functions */
                color_scheme_enable("welcome", UL_COLOR_GREEN);
index bff810ec3b28f8532e93da5a7e3ea86363a69b4a..13b12926c8f9cdad9d4cbe61fa2b58528e12177b 100644 (file)
@@ -177,7 +177,8 @@ leave(int status) {
 }
 
 static void __attribute__((__noreturn__))
-usage(FILE *out) {
+usage(void) {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] <device>\n"), program_invocation_short_name);
        fputs(USAGE_SEPARATOR, out);
@@ -194,7 +195,7 @@ usage(FILE *out) {
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("fsck.minix(8)"));
-       leave(out == stderr ? FSCK_EX_USAGE : FSCK_EX_OK);
+       exit(FSCK_EX_OK);
 }
 
 static void die(const char *fmt, ...)
@@ -1329,7 +1330,7 @@ main(int argc, char **argv) {
                        printf(UTIL_LINUX_VERSION);
                        return FSCK_EX_OK;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(FSCK_EX_USAGE);
                }
@@ -1337,9 +1338,10 @@ main(int argc, char **argv) {
        argv += optind;
        if (0 < argc) {
                device_name = argv[0];
-       } else
-               usage(stderr);
-
+       } else {
+               warnx(_("no device specified"));
+               errtryhelp(FSCK_EX_USAGE);
+       }
        check_mount();          /* trying to check a mounted filesystem? */
        if (repair && !automatic && (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)))
                die(_("need terminal for interactive repairs"));
index b5ac56262ad390402db0db8c53ea233a710cffbe..ed43c9d70c58f050e27bb74d9e30eff21ea4f785 100644 (file)
@@ -126,8 +126,9 @@ static void isosize(int argc, char *filenamep, int xflag, long divisor)
        close(fd);
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out,
                _(" %s [options] <iso9660_image_file>\n"),
@@ -144,7 +145,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("isosize(8)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -179,15 +180,17 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
 
        ct = argc - optind;
 
-       if (ct <= 0)
-               usage(stderr);
+       if (ct <= 0) {
+               warnx(_("no device specified"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        for (j = optind; j < argc; j++)
                isosize(ct, argv[j], xflag, divisor);
index 0bf18509edd6032b693d9736f1c363a85e8c1a74..b19afa7cdfdf1b4d28cbd52a1f54ddb244a5f87f 100644 (file)
@@ -67,8 +67,9 @@ struct bfsde {
        char d_name[BFS_NAMELEN];
 };
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fprintf(out,
                _("Usage: %s [options] device [block-count]\n"),
                program_invocation_short_name);
@@ -88,7 +89,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
                       " -h, --help          display this help and exit\n\n"));
 
        fprintf(out, USAGE_MAN_TAIL("mkfs.bfs(8)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 static void __attribute__ ((__noreturn__)) print_version(void)
@@ -129,9 +130,10 @@ int main(int argc, char **argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       if (argc < 2)
-               usage(stderr);
-
+       if (argc < 2) {
+               warnx(_("not enough arguments"));
+               errtryhelp(EXIT_FAILURE);
+       }
        if (argc == 2 && !strcmp(argv[1], "-V"))
                print_version();
 
@@ -170,14 +172,16 @@ int main(int argc, char **argv)
                case VERSION_OPTION:
                        print_version();
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
        }
 
-       if (optind == argc)
-               usage(stderr);
+       if (optind == argc) {
+               warnx(_("no device specified"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        device = argv[optind++];
 
@@ -191,8 +195,10 @@ int main(int argc, char **argv)
        if (optind == argc - 1)
                user_specified_total_blocks =
                        strtou64_or_err(argv[optind], _("invalid block-count"));
-       else if (optind != argc)
-               usage(stderr);
+       else if (optind != argc) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        if (blkdev_get_sectors(fd, &total_blocks) == -1) {
                if (!user_specified_total_blocks)
index cf1a312d916bc8c49a71200611f7a005445851f2..25cc59d20df9746ebc27217c11a9d0041f3ca73d 100644 (file)
@@ -38,8 +38,9 @@
 #define DEFAULT_FSTYPE "ext2"
 #endif
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] [-t <type>] [fs-options] <device> [<size>]\n"),
                     program_invocation_short_name);
@@ -60,7 +61,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
 
        fprintf(out, USAGE_MAN_TAIL("mkfs(8)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 static void __attribute__ ((__noreturn__)) print_version(void)
@@ -106,7 +107,7 @@ int main(int argc, char **argv)
                        fstype = optarg;
                        break;
                case 'h':
-                       usage(stdout);
+                       usage();
                case VERSION_OPTION:
                        print_version();
                default:
@@ -114,8 +115,10 @@ int main(int argc, char **argv)
                        more = 1;
                        break;  /* start of specific arguments */
                }
-       if (optind == argc)
-               usage(stderr);
+       if (optind == argc) {
+               warnx(_("no device specified"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        /* If -t wasn't specified, use the default */
        if (fstype == NULL)
index 98a62668a77a02e8a0f552c9bbe37be2180bda7a..39e159f7a0f6c7e3332271a3cf7145bb928becf1 100644 (file)
@@ -131,8 +131,9 @@ static char *zone_map;
 #define mark_zone(x) (setbit(zone_map,(x)-get_first_zone()+1))
 #define unmark_zone(x) (clrbit(zone_map,(x)-get_first_zone()+1))
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] /dev/name [blocks]\n"), program_invocation_short_name);
        fputs(USAGE_OPTIONS, out);
@@ -147,7 +148,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("mkfs.minix(8)"));
-       exit(out == stderr ? MKFS_EX_USAGE : MKFS_EX_OK);
+       exit(MKFS_EX_OK);
 }
 
 #ifdef TEST_SCRIPT
@@ -795,7 +796,7 @@ int main(int argc, char ** argv)
                        printf(UTIL_LINUX_VERSION);
                        return MKFS_EX_OK;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(MKFS_EX_USAGE);
                }
@@ -810,7 +811,8 @@ int main(int argc, char ** argv)
                ctl.fs_blocks = strtoul_or_err(argv[0], _("failed to parse number of blocks"));
 
        if (!ctl.device_name) {
-               usage(stderr);
+               warnx(_("no device specified"));
+               errtryhelp(MKFS_EX_USAGE);
        }
        check_user_instructions(&ctl);
        if (is_mounted(ctl.device_name))
index ff076c8ab950612bb908bc520e9651b7b00e51fa..73e5258ed3784cc368f8dd333ca6b162af573879 100644 (file)
@@ -141,8 +141,9 @@ static void set_uuid_and_label(const struct mkswap_control *ctl)
        }
 }
 
-static void __attribute__ ((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fprintf(out,
                _("\nUsage:\n"
                  " %s [options] device [size]\n"),
@@ -162,7 +163,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
                " -V, --version             output version information and exit\n"
                " -h, --help                display this help and exit\n\n"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 static void page_bad(struct mkswap_control *ctl, unsigned int page)
@@ -400,7 +401,7 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        exit(EXIT_SUCCESS);
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -412,7 +413,7 @@ int main(int argc, char **argv)
                block_count = argv[optind++];
        if (optind != argc) {
                warnx(_("only one device argument is currently supported"));
-               usage(stderr);
+               errtryhelp(EXIT_FAILURE);
        }
 
 #ifdef HAVE_LIBUUID
@@ -428,7 +429,7 @@ int main(int argc, char **argv)
 
        if (!ctl.devname) {
                warnx(_("error: Nowhere to set up swap on?"));
-               usage(stderr);
+               errtryhelp(EXIT_FAILURE);
        }
        if (block_count) {
                /* this silly user specified the number of blocks explicitly */
index 93fbc9c1df8f941dfe2989b67b8ebcb8bfa50d6a..9a868cd819d8118f5ced639b5829aa61c89de37f 100644 (file)
@@ -743,8 +743,9 @@ static blkid_partlist get_partlist(blkid_probe pr,
        return ls;
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        size_t i;
 
        fputs(USAGE_HEADER, out);
@@ -781,7 +782,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 
        fprintf(out, USAGE_MAN_TAIL("partx(8)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -891,7 +892,7 @@ int main(int argc, char **argv)
                        return EXIT_SUCCESS;
                }
                case 'h':
-                       usage(stdout);
+                       usage();
                case 'V':
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
@@ -963,9 +964,10 @@ int main(int argc, char **argv)
                        device = NULL;
                        part_devno = 0;
                }
-       } else
-               usage(stderr);
-
+       } else {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
        if (device && (upper || lower))
                errx(EXIT_FAILURE, _("--nr and <partition> are mutually exclusive"));
 
index 97533e26f96bdb6a6a598c978aa18fdc69cf1a8a..a234c8079180beb46ad47907803ee118f50f4fe8 100644 (file)
@@ -13,8 +13,9 @@
 #include "strutils.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 <disk device> <partition number> <length>\n"),
                program_invocation_short_name);
@@ -26,7 +27,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("resizepart(8)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 static int get_partition_start(int fd, int partno, uint64_t *start)
@@ -86,13 +87,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 != 4)
-               usage(stderr);
+       if (argc != 4) {
+               warnx(_("not enough arguments"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        wholedisk = argv[1];
        partno = strtou32_or_err(argv[2], _("invalid partition number argument"));
index 233f027d15413e3b52db81b3538d62a11b2e8cae..c8fede25e752e1f1c0b4a8bea94b93b98c62b3ec 100644 (file)
@@ -111,8 +111,9 @@ err:
        return -1;
 }
 
-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);
@@ -127,7 +128,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("swaplabel(8)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char *argv[])
@@ -152,7 +153,7 @@ int main(int argc, char *argv[])
        while ((c = getopt_long(argc, argv, "hVL:U:", longopts, NULL)) != -1) {
                switch (c) {
                case 'h':
-                       usage(stdout);
+                       usage();
                        break;
                case 'V':
                        printf(UTIL_LINUX_VERSION);
@@ -172,9 +173,10 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (optind == argc)
-               usage(stderr);
-
+       if (optind == argc) {
+               warnx(_("no device specified"));
+               errtryhelp(EXIT_FAILURE);
+       }
        devname = argv[optind];
        pr = get_swap_prober(devname);
        if (pr) {
index 674f012063a196dc113088918e0ea3ba60dbf57a..de0a8eac4a4479eec16e663d9bcd973056edd679 100644 (file)
@@ -194,8 +194,9 @@ static void compose_tree(struct libscols_table *tb, int parent_col, int id_col)
 }
 
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fprintf(out,
                "\n %s [options] <column-data-file> ...\n\n", program_invocation_short_name);
 
@@ -212,7 +213,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(" -h, --help                     this help\n", out);
        fputs("\n", out);
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char *argv[])
@@ -298,9 +299,9 @@ int main(int argc, char *argv[])
                        scols_table_set_termwidth(tb, strtou32_or_err(optarg, "failed to parse terminal width"));
                        break;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
-                       usage(stderr);
+                       errtryhelp(EXIT_FAILURE);
                }
        }
 
index 3a951a1935b1e135a45afc4c9c97a5dd104982d0..7a57e916989ff3ca496b6070cab41d7a7562917c 100644 (file)
@@ -89,8 +89,9 @@ struct chfn_control {
 /* we do not accept gecos field sizes longer than MAX_FIELD_SIZE */
 #define MAX_FIELD_SIZE         256
 
-static void __attribute__((__noreturn__)) usage(FILE *fp)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *fp = stdout;
        fputs(USAGE_HEADER, fp);
        fprintf(fp, _(" %s [options] [<username>]\n"), program_invocation_short_name);
 
@@ -106,7 +107,7 @@ static void __attribute__((__noreturn__)) usage(FILE *fp)
        fputs(_(" -u, --help     display this help and exit\n"), fp);
        fputs(_(" -v, --version  output version information and exit\n"), fp);
        fprintf(fp, USAGE_MAN_TAIL("chfn(1)"));
-       exit(fp == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 /*
@@ -178,7 +179,7 @@ static void parse_argv(struct chfn_control *ctl, int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        exit(EXIT_SUCCESS);
                case 'u':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -189,8 +190,10 @@ static void parse_argv(struct chfn_control *ctl, int argc, char **argv)
                exit(EXIT_FAILURE);
        /* done parsing arguments.  check for a username. */
        if (optind < argc) {
-               if (optind + 1 < argc)
-                       usage(stderr);
+               if (optind + 1 < argc) {
+                       warnx(_("cannot handle multiple usernames"));
+                       errtryhelp(EXIT_FAILURE);
+               }
                ctl->username = argv[optind];
        }
        return;
index 10b0bdcda02438612e26c764b4cc60c9274a5a13..1083583b931e947c94f0a5678c7ea24bb000e947 100644 (file)
@@ -70,8 +70,9 @@ struct sinfo {
 /* global due readline completion */
 static char **global_shells;
 
-static void __attribute__((__noreturn__)) usage (FILE *fp)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *fp = stdout;
        fputs(USAGE_HEADER, fp);
        fprintf(fp, _(" %s [options] [<username>]\n"), program_invocation_short_name);
 
@@ -85,7 +86,7 @@ static void __attribute__((__noreturn__)) usage (FILE *fp)
        fputs(_(" -u, --help     display this help and exit\n"), fp);
        fputs(_(" -v, --version  output version information and exit\n"), fp);
        fprintf(fp, USAGE_MAN_TAIL("chsh(1)"));
-       exit(fp == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 /*
@@ -229,7 +230,7 @@ static void parse_argv(int argc, char **argv, struct sinfo *pinfo)
                        exit(EXIT_SUCCESS);
                case 'u': /* deprecated */
                case 'h':
-                       usage(stdout);
+                       usage();
                case 'l':
                        init_shells();
                        print_shells();
@@ -243,8 +244,9 @@ static void parse_argv(int argc, char **argv, struct sinfo *pinfo)
        }
        /* done parsing arguments.  check for a username. */
        if (optind < argc) {
-               if (optind + 1 < argc)
-                       usage(stderr);
+               if (optind + 1 < argc) {
+                       errx(EXIT_FAILURE, _("cannot handle multiple usernames"));
+               }
                pinfo->username = argv[optind];
        }
 }
index 86e159bfa14dbdf01b96be7161a7415a3bb765dc..f73cbbf30ef48ba589d56bde5466dcc04e67d0a1 100644 (file)
@@ -244,7 +244,7 @@ static int week_number(int day, int month, int32_t year, const struct cal_contro
 static int week_to_day(const struct cal_control *ctl);
 static int center_str(const char *src, char *dest, size_t dest_size, size_t width);
 static void center(const char *str, size_t len, int separate);
-static void __attribute__((__noreturn__)) usage(FILE *out);
+static void __attribute__((__noreturn__)) usage(void);
 
 int main(int argc, char **argv)
 {
@@ -394,7 +394,7 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -470,7 +470,8 @@ int main(int argc, char **argv)
                        ctl.req.month = local_time->tm_mon + 1;
                break;
        default:
-               usage(stderr);
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
        }
 
        if (0 < ctl.req.week) {
@@ -987,8 +988,9 @@ static void center(const char *str, size_t len, int separate)
        }
 }
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] [[[day] month] year]\n"), program_invocation_short_name);
        fprintf(out, _(" %s [options] <timestamp|monthname>\n"), program_invocation_short_name);
@@ -1017,5 +1019,5 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("cal(1)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
index 3f785a727fcd2b696e9ab1ce9861cd3c12847f46..a0d898db12328d29bdaa8886f21e187eb96dd455 100644 (file)
@@ -78,7 +78,7 @@ static int compare (char *, char *);
 static char *linear_search (char *, char *);
 static int look (char *, char *);
 static void print_from (char *, char *);
-static void __attribute__ ((__noreturn__)) usage(FILE * out);
+static void __attribute__((__noreturn__)) usage(void);
 
 int
 main(int argc, char *argv[])
@@ -126,7 +126,7 @@ main(int argc, char *argv[])
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -143,7 +143,8 @@ main(int argc, char *argv[])
                string = *argv;
                break;
        default:
-               usage(stderr);
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
        }
 
        if (termchar != '\0' && (p = strchr(string, termchar)) != NULL)
@@ -348,8 +349,9 @@ compare(char *s2, char *s2end) {
        return ((i > 0) ? LESS : (i < 0) ? GREATER : EQUAL);
 }
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] <string> [<file>...]\n"), program_invocation_short_name);
 
@@ -367,5 +369,5 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("look(1)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
index 8230ac3da02a11d40671dc4ed6d49bc99ac805f7..48606d75e9a8d26c3fee96168237725e0dd95c92 100644 (file)
@@ -127,8 +127,9 @@ static int do_file(char *from, char *to, char *s, int verbose, int noact, int no
        return ret;
 }
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out,
              _(" %s [options] <expression> <replacement> <file>...\n"),
@@ -146,7 +147,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_HELP, out);
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("rename(1)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -188,7 +189,7 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -198,7 +199,7 @@ int main(int argc, char **argv)
 
        if (argc < 3) {
                warnx(_("not enough arguments"));
-               usage(stderr);
+               errtryhelp(EXIT_FAILURE);
        }
 
        from = argv[0];
index 209ed7147b3520e048df9baa8bea713f304fb8d2..0bd53253dcaa0b049e281ee412798e40f54291eb 100644 (file)
@@ -451,8 +451,9 @@ do_wipe(struct wipe_desc *wp, const char *devname, int flags)
 
 
 static void __attribute__((__noreturn__))
-usage(FILE *out)
+usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out,
              _(" %s [options] <device>\n"), program_invocation_short_name);
@@ -474,7 +475,7 @@ usage(FILE *out)
 
        fprintf(out, USAGE_MAN_TAIL("wipefs(8)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 
@@ -525,7 +526,7 @@ main(int argc, char **argv)
                        flags |= WP_FL_FORCE;
                        break;
                case 'h':
-                       usage(stdout);
+                       usage();
                        break;
                case 'n':
                        flags |= WP_FL_NOACT;
@@ -552,8 +553,11 @@ main(int argc, char **argv)
                }
        }
 
-       if (optind == argc)
-               usage(stderr);
+       if (optind == argc) {
+               warnx(_("no device specified"));
+               errtryhelp(EXIT_FAILURE);
+
+       }
 
        if ((flags & WP_FL_BACKUP) && !((flags & WP_FL_ALL) || has_offset))
                warnx(_("The --backup option is meaningless in this context"));
index 1cbde8faafd7d3645fcb2541e91dd8a7d8766213..9d0648bcaaa4c0963bdb2bee1921e79ec9491fed 100644 (file)
@@ -98,8 +98,9 @@ static void ioprio_setid(int which, int ioclass, int data, int who)
                err(EXIT_FAILURE, _("ioprio_set failed"));
 }
 
-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] -p <pid>...\n"
                        " %1$s [options] -P <pgid>...\n"
@@ -125,7 +126,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
 
        fprintf(out, USAGE_MAN_TAIL("ionice(1)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -201,7 +202,7 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -258,9 +259,10 @@ int main(int argc, char **argv)
                ioprio_setid(0, ioclass, data, IOPRIO_WHO_PROCESS);
                execvp(argv[optind], &argv[optind]);
                err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]);
-       } else
-               usage(stderr);
-
+       } else {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        return EXIT_SUCCESS;
 }
index b117b1c8573d028883f96de508d679a978955248..9870040e7d7976fb828d9ed2f11ec5ab6b921e48 100644 (file)
@@ -45,8 +45,9 @@ struct taskset {
                        get_only:1;     /* print the mask, but not modify */
 };
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fprintf(out,
                _("Usage: %s [options] [mask | cpu-list] [pid|cmd [args...]]\n\n"),
                program_invocation_short_name);
@@ -78,7 +79,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 
        fprintf(out, USAGE_MAN_TAIL("taskset(1)"));
 
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 static void print_affinity(struct taskset *ts, int isnew)
@@ -176,7 +177,7 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'h':
-                       usage(stdout);
+                       usage();
                        break;
                default:
                        errtryhelp(EXIT_FAILURE);
@@ -184,8 +185,10 @@ int main(int argc, char **argv)
        }
 
        if ((!pid && argc - optind < 2)
-           || (pid && (argc - optind < 1 || argc - optind > 2)))
-               usage(stderr);
+           || (pid && (argc - optind < 1 || argc - optind > 2))) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        ncpus = get_max_number_of_cpus();
        if (ncpus <= 0)
index 7f2db58b1f13923c69463c55448bc70f8abe3d71..e6a9dce5c8a3adac0df0b7dd6f90cd94bba915ce 100644 (file)
@@ -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);
index 30afa457ccdf86b323fd4da0baa96b95851b3ba5..c0f568073b64596b904587ad0701d25b02ab6121 100644 (file)
@@ -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:
index 44733bf769fee31000676a1cf2bf0251fb578829..7f7be6ab6ceff75add6d0868b2c358dc21fc6742 100644 (file)
@@ -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]);
 
index 37639ebe5a1e3d87dfdb40b70705fe9e497435db..cd5da90f4c915a20fa8282ea99ccd2e0bcf933d3 100644 (file)
@@ -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)   ||
index b1fa4fa8cbd74a53011a768f054c1f632e8d52a4..8b0d5d10edf5abf86fc63ad7ddcc38da8e86b9cc 100644 (file)
@@ -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);
index c400a61b55a2b21cbe513a5b22661a1c86a7dd00..698f30a931ac217fdede3efd6d6f53609dd6f1bd 100644 (file)
@@ -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)
index f18baf00d356495279741c042ed0e2c838e0d4cd..c6d322cbfc9c17808c8756fa0ec22189d0d1bc5f 100644 (file)
@@ -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)))
index 5b71f7d813ef022d762c1582192c05434c8d50ef..a60919d9bf8c12b831c2300b05bcd516468283b3 100644 (file)
@@ -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;
index 9ff547edb57246f0e48ce6c03a6b6cda2a207f99..593d3b5366df2e5791bfbacaa6c2f85006aa9083 100644 (file)
@@ -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;
        }
 
index 2871f7131eae11df65b56d53285ca039b198121e..2504da2e06d0ced44e4d9e7b7afccb456b5c2c6b 100644 (file)
@@ -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) {
index 891be36f76458dcce765f374e478a4fc82f732c4..4efd296329b553fd997a09a5a8770f9bf89aeaf8 100644 (file)
@@ -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"));
index ffe294e3f1f982bf00216da4dcaa73499abdf877..b46634c7c5559f3527a7daaddc01060474b90e1e 100644 (file)
@@ -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);
index ab0951f9b915df681c3b175a42df90c5df1c89b7..d0707725268d20f35541acf256b4be6f7375f5c1 100644 (file)
@@ -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];
 
index acc105621258b9cfee89b53055d2d203c2911554..ee6fd3c19dfd077aea5b2b961f2d3ba0c03390d4 100644 (file)
 
 #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]);
index ecc32ef410fdd568fe76495118a84e6f80ae105c..891d8a6b7fc152d75bc8840a89e71540ff600243 100644 (file)
@@ -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();
index aab6dfb8d9e9bcbf23acfea840eea339ac81fc29..da2e268d7ebff621dc75eb28f18675e896a99c81 100644 (file)
@@ -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();
index a46633b160aabcc6bacbe1f60b9436d11b83c11f..5242b96f4907f9339fcb372eb1afcc9b4b91b40c 100644 (file)
@@ -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);
index 7bd07783ee3a7ec07bfeb6f1c048ca4d239c7cdd..dff33425342c147bcbd746356a861785f57bc44d 100644 (file)
@@ -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."));
index 2749dd1c8e9f5d28f8dfe606d95bef350ec60c2c..99da3f3f622adaa541936b22a9612c5cb03a09fa 100644 (file)
@@ -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
index 57140a660d0fc2e54fd021d0d849ebc9a808467e..17d94be10344ebed82c06405553f665cae776c74 100644 (file)
@@ -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--)
index 43835b480bab48562e0e43f9ea8664dc5e2e5b42..fe5218aa440e39857b380a9961558b5406632953 100644 (file)
@@ -66,8 +66,9 @@
 #define IS_NOT_ALLOWED    1  /* Receiving messages is not allowed.  */
 #define MESG_EXIT_FAILURE 2  /* An error occurred.  */
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        /* TRANSLATORS: this program uses for y and n rpmatch(3),
         * which means they can be translated.  */
@@ -83,7 +84,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
        fputs(USAGE_VERSION, out);
        fprintf(out, USAGE_MAN_TAIL("mesg(1)"));
 
-       exit(out == stderr ? MESG_EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char *argv[])
@@ -113,7 +114,7 @@ int main(int argc, char *argv[])
                        printf(UTIL_LINUX_VERSION);
                        exit(EXIT_SUCCESS);
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -159,7 +160,7 @@ int main(int argc, char *argv[])
                break;
        case RPMATCH_INVALID:
                warnx(_("invalid argument: %s"), argv[0]);
-               usage(stderr);
+               errtryhelp(EXIT_FAILURE);
         default:
                 abort();
        }
index 9f60e569342ffb8a312f42b607f4f20cd0502bb1..8ab5b45d796fb5adeb6f2bedb133c00cd1dd0d66 100644 (file)
@@ -371,8 +371,9 @@ static int parse_bfreq(char **av, char *oa, int *oi)
        return strtos32_or_err(arg, _("argument error"));
 }
 
-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);
@@ -420,7 +421,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" --version                         show version information and exit\n"), out);
        fputs(_(" --help                            display this help and exit\n"), out);
        fprintf(out, USAGE_MAN_TAIL("setterm(1)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 static int __attribute__((__pure__)) set_opt_flag(int opt)
@@ -672,7 +673,7 @@ static void parse_option(struct setterm_control *ctl, int ac, char **av)
                        printf(UTIL_LINUX_VERSION);
                        exit(EXIT_SUCCESS);
                case OPT_HELP:
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -1170,9 +1171,10 @@ int main(int argc, char **argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       if (argc < 2)
-               usage(stderr);
-
+       if (argc < 2) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
        parse_option(&ctl, argc, argv);
        init_terminal(&ctl);
        perform_sequence(&ctl);
index bac48e7e33e5cba3a35edb1094e397af5a1bf7a9..a473e55fb0085cb5b217c0ddc8802c0d8aa8ea6a 100644 (file)
@@ -124,8 +124,9 @@ static int pass_unknown_seqs;               /* whether to pass unknown control sequences */
        if (putwchar(ch) == WEOF) \
                wrerr();
 
-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);
@@ -149,7 +150,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
                program_invocation_short_name);
 
        fprintf(out, USAGE_MAN_TAIL("col(1)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       exit(EXIT_SUCCESS);
 }
 
 static void __attribute__((__noreturn__)) wrerr(void)
@@ -221,13 +222,15 @@ int main(int argc, char **argv)
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
                case 'H':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
 
-       if (optind != argc)
-               usage(stderr);
+       if (optind != argc) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        adjust = cur_col = extra_lines = warned = 0;
        cur_line = max_line = nflushd_lines = this_line = 0;