diff options
author | Karel Zak | 2019-04-16 15:14:13 +0200 |
---|---|---|
committer | Karel Zak | 2019-04-16 15:14:13 +0200 |
commit | 2c308875a7fa1aaa44892c368f6b37bcfcb8879a (patch) | |
tree | 157ea7afca59059676dbcc25133dd196d1e45fb8 /sys-utils | |
parent | include/c: add print_version() macro (diff) | |
download | kernel-qcow2-util-linux-2c308875a7fa1aaa44892c368f6b37bcfcb8879a.tar.gz kernel-qcow2-util-linux-2c308875a7fa1aaa44892c368f6b37bcfcb8879a.tar.xz kernel-qcow2-util-linux-2c308875a7fa1aaa44892c368f6b37bcfcb8879a.zip |
misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
42 files changed, 186 insertions, 209 deletions
diff --git a/sys-utils/blkdiscard.c b/sys-utils/blkdiscard.c index c19b67bf4..f9ba5e468 100644 --- a/sys-utils/blkdiscard.c +++ b/sys-utils/blkdiscard.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); range[0] = 0; range[1] = ULLONG_MAX; @@ -135,12 +135,6 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, "hVsvo:l:p:z", longopts, NULL)) != -1) { switch(c) { - case 'h': - usage(); - break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'l': range[1] = strtosize_or_err(optarg, _("failed to parse length")); @@ -162,6 +156,11 @@ int main(int argc, char **argv) case 'z': act = ACT_ZEROOUT; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/blkzone.c b/sys-utils/blkzone.c index 1dcbdf500..5fd5da7a3 100644 --- a/sys-utils/blkzone.c +++ b/sys-utils/blkzone.c @@ -357,7 +357,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc >= 2 && *argv[1] != '-') { ctl.command = name_to_command(argv[1]); @@ -372,9 +372,6 @@ int main(int argc, char **argv) err_exclusive_options(c, longopts, excl, excl_st); switch (c) { - case 'h': - usage(); - break; case 'c': ctl.count = strtou32_or_err(optarg, _("failed to parse number of zones")); @@ -390,9 +387,11 @@ int main(int argc, char **argv) case 'v': ctl.verbose = 1; break; + + case 'h': + usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c index 4060a4ca4..c4e5bc7e2 100644 --- a/sys-utils/chcpu.c +++ b/sys-utils/chcpu.c @@ -288,7 +288,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); ul_path_init_debug(); sys = ul_new_path(_PATH_SYS_CPU); @@ -329,8 +329,6 @@ int main(int argc, char *argv[]) cmd = CMD_CPU_DECONFIGURE; cpu_parse(argv[optind - 1], cpu_set, setsize); break; - case 'h': - usage(); case 'p': if (strcmp("horizontal", argv[optind - 1]) == 0) cmd = CMD_CPU_DISPATCH_HORIZONTAL; @@ -343,9 +341,11 @@ int main(int argc, char *argv[]) case 'r': cmd = CMD_CPU_RESCAN; break; + + case 'h': + usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/chmem.c b/sys-utils/chmem.c index 861f6cfd2..b3645be19 100644 --- a/sys-utils/chmem.c +++ b/sys-utils/chmem.c @@ -379,7 +379,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); ul_path_init_debug(); desc->sysmem = ul_new_path(_PATH_SYS_MEMORY); @@ -402,18 +402,17 @@ int main(int argc, char **argv) case 'b': desc->use_blocks = 1; break; - case 'h': - usage(); - break; case 'v': desc->verbose = 1; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'z': zone = xstrdup(optarg); break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/choom.c b/sys-utils/choom.c index eff95b6bf..1096ab186 100644 --- a/sys-utils/choom.c +++ b/sys-utils/choom.c @@ -94,7 +94,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "hn:p:V", longopts, NULL)) != -1) { switch (c) { @@ -105,9 +105,9 @@ int main(int argc, char **argv) adj = strtos32_or_err(optarg, _("invalid adjust argument")); has_adj = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/ctrlaltdel.c b/sys-utils/ctrlaltdel.c index ea662c486..9ead94621 100644 --- a/sys-utils/ctrlaltdel.c +++ b/sys-utils/ctrlaltdel.c @@ -93,13 +93,12 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch (ch) { case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index ba4e22528..f96e5bdf7 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -1354,7 +1354,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "CcDdEeF:f:HhkL::l:n:iPprSs:TtuVwx", longopts, NULL)) != -1) { @@ -1395,9 +1395,6 @@ int main(int argc, char *argv[]) colormode = UL_COLORMODE_AUTO; ctl.pager = 1; break; - case 'h': - usage(); - break; case 'k': ctl.fltr_fac = 1; setbit(ctl.facilities, FAC_BASE(LOG_KERN)); @@ -1447,9 +1444,6 @@ int main(int argc, char *argv[]) for (n = 1; (size_t) n < ARRAY_SIZE(facility_names); n++) setbit(ctl.facilities, n); break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'w': ctl.follow = 1; break; @@ -1459,6 +1453,11 @@ int main(int argc, char *argv[]) case OPT_TIME_FORMAT: ctl.time_fmt = which_time_format(optarg); break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/eject.c b/sys-utils/eject.c index 81cd2bcff..d2e76d2ff 100644 --- a/sys-utils/eject.c +++ b/sys-utils/eject.c @@ -222,9 +222,6 @@ static void parse_args(struct eject_control *ctl, int argc, char **argv) case 'F': ctl->F_option = 1; break; - case 'h': - usage(); - break; case 'i': ctl->i_option = 1; ctl->i_arg = parse_switch(optarg, _("argument error"), @@ -263,10 +260,11 @@ static void parse_args(struct eject_control *ctl, int argc, char **argv) case 'v': ctl->v_option = 1; break; + + case 'h': + usage(); case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - break; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); break; @@ -849,7 +847,7 @@ int main(int argc, char **argv) setlocale(LC_ALL,""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); /* parse the command line arguments */ parse_args(&ctl, argc, argv); diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index ba3867cae..04a3eaff5 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -312,7 +312,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "hvVncpdizxl:o:", longopts, NULL)) != -1) { @@ -320,9 +320,6 @@ int main(int argc, char **argv) err_exclusive_options(c, longopts, excl, excl_st); switch(c) { - case 'h': - usage(); - break; case 'c': mode |= FALLOC_FL_COLLAPSE_RANGE; break; @@ -357,9 +354,11 @@ int main(int argc, char **argv) case 'v': verbose++; break; + + case 'h': + usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/flock.c b/sys-utils/flock.c index 57153c8d9..8dddebefd 100644 --- a/sys-utils/flock.c +++ b/sys-utils/flock.c @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(EX_USAGE); @@ -216,9 +216,9 @@ int main(int argc, char *argv[]) case OPT_VERBOSE: verbose = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - exit(EX_OK); + print_version(EX_OK); case 'h': usage(); default: diff --git a/sys-utils/fsfreeze.c b/sys-utils/fsfreeze.c index 401ab5c98..4da1a6fa3 100644 --- a/sys-utils/fsfreeze.c +++ b/sys-utils/fsfreeze.c @@ -84,18 +84,17 @@ int main(int argc, char **argv) err_exclusive_options(c, longopts, excl, excl_st); switch(c) { - case 'h': - usage(); - break; case 'f': action = FREEZE; break; case 'u': action = UNFREEZE; break; + + case 'h': + usage(); case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c index 830556458..87a9031b7 100644 --- a/sys-utils/fstrim.c +++ b/sys-utils/fstrim.c @@ -381,7 +381,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "Aahl:m:no:Vv", longopts, NULL)) != -1) { switch(c) { @@ -394,12 +394,6 @@ int main(int argc, char **argv) case 'n': ctl.dryrun = 1; break; - case 'h': - usage(); - break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'l': ctl.range.len = strtosize_or_err(optarg, _("failed to parse length")); @@ -415,9 +409,13 @@ int main(int argc, char **argv) case 'v': ctl.verbose = 1; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); - break; } } diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index 5f4c014fc..9512f696e 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -1259,7 +1259,7 @@ int main(int argc, char **argv) #endif bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "hvVDd:alrsuwf:", longopts, NULL)) != -1) { @@ -1359,9 +1359,9 @@ int main(int argc, char **argv) ctl.rtc_dev_name = optarg; /* --rtc */ break; #endif + case 'V': /* --version */ - out_version(); - return 0; + print_version(EXIT_SUCCESS); case 'h': /* --help */ usage(); default: diff --git a/sys-utils/ipcmk.c b/sys-utils/ipcmk.c index df836525a..8aadffbbb 100644 --- a/sys-utils/ipcmk.c +++ b/sys-utils/ipcmk.c @@ -102,7 +102,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while((opt = getopt_long(argc, argv, "hM:QS:p:Vh", longopts, NULL)) != -1) { switch(opt) { @@ -120,12 +120,11 @@ int main(int argc, char **argv) case 'p': permission = strtoul(optarg, NULL, 8); break; + case 'h': usage(); - break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c index a9f2d1b9a..5a27b7d20 100644 --- a/sys-utils/ipcrm.c +++ b/sys-utils/ipcrm.c @@ -328,7 +328,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); /* check to see if the command is being invoked in the old way if so * then remove argument list */ @@ -400,11 +400,11 @@ int main(int argc, char **argv) case 'v': verbose = 1; break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c index 73cf28ab1..2d18a13cc 100644 --- a/sys-utils/ipcs.c +++ b/sys-utils/ipcs.c @@ -108,7 +108,7 @@ int main (int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) { switch (opt) { @@ -149,11 +149,11 @@ int main (int argc, char **argv) case 'b': unit = IPC_UNIT_BYTES; break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/ldattach.c b/sys-utils/ldattach.c index fb50711eb..3019e5a9f 100644 --- a/sys-utils/ldattach.c +++ b/sys-utils/ldattach.c @@ -354,9 +354,9 @@ int main(int argc, char **argv) case 'i': parse_iflag(optarg, &set_iflag, &clr_iflag); break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 3dbbcdd3e..d862fd8e7 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -683,9 +683,6 @@ int main(int argc, char **argv) case 'f': act = A_FIND_FREE; break; - case 'h': - usage(); - break; case 'J': json = 1; break; @@ -730,13 +727,15 @@ int main(int argc, char **argv) break; case 'v': break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case OPT_SIZELIMIT: /* --sizelimit */ sizelimit = strtosize_or_err(optarg, _("failed to parse size")); flags |= LOOPDEV_FL_SIZELIMIT; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 774a27b3a..9a5a1aa5b 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -2280,8 +2280,6 @@ int main(int argc, char *argv[]) } mod->mode = OUTPUT_CACHES; break; - case 'h': - usage(); case 'J': mod->json = 1; break; @@ -2308,12 +2306,14 @@ int main(int argc, char *argv[]) case 'y': mod->physical = 1; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case OPT_OUTPUT_ALL: all = 1; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c index e8ada571e..5ba9cd7bf 100644 --- a/sys-utils/lsipc.c +++ b/sys-utils/lsipc.c @@ -1232,11 +1232,11 @@ int main(int argc, char *argv[]) case 'c': show_creat = 1; break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/lsmem.c b/sys-utils/lsmem.c index 86383360a..a1272ae60 100644 --- a/sys-utils/lsmem.c +++ b/sys-utils/lsmem.c @@ -518,7 +518,7 @@ static void __attribute__((__noreturn__)) usage(void) printf(USAGE_MAN_TAIL("lsmem(1)")); - exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); + exit(EXIT_SUCCESS); } int main(int argc, char **argv) @@ -563,7 +563,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "abhJno:PrS:s:V", longopts, NULL)) != -1) { @@ -576,9 +576,6 @@ int main(int argc, char **argv) case 'b': lsmem->bytes = 1; break; - case 'h': - usage(); - break; case 'J': lsmem->json = 1; lsmem->want_summary = 0; @@ -607,9 +604,6 @@ int main(int argc, char **argv) case 'S': splitarg = optarg; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return 0; case LSMEM_OPT_SUMARRY: if (optarg) { if (strcmp(optarg, "never") == 0) @@ -623,6 +617,11 @@ int main(int argc, char **argv) } else lsmem->want_table = 0; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c index 38ea2e009..c298d6a3c 100644 --- a/sys-utils/lsns.c +++ b/sys-utils/lsns.c @@ -960,7 +960,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); lsns_init_debug(); memset(&ls, 0, sizeof(ls)); @@ -988,14 +988,9 @@ int main(int argc, char *argv[]) for (ncolumns = 0; ncolumns < ARRAY_SIZE(infos); ncolumns++) columns[ncolumns] = ncolumns; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'p': ls.fltr_pid = strtos32_or_err(optarg, _("invalid PID argument")); break; - case 'h': - usage(); case 'n': ls.no_headings = 1; break; @@ -1019,6 +1014,11 @@ int main(int argc, char *argv[]) case 'W': ls.no_wrap = 1; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/mount.c b/sys-utils/mount.c index b1b43251e..b391347fc 100644 --- a/sys-utils/mount.c +++ b/sys-utils/mount.c @@ -655,7 +655,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(MNT_EX_USAGE); @@ -691,9 +691,6 @@ int main(int argc, char **argv) case 'F': mnt_context_enable_fork(cxt, TRUE); break; - case 'h': - usage(); - break; case 'i': mnt_context_disable_helpers(cxt, TRUE); break; @@ -707,9 +704,6 @@ int main(int argc, char **argv) case 'v': mnt_context_enable_verbose(cxt, TRUE); break; - case 'V': - mount_print_version(); - break; case 'w': append_option(cxt, "rw"); mnt_context_enable_rwonly_mount(cxt, TRUE); @@ -829,6 +823,13 @@ int main(int argc, char **argv) case MOUNT_OPT_OPTSRC_FORCE: optmode |= MNT_OMODE_FORCE; break; + + case 'h': + mnt_free_context(cxt); + usage(); + case 'V': + mnt_free_context(cxt); + mount_print_version(); default: errtryhelp(MNT_EX_USAGE); } diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c index 00a74daf0..985130cba 100644 --- a/sys-utils/mountpoint.c +++ b/sys-utils/mountpoint.c @@ -149,7 +149,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); mnt_init_debug(0); @@ -165,12 +165,11 @@ int main(int argc, char **argv) case 'x': ctl.dev_devno = 1; break; + case 'h': usage(); - break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c index fbfcf9831..f294b1257 100644 --- a/sys-utils/nsenter.c +++ b/sys-utils/nsenter.c @@ -245,17 +245,12 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "+ahVt:m::u::i::n::p::C::U::S:G:r::w::FZ", longopts, NULL)) != -1) { switch (c) { - case 'h': - usage(); - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'a': do_all = true; break; @@ -336,6 +331,10 @@ int main(int argc, char *argv[]) selinux = 1; break; #endif + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/pivot_root.c b/sys-utils/pivot_root.c index ea76d94bf..aef1b12bb 100644 --- a/sys-utils/pivot_root.c +++ b/sys-utils/pivot_root.c @@ -55,13 +55,12 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch (ch) { case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c index 6f806362d..607849066 100644 --- a/sys-utils/prlimit.c +++ b/sys-utils/prlimit.c @@ -516,7 +516,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); INIT_LIST_HEAD(&lims); @@ -584,8 +584,6 @@ int main(int argc, char **argv) errx(EXIT_FAILURE, _("option --pid may be specified only once")); pid = strtos32_or_err(optarg, _("invalid PID argument")); break; - case 'h': - usage(); case 'o': ncolumns = string_to_idarray(optarg, columns, ARRAY_SIZE(columns), @@ -593,10 +591,6 @@ int main(int argc, char **argv) if (ncolumns < 0) return EXIT_FAILURE; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; - case NOHEADINGS_OPTION: no_headings = 1; break; @@ -606,6 +600,11 @@ int main(int argc, char **argv) case RAW_OPTION: raw = 1; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c index ca0037529..1d484252a 100644 --- a/sys-utils/readprofile.c +++ b/sys-utils/readprofile.c @@ -169,7 +169,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); proFile = defaultpro; mapFile = defaultmap; @@ -206,9 +206,9 @@ int main(int argc, char **argv) case 'v': optVerbose++; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/renice.c b/sys-utils/renice.c index 3ae71f9c1..5efecdfd0 100644 --- a/sys-utils/renice.c +++ b/sys-utils/renice.c @@ -119,7 +119,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); argc--; argv++; @@ -131,10 +131,8 @@ int main(int argc, char **argv) if (strcmp(*argv, "-v") == 0 || strcmp(*argv, "-V") == 0 || - strcmp(*argv, "--version") == 0) { - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; - } + strcmp(*argv, "--version") == 0) + print_version(EXIT_SUCCESS); } if (*argv && (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--priority") == 0)) { diff --git a/sys-utils/rfkill.c b/sys-utils/rfkill.c index a93e8ba83..b00bf753e 100644 --- a/sys-utils/rfkill.c +++ b/sys-utils/rfkill.c @@ -637,7 +637,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "Jno:rVh", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -657,9 +657,9 @@ int main(int argc, char **argv) case 'r': ctrl.raw = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 029f00f9b..1058e8af9 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -457,7 +457,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((t = getopt_long(argc, argv, "A:ahd:lm:ns:t:uVv", long_options, NULL)) != EOF) { @@ -511,9 +511,9 @@ int main(int argc, char **argv) case 'v': ctl.verbose = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c index fb4c4d333..f84e90b5b 100644 --- a/sys-utils/setarch.c +++ b/sys-utils/setarch.c @@ -315,7 +315,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc < 1) { warnx(_("Not enough arguments")); @@ -343,12 +343,6 @@ int main(int argc, char *argv[]) while ((c = getopt_long(argc, argv, "+hVv3BFILRSTXZ", longopts, NULL)) != -1) { switch (c) { - case 'h': - usage(archwrapper); - break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'v': verbose = 1; break; @@ -394,8 +388,13 @@ int main(int argc, char *argv[]) } else warnx(_("unrecognized option '--list'")); /* fallthrough */ + default: errtryhelp(EXIT_FAILURE); + case 'h': + usage(archwrapper); + case 'V': + print_version(EXIT_SUCCESS); } } diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c index 828ddc12f..717031d94 100644 --- a/sys-utils/setpriv.c +++ b/sys-utils/setpriv.c @@ -837,7 +837,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); memset(&opts, 0, sizeof(opts)); @@ -971,11 +971,11 @@ int main(int argc, char **argv) case RESET_ENV: opts.reset_env = 1; break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/setsid.c b/sys-utils/setsid.c index 8b4f83dd2..5725e8009 100644 --- a/sys-utils/setsid.c +++ b/sys-utils/setsid.c @@ -66,13 +66,10 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((ch = getopt_long(argc, argv, "+Vhcfw", longopts, NULL)) != -1) switch (ch) { - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'c': ctty=1; break; @@ -82,8 +79,11 @@ int main(int argc, char **argv) case 'w': status = 1; break; + case 'h': usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/swapoff.c b/sys-utils/swapoff.c index 0a3807fda..a13d4f1e5 100644 --- a/sys-utils/swapoff.c +++ b/sys-utils/swapoff.c @@ -197,7 +197,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "ahvVL:U:", long_opts, NULL)) != -1) { @@ -205,21 +205,20 @@ int main(int argc, char *argv[]) case 'a': /* all */ ++all; break; - case 'h': /* help */ - usage(); - break; case 'v': /* be chatty */ ++verbose; break; - case 'V': /* version */ - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'L': add_label(optarg); break; case 'U': add_uuid(optarg); break; + + case 'h': /* help */ + usage(); + case 'V': /* version */ + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index 357dcb3f7..7e3135c72 100644 --- a/sys-utils/swapon.c +++ b/sys-utils/swapon.c @@ -883,7 +883,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); memset(&ctl, 0, sizeof(struct swapon_ctl)); ctl.props.priority = -1; @@ -900,9 +900,6 @@ int main(int argc, char *argv[]) case 'a': /* all */ ctl.all = 1; break; - case 'h': /* help */ - usage(); - break; case 'o': options = optarg; break; @@ -966,11 +963,13 @@ int main(int argc, char *argv[]) case BYTES_OPTION: ctl.bytes = 1; break; - case 'V': /* version */ - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 0: break; + + case 'h': /* help */ + usage(); + case 'V': /* version */ + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c index a85ce24b9..a42bceca3 100644 --- a/sys-utils/switch_root.c +++ b/sys-utils/switch_root.c @@ -225,13 +225,12 @@ int main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "+Vh", longopts, NULL)) != -1) switch (c) { case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c index fe261f393..b1e7f75df 100644 --- a/sys-utils/tunelp.c +++ b/sys-utils/tunelp.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(EXIT_LP_BADVAL); @@ -159,9 +159,6 @@ int main(int argc, char **argv) show_irq = 1; while ((c = getopt_long(argc, argv, "t:c:w:a:i:ho:C:sq:rT:vV", longopts, NULL)) != -1) { switch (c) { - case 'h': - usage(); - break; case 'i': cmds->op = LPSETIRQ; cmds->val = strtol_or_err(optarg, _("argument error")); @@ -229,10 +226,12 @@ int main(int argc, char **argv) cmds = cmds->next; cmds->next = NULL; break; + + case 'h': + usage(); case 'v': case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/umount.c b/sys-utils/umount.c index 929da8d91..e3734b0ec 100644 --- a/sys-utils/umount.c +++ b/sys-utils/umount.c @@ -479,7 +479,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); mnt_init_debug(0); cxt = mnt_new_context(); @@ -517,9 +517,6 @@ int main(int argc, char **argv) case 'f': mnt_context_enable_force(cxt, TRUE); break; - case 'h': - usage(); - break; case 'i': mnt_context_disable_helpers(cxt, TRUE); break; @@ -548,9 +545,6 @@ int main(int argc, char **argv) case 'v': mnt_context_enable_verbose(cxt, TRUE); break; - case 'V': - umount_print_version(); - break; case 'N': { char path[PATH_MAX]; @@ -563,6 +557,13 @@ int main(int argc, char **argv) err(MNT_EX_SYSERR, _("failed to set target namespace to %s"), pid ? path : optarg); break; } + + case 'h': + mnt_free_context(cxt); + usage(); + case 'V': + mnt_free_context(cxt); + umount_print_version(); default: errtryhelp(MNT_EX_USAGE); } diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index e9ddb09de..21910a4ee 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -335,18 +335,13 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "+fhVmuinpCUrR:w:S:G:", longopts, NULL)) != -1) { switch (c) { case 'f': forkit = 1; break; - case 'h': - usage(); - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'm': unshare_flags |= CLONE_NEWNS; if (optarg) @@ -420,6 +415,11 @@ int main(int argc, char *argv[]) case 'w': newdir = optarg; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c index 642db85d2..4574e10da 100644 --- a/sys-utils/wdctl.c +++ b/sys-utils/wdctl.c @@ -505,7 +505,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "d:f:hFnITo:s:OrVx", long_opts, NULL)) != -1) { @@ -527,11 +527,6 @@ int main(int argc, char *argv[]) if (string_to_bitmask(optarg, (unsigned long *) &wanted, name2bit) != 0) return EXIT_FAILURE; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; - case 'h': - usage(); case 'F': noflags = 1; break; @@ -554,6 +549,11 @@ int main(int argc, char *argv[]) noident = 1; notimeouts = 1; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c index 69267c860..dedfa345e 100644 --- a/sys-utils/zramctl.c +++ b/sys-utils/zramctl.c @@ -616,7 +616,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((c = getopt_long(argc, argv, "a:bfho:nrs:t:V", longopts, NULL)) != -1) { @@ -659,9 +659,9 @@ int main(int argc, char **argv) case 'n': no_headings = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: |