From 2c308875a7fa1aaa44892c368f6b37bcfcb8879a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 16 Apr 2019 15:14:13 +0200 Subject: [PATCH] misc: consolidate version printing and close_stdout() Signed-off-by: Karel Zak --- Documentation/boilerplate.c | 5 ++--- disk-utils/addpart.c | 3 +-- disk-utils/blockdev.c | 8 +++----- disk-utils/cfdisk.c | 5 ++--- disk-utils/delpart.c | 3 +-- disk-utils/fdformat.c | 5 ++--- disk-utils/fdisk.c | 5 ++--- disk-utils/fsck.c | 8 +++----- disk-utils/fsck.cramfs.c | 5 ++--- disk-utils/fsck.minix.c | 5 ++--- disk-utils/isosize.c | 5 ++--- disk-utils/mkfs.bfs.c | 2 +- disk-utils/mkfs.c | 2 +- disk-utils/mkfs.cramfs.c | 7 +++---- disk-utils/mkfs.minix.c | 5 ++--- disk-utils/mkswap.c | 5 ++--- disk-utils/partx.c | 5 ++--- disk-utils/raw.c | 5 ++--- disk-utils/resizepart.c | 5 ++--- disk-utils/sfdisk.c | 6 ++---- disk-utils/swaplabel.c | 5 ++--- include/c.h | 5 +++++ login-utils/chfn.c | 6 +++--- login-utils/chsh.c | 5 ++--- login-utils/islocal.c | 2 +- login-utils/last.c | 5 ++--- login-utils/login.c | 3 +-- login-utils/logindefs.c | 2 +- login-utils/lslogins.c | 5 ++--- login-utils/newgrp.c | 5 ++--- login-utils/nologin.c | 4 +--- login-utils/su-common.c | 6 ++---- login-utils/sulogin.c | 8 ++++---- login-utils/utmpdump.c | 6 ++---- login-utils/vipw.c | 5 ++--- misc-utils/blkid.c | 2 +- misc-utils/cal.c | 5 ++--- misc-utils/fincore.c | 5 ++--- misc-utils/findfs.c | 5 ++--- misc-utils/findmnt.c | 13 ++++++------- misc-utils/getopt.c | 10 +++++----- misc-utils/hardlink.c | 5 ++--- misc-utils/kill.c | 8 +++----- misc-utils/logger.c | 12 ++++++------ misc-utils/look.c | 5 ++--- misc-utils/lsblk.c | 16 ++++++++-------- misc-utils/lslocks.c | 12 ++++++------ misc-utils/mcookie.c | 6 +++--- misc-utils/namei.c | 13 ++++++------- misc-utils/rename.c | 6 +++--- misc-utils/uuidd.c | 6 +++--- misc-utils/uuidgen.c | 8 ++++---- misc-utils/uuidparse.c | 6 +++--- misc-utils/whereis.c | 12 +++++------- misc-utils/wipefs.c | 11 +++++------ schedutils/chrt.c | 6 +++--- schedutils/ionice.c | 6 +++--- schedutils/taskset.c | 7 +++---- sys-utils/blkdiscard.c | 13 ++++++------- sys-utils/blkzone.c | 11 +++++------ sys-utils/chcpu.c | 10 +++++----- sys-utils/chmem.c | 13 ++++++------- sys-utils/choom.c | 6 +++--- sys-utils/ctrlaltdel.c | 5 ++--- sys-utils/dmesg.c | 13 ++++++------- sys-utils/eject.c | 12 +++++------- sys-utils/fallocate.c | 11 +++++------ sys-utils/flock.c | 6 +++--- sys-utils/fsfreeze.c | 9 ++++----- sys-utils/fstrim.c | 14 ++++++-------- sys-utils/hwclock.c | 6 +++--- sys-utils/ipcmk.c | 7 +++---- sys-utils/ipcrm.c | 6 +++--- sys-utils/ipcs.c | 6 +++--- sys-utils/ldattach.c | 4 ++-- sys-utils/losetup.c | 11 +++++------ sys-utils/lscpu.c | 10 +++++----- sys-utils/lsipc.c | 4 ++-- sys-utils/lsmem.c | 15 +++++++-------- sys-utils/lsns.c | 12 ++++++------ sys-utils/mount.c | 15 ++++++++------- sys-utils/mountpoint.c | 7 +++---- sys-utils/nsenter.c | 11 +++++------ sys-utils/pivot_root.c | 5 ++--- sys-utils/prlimit.c | 13 ++++++------- sys-utils/readprofile.c | 6 +++--- sys-utils/renice.c | 8 +++----- sys-utils/rfkill.c | 6 +++--- sys-utils/rtcwake.c | 6 +++--- sys-utils/setarch.c | 13 ++++++------- sys-utils/setpriv.c | 6 +++--- sys-utils/setsid.c | 8 ++++---- sys-utils/swapoff.c | 13 ++++++------- sys-utils/swapon.c | 13 ++++++------- sys-utils/switch_root.c | 5 ++--- sys-utils/tunelp.c | 11 +++++------ sys-utils/umount.c | 15 ++++++++------- sys-utils/unshare.c | 12 ++++++------ sys-utils/wdctl.c | 12 ++++++------ sys-utils/zramctl.c | 6 +++--- term-utils/mesg.c | 6 +++--- term-utils/script.c | 8 +++----- term-utils/scriptreplay.c | 6 +++--- term-utils/setterm.c | 6 +++--- term-utils/wall.c | 6 +++--- term-utils/write.c | 5 ++--- text-utils/col.c | 6 +++--- text-utils/colcrt.c | 6 +++--- text-utils/colrm.c | 3 +-- text-utils/column.c | 13 ++++++------- text-utils/hexdump.c | 7 +++---- text-utils/line.c | 5 ++--- text-utils/more.c | 10 ++++------ text-utils/pg.c | 8 ++++---- text-utils/rev.c | 5 ++--- text-utils/ul.c | 6 +++--- 116 files changed, 391 insertions(+), 466 deletions(-) diff --git a/Documentation/boilerplate.c b/Documentation/boilerplate.c index a92f7f097b..535e85c387 100644 --- a/Documentation/boilerplate.c +++ b/Documentation/boilerplate.c @@ -84,7 +84,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, "nr:zelfVh", longopts, NULL)) != -1) switch (c) { @@ -98,8 +98,7 @@ int main(int argc, char **argv) case 'f': break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/disk-utils/addpart.c b/disk-utils/addpart.c index 018c99585f..33abb36cab 100644 --- a/disk-utils/addpart.c +++ b/disk-utils/addpart.c @@ -41,8 +41,7 @@ int main(int argc, char **argv) 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/disk-utils/blockdev.c b/disk-utils/blockdev.c index 5122460f09..f1067c8152 100644 --- a/disk-utils/blockdev.c +++ b/disk-utils/blockdev.c @@ -238,7 +238,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc < 2) { warnx(_("not enough arguments")); @@ -246,10 +246,8 @@ int main(int argc, char **argv) } /* -V not together with commands */ - if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) { - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; - } + if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) + print_version(EXIT_SUCCESS); if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) usage(); diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index ff1bc44c1d..376809974f 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -2667,7 +2667,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, "L::hVz", longopts, NULL)) != -1) { switch(c) { @@ -2681,8 +2681,7 @@ int main(int argc, char *argv[]) _("unsupported color mode")); break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'z': cf->zero_start = 1; break; diff --git a/disk-utils/delpart.c b/disk-utils/delpart.c index dc069970d2..7ee0c525f0 100644 --- a/disk-utils/delpart.c +++ b/disk-utils/delpart.c @@ -41,8 +41,7 @@ int main(int argc, char **argv) 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/disk-utils/fdformat.c b/disk-utils/fdformat.c index f461c82e1c..c10776f76e 100644 --- a/disk-utils/fdformat.c +++ b/disk-utils/fdformat.c @@ -186,7 +186,7 @@ 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, "f:t:r:nVh", longopts, NULL)) != -1) switch (ch) { @@ -204,8 +204,7 @@ int main(int argc, char **argv) verify = 0; break; case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 3e8ebf4a30..c27485af27 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -891,7 +891,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); fdisk_init_debug(0); scols_init_debug(0); @@ -990,8 +990,7 @@ int main(int argc, char **argv) break; case 'V': /* preferred for util-linux */ case 'v': /* for backward compatibility only */ - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'w': wipemode = wipemode_from_string(optarg); if (wipemode < 0) diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index 3afc88600d..be25f9c95f 100644 --- a/disk-utils/fsck.c +++ b/disk-utils/fsck.c @@ -1450,10 +1450,8 @@ static void parse_argv(int argc, char *argv[]) /* the only two longopts to satisfy UL standards */ if (!opts_for_fsck && !strcmp(arg, "--help")) usage(); - if (!opts_for_fsck && !strcmp(arg, "--version")) { - printf(UTIL_LINUX_VERSION); - exit(FSCK_EX_OK); - } + if (!opts_for_fsck && !strcmp(arg, "--version")) + print_version(FSCK_EX_OK); if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) { if (num_devices >= MAX_DEVICES) @@ -1621,7 +1619,7 @@ int main(int argc, char *argv[]) setlocale(LC_CTYPE, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(FSCK_EX_USAGE); mnt_init_debug(0); /* init libmount debug mask */ diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c index ee9c20ab26..e1b964b64c 100644 --- a/disk-utils/fsck.cramfs.c +++ b/disk-utils/fsck.cramfs.c @@ -660,7 +660,7 @@ int main(int argc, char **argv) setlocale(LC_CTYPE, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(FSCK_EX_USAGE); @@ -674,8 +674,7 @@ int main(int argc, char **argv) usage(); break; case 'V': - printf(UTIL_LINUX_VERSION); - return FSCK_EX_OK; + print_version(FSCK_EX_OK); case 'x': opt_extract = 1; if(optarg) diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c index b978684a83..246f254f3b 100644 --- a/disk-utils/fsck.minix.c +++ b/disk-utils/fsck.minix.c @@ -1291,7 +1291,7 @@ main(int argc, char **argv) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(FSCK_EX_USAGE); @@ -1326,8 +1326,7 @@ main(int argc, char **argv) { force = 1; break; case 'V': - printf(UTIL_LINUX_VERSION); - return FSCK_EX_OK; + print_version(FSCK_EX_OK); case 'h': usage(); default: diff --git a/disk-utils/isosize.c b/disk-utils/isosize.c index 85a549a189..3c8d40f3ca 100644 --- a/disk-utils/isosize.c +++ b/disk-utils/isosize.c @@ -177,7 +177,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, "d:xVh", longopts, NULL)) != -1) { switch (opt) { @@ -190,8 +190,7 @@ int main(int argc, char **argv) xflag = 1; break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/disk-utils/mkfs.bfs.c b/disk-utils/mkfs.bfs.c index 77f253f1ed..54d261b293 100644 --- a/disk-utils/mkfs.bfs.c +++ b/disk-utils/mkfs.bfs.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc < 2) { warnx(_("not enough arguments")); diff --git a/disk-utils/mkfs.c b/disk-utils/mkfs.c index fbd575e7e0..8ba28c2f57 100644 --- a/disk-utils/mkfs.c +++ b/disk-utils/mkfs.c @@ -80,7 +80,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc == 2 && !strcmp(argv[1], "-V")) print_version(EXIT_SUCCESS); diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index bf07f8c67b..71320a0a9e 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -714,14 +714,14 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc > 1) { /* first arg may be one of our standard longopts */ if (!strcmp(argv[1], "--help")) usage(); if (!strcmp(argv[1], "--version")) { - printf(UTIL_LINUX_VERSION); + print_version(EXIT_SUCCESS); exit(MKFS_EX_OK); } } @@ -770,8 +770,7 @@ int main(int argc, char **argv) /* old option, ignored */ break; case 'V': - printf(UTIL_LINUX_VERSION); - exit(MKFS_EX_OK); + print_version(MKFS_EX_OK); case 'v': verbose = 1; break; diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c index 8e6811f49d..ed03f4a42d 100644 --- a/disk-utils/mkfs.minix.c +++ b/disk-utils/mkfs.minix.c @@ -758,7 +758,7 @@ int main(int argc, char ** argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(MKFS_EX_USAGE); @@ -792,8 +792,7 @@ int main(int argc, char ** argv) listfile = optarg; break; case 'V': - printf(UTIL_LINUX_VERSION); - return MKFS_EX_OK; + print_version(MKFS_EX_OK); case 'h': usage(); default: diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 28a139d455..659ebf0d71 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -369,7 +369,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, "cfp:L:v:U:Vh", longopts, NULL)) != -1) { switch (c) { @@ -400,8 +400,7 @@ int main(int argc, char **argv) #endif break; case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/disk-utils/partx.c b/disk-utils/partx.c index e10efa96af..949278eb79 100644 --- a/disk-utils/partx.c +++ b/disk-utils/partx.c @@ -832,7 +832,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, "abdglrsuvn:t:o:PS:hV", long_opts, NULL)) != -1) { @@ -901,8 +901,7 @@ int main(int argc, char **argv) case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/disk-utils/raw.c b/disk-utils/raw.c index 8abcbb747f..b44a581a2d 100644 --- a/disk-utils/raw.c +++ b/disk-utils/raw.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 ((c = getopt_long(argc, argv, "qaVh", longopts, NULL)) != -1) switch (c) { @@ -119,8 +119,7 @@ int main(int argc, char *argv[]) do_query_all = 1; break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/disk-utils/resizepart.c b/disk-utils/resizepart.c index 527517f242..b2738271e2 100644 --- a/disk-utils/resizepart.c +++ b/disk-utils/resizepart.c @@ -80,13 +80,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, "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/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 2427cef5b3..8166137c54 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -1994,7 +1994,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, "aAbcdfFgGhJlLo:O:nN:qrsTu:vVX:Y:w:W:", longopts, &longidx)) != -1) { @@ -2079,9 +2079,7 @@ int main(int argc, char *argv[]) errx(EXIT_FAILURE, _("unsupported unit '%c'"), *optarg); break; case 'v': - printf(_("%s from %s\n"), program_invocation_short_name, - PACKAGE_STRING); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'V': sf->verify = 1; break; diff --git a/disk-utils/swaplabel.c b/disk-utils/swaplabel.c index ccc226a02d..e6ba7d66d7 100644 --- a/disk-utils/swaplabel.c +++ b/disk-utils/swaplabel.c @@ -152,7 +152,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, "hVL:U:", longopts, NULL)) != -1) { switch (c) { @@ -160,8 +160,7 @@ int main(int argc, char *argv[]) usage(); break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'L': label = optarg; break; diff --git a/include/c.h b/include/c.h index fb68352531..fc69b910b7 100644 --- a/include/c.h +++ b/include/c.h @@ -351,6 +351,11 @@ static inline int xusleep(useconds_t usec) #define UTIL_LINUX_VERSION _("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING +#define print_version(eval) __extension__ ({ \ + printf(UTIL_LINUX_VERSION); \ + exit(eval); \ +}) + /* * scanf modifiers for "strings allocation" */ diff --git a/login-utils/chfn.c b/login-utils/chfn.c index c5312fa0c4..a2e6e099e0 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -176,8 +176,7 @@ static void parse_argv(struct chfn_control *ctl, int argc, char **argv) status += check_gecos_string(_("Home Phone"), optarg); break; case 'v': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'u': usage(); default: @@ -412,7 +411,8 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); /* both for messages and for iscntrl() below */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); + uid = getuid(); /* check /etc/login.defs CHFN_RESTRICT */ diff --git a/login-utils/chsh.c b/login-utils/chsh.c index c267c72728..9b27611573 100644 --- a/login-utils/chsh.c +++ b/login-utils/chsh.c @@ -166,8 +166,7 @@ static void parse_argv(int argc, char **argv, struct sinfo *pinfo) while ((c = getopt_long(argc, argv, "s:lhuv", long_options, NULL)) != -1) { switch (c) { case 'v': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'u': /* deprecated */ case 'h': usage(); @@ -264,7 +263,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); parse_argv(argc, argv, &info); if (!info.username) { diff --git a/login-utils/islocal.c b/login-utils/islocal.c index 7c4e775c1a..469bc5629d 100644 --- a/login-utils/islocal.c +++ b/login-utils/islocal.c @@ -91,7 +91,7 @@ int is_local(const char *user) #ifdef TEST_PROGRAM int main(int argc, char *argv[]) { - atexit(close_stdout); + close_stdout_atexit(); if (argc <= 2) { fprintf(stderr, _("Usage: %s ...\n"), argv[0]); diff --git a/login-utils/last.c b/login-utils/last.c index 303adeacd8..2f7d9d48f5 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -939,7 +939,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); /* * Which file do we want to read? */ @@ -954,8 +954,7 @@ int main(int argc, char **argv) usage(&ctl); break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'R': ctl.showhost = 0; break; diff --git a/login-utils/login.c b/login-utils/login.c index ab819f16ff..a2d2725a62 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -1196,8 +1196,7 @@ int main(int argc, char **argv) break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case HELP_OPTION: usage(); default: diff --git a/login-utils/logindefs.c b/login-utils/logindefs.c index 07a977660b..2b505d255d 100644 --- a/login-utils/logindefs.c +++ b/login-utils/logindefs.c @@ -403,7 +403,7 @@ int get_hushlogin_status(struct passwd *pwd, int force_check) int main(int argc, char *argv[]) { char *name, *type; - atexit(close_stdout); + close_stdout_atexit(); if (argc <= 1) errx(EXIT_FAILURE, "usage: %s " diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index c913cf2d84..efb20a4f7c 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -1425,7 +1425,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); ctl->time_mode = TIME_SHORT; @@ -1528,8 +1528,7 @@ int main(int argc, char *argv[]) ctl->time_mode = parse_time_mode(optarg); break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'Z': { #ifdef HAVE_LIBSELINUX diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c index 4538831480..5e4b4caa02 100644 --- a/login-utils/newgrp.c +++ b/login-utils/newgrp.c @@ -196,13 +196,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/login-utils/nologin.c b/login-utils/nologin.c index b0b6a721c1..14a091715e 100644 --- a/login-utils/nologin.c +++ b/login-utils/nologin.c @@ -54,10 +54,8 @@ int main(int argc, char *argv[]) switch (c) { case 'h': usage(); - break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_FAILURE; + print_version(EXIT_FAILURE); /* yes FAILURE! */ default: errtryhelp(EXIT_FAILURE); } diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 94289898d4..86beab99ca 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -1321,7 +1321,7 @@ int su_main(int argc, char **argv, int mode) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); su_init_debug(); su->conv.appdata_ptr = (void *) su; @@ -1392,9 +1392,7 @@ int su_main(int argc, char **argv, int mode) usage(mode); case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c index 5f09bd48e4..549870d224 100644 --- a/login-utils/sulogin.c +++ b/login-utils/sulogin.c @@ -815,6 +815,8 @@ static void usage(void) fputs(USAGE_SEPARATOR, out); printf(USAGE_HELP_OPTIONS(26)); printf(USAGE_MAN_TAIL("sulogin(8)")); + + exit(EXIT_SUCCESS); } int main(int argc, char **argv) @@ -853,7 +855,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); /* XXX */ + close_stdout_atexit(); /* * See if we have a timeout flag. @@ -870,11 +872,9 @@ int main(int argc, char **argv) opt_e = 1; break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); - return EXIT_SUCCESS; default: /* Do not exit! getopt prints a warning. */ break; diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c index 5cc87834ae..f1a3607dc0 100644 --- a/login-utils/utmpdump.c +++ b/login-utils/utmpdump.c @@ -334,7 +334,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, "fro:hV", longopts, NULL)) != -1) { switch (c) { @@ -355,10 +355,8 @@ int main(int argc, char **argv) case 'h': usage(); - break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/login-utils/vipw.c b/login-utils/vipw.c index 2502fcb4ea..2b35036e61 100644 --- a/login-utils/vipw.c +++ b/login-utils/vipw.c @@ -325,7 +325,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (!strcmp(program_invocation_short_name, "vigr")) { program = VIGR; @@ -338,8 +338,7 @@ int main(int argc, char *argv[]) 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/misc-utils/blkid.c b/misc-utils/blkid.c index c03e1bb8d3..2b13f71c0f 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -686,7 +686,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); strutils_set_exitcode(BLKID_EXIT_OTHER); diff --git a/misc-utils/cal.c b/misc-utils/cal.c index bbb22505e7..c7e8d9511e 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -332,7 +332,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); term = getenv("TERM"); if (term) { @@ -435,8 +435,7 @@ int main(int argc, char **argv) ctl.reform_year = ISO; break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c index 6bad2c0401..0fb1a759a0 100644 --- a/misc-utils/fincore.c +++ b/misc-utils/fincore.c @@ -310,7 +310,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, "bno:JrVh", longopts, NULL)) != -1) { switch (c) { @@ -330,8 +330,7 @@ int main(int argc, char ** argv) ctl.raw = 1; break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/findfs.c b/misc-utils/findfs.c index a437bda84a..0997e1b49b 100644 --- a/misc-utils/findfs.c +++ b/misc-utils/findfs.c @@ -50,7 +50,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc != 2) { /* we return '2' for backward compatibility @@ -62,8 +62,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch (c) { case 'V': - printf(UTIL_LINUX_VERSION); - return FINDFS_SUCCESS; + print_version(FINDFS_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 331460bd18..eea772f0e6 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -1348,7 +1348,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); /* default output format */ flags |= FL_TREE; @@ -1391,9 +1391,6 @@ int main(int argc, char *argv[]) case 'e': flags |= FL_EVALUATE; break; - case 'h': - usage(); - break; case 'i': flags |= FL_INVERT; break; @@ -1490,9 +1487,6 @@ int main(int argc, char *argv[]) case 'w': timeout = strtos32_or_err(optarg, _("invalid timeout argument")); break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'x': verify = 1; break; @@ -1508,6 +1502,11 @@ int main(int argc, char *argv[]) case FINDMNT_OPT_REAL: flags |= FL_REAL; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c index 9b4f352795..3fa158eb3b 100644 --- a/misc-utils/getopt.c +++ b/misc-utils/getopt.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(); if (getenv("GETOPT_COMPATIBLE")) ctl.compatible = 1; @@ -413,8 +413,6 @@ int main(int argc, char *argv[]) case 'a': getopt_long_fp = getopt_long_only; break; - case 'h': - usage(); case 'o': free(ctl.optstr); ctl.optstr = xstrdup(optarg); @@ -441,12 +439,14 @@ int main(int argc, char *argv[]) case 'u': ctl.quote = 0; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case '?': case ':': parse_error(NULL); + case 'h': + usage(); default: parse_error(_("internal error, contact the author.")); } diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c index f7cfc961bb..2a1e216a21 100644 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@ -413,7 +413,7 @@ 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, "cnvfx:Vh", longopts, NULL)) != -1) { switch (ch) { @@ -438,8 +438,7 @@ int main(int argc, char **argv) #endif break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/kill.c b/misc-utils/kill.c index 726768bd19..1ac61cf5a6 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -213,10 +213,8 @@ static char **parse_arguments(int argc, char **argv, struct kill_control *ctl) break; } if (!strcmp(arg, "-v") || !strcmp(arg, "-V") || - !strcmp(arg, "--version")) { - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - } + !strcmp(arg, "--version")) + print_version(EXIT_SUCCESS); if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) usage(); if (!strcmp(arg, "--verbose")) { @@ -343,7 +341,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); argv = parse_arguments(argc, argv, &ctl); diff --git a/misc-utils/logger.c b/misc-utils/logger.c index d6cee8287b..a99a0c96cd 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -1155,7 +1155,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); INIT_LIST_HEAD(&ctl.user_sds); INIT_LIST_HEAD(&ctl.reserved_sds); @@ -1212,11 +1212,6 @@ int main(int argc, char **argv) case 'P': ctl.port = optarg; break; - case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - case 'h': - usage(); case OPT_OCTET_COUNT: ctl.octet_count = 1; break; @@ -1263,6 +1258,11 @@ int main(int argc, char **argv) errx(EXIT_FAILURE, _("invalid structured data parameter: '%s'"), optarg); add_structured_data_param(get_user_structured_data(&ctl), optarg); break; + + case 'V': + print_version(EXIT_SUCCESS); + case 'h': + usage(); default: errtryhelp(EXIT_FAILURE); } diff --git a/misc-utils/look.c b/misc-utils/look.c index d2699bfdd6..d3f0622c34 100644 --- a/misc-utils/look.c +++ b/misc-utils/look.c @@ -100,7 +100,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); setlocale(LC_ALL, ""); @@ -127,8 +127,7 @@ main(int argc, char *argv[]) termchar = *optarg; break; case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 915a062baa..c8683854c6 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -1814,7 +1814,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); lsblk = &_ls; @@ -1849,9 +1849,6 @@ int main(int argc, char *argv[]) case 'e': parse_excludes(optarg); break; - case 'h': - usage(); - break; case 'J': lsblk->flags |= LSBLK_JSON; break; @@ -1939,9 +1936,6 @@ int main(int argc, char *argv[]) case OPT_SYSROOT: lsblk->sysroot = optarg; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'E': lsblk->dedup_id = column_name_to_id(optarg, strlen(optarg)); if (lsblk->dedup_id >= 0) @@ -1953,7 +1947,13 @@ int main(int argc, char *argv[]) lsblk->sort_id = column_name_to_id(optarg, strlen(optarg)); if (lsblk->sort_id >= 0) break; - /* fallthrough */ + errtryhelp(EXIT_FAILURE); + break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c index f83fb76f2d..18922e5468 100644 --- a/misc-utils/lslocks.c +++ b/misc-utils/lslocks.c @@ -585,7 +585,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, "biJp:o:nruhV", long_opts, NULL)) != -1) { @@ -612,11 +612,6 @@ 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 'h': - usage(); case 'n': no_headings = 1; break; @@ -626,6 +621,11 @@ int main(int argc, char *argv[]) case 'u': disable_columns_truncate(); break; + + case 'V': + print_version(EXIT_SUCCESS); + case 'h': + usage(); default: errtryhelp(EXIT_FAILURE); } diff --git a/misc-utils/mcookie.c b/misc-utils/mcookie.c index 8598ac3452..ea29a8209f 100644 --- a/misc-utils/mcookie.c +++ b/misc-utils/mcookie.c @@ -147,7 +147,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, "f:m:vVh", longopts, NULL)) != -1) { switch (c) { @@ -163,9 +163,9 @@ int main(int argc, char **argv) ctl.maxsz = strtosize_or_err(optarg, _("failed to parse length")); break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/namei.c b/misc-utils/namei.c index 60171f6002..9c5f5fa4ac 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -372,16 +372,10 @@ 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, "hVlmnovx", longopts, NULL)) != -1) { switch(c) { - case 'h': - usage(); - break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'l': flags |= (NAMEI_OWNERS | NAMEI_MODES | NAMEI_VERTICAL); break; @@ -400,6 +394,11 @@ main(int argc, char **argv) case 'v': flags |= NAMEI_VERTICAL; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/misc-utils/rename.c b/misc-utils/rename.c index 1d9315793a..a9378af59b 100644 --- a/misc-utils/rename.c +++ b/misc-utils/rename.c @@ -243,7 +243,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, "vsVhnoi", longopts, NULL)) != -1) switch (c) { @@ -264,9 +264,9 @@ int main(int argc, char **argv) case 's': do_rename = do_symlink; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index 0382bac47d..af24efc14f 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -576,7 +576,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, "p:s:T:krtn:PFSdqVh", longopts, @@ -629,9 +629,9 @@ int main(int argc, char **argv) uuidd_cxt.timeout = strtou32_or_err(optarg, _("failed to parse --timeout")); break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c index c197069538..fa148abae6 100644 --- a/misc-utils/uuidgen.c +++ b/misc-utils/uuidgen.c @@ -104,7 +104,7 @@ 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, "rtVhn:N:msx", longopts, NULL)) != -1) switch (c) { @@ -114,9 +114,6 @@ main (int argc, char *argv[]) case 'r': do_type = UUID_TYPE_DCE_RANDOM; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'n': namespace = optarg; break; @@ -132,8 +129,11 @@ main (int argc, char *argv[]) case 'x': is_hex = 1; break; + case 'h': usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/misc-utils/uuidparse.c b/misc-utils/uuidparse.c index 6a13f2a2b9..eae0b71a15 100644 --- a/misc-utils/uuidparse.c +++ b/misc-utils/uuidparse.c @@ -304,7 +304,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); @@ -321,9 +321,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/misc-utils/whereis.c b/misc-utils/whereis.c index 2d4c58125a..21f381321b 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -512,7 +512,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")); @@ -521,10 +521,8 @@ int main(int argc, char **argv) /* first arg may be one of our standard longopts */ if (!strcmp(argv[1], "--help")) usage(); - if (!strcmp(argv[1], "--version")) { - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - } + if (!strcmp(argv[1], "--version")) + print_version(EXIT_SUCCESS); } whereis_init_debug(); @@ -628,9 +626,9 @@ int main(int argc, char **argv) case 'l': list_dirlist(ls); break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index 13a720e85f..78e5ac376e 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -700,7 +700,7 @@ 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, "abfhiJnO:o:pqt:V", longopts, NULL)) != -1) { @@ -716,9 +716,6 @@ main(int argc, char **argv) case 'f': ctl.force = 1; break; - case 'h': - usage(); - break; case 'J': ctl.json = 1; break; @@ -745,9 +742,11 @@ main(int argc, char **argv) case 't': ctl.type_pattern = optarg; break; + + case 'h': + usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/schedutils/chrt.c b/schedutils/chrt.c index b08c78ed8a..cc3a8c2f0e 100644 --- a/schedutils/chrt.c +++ b/schedutils/chrt.c @@ -434,7 +434,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, "+abdD:fiphmoP:T:rRvV", longopts, NULL)) != -1) { @@ -489,9 +489,9 @@ int main(int argc, char **argv) case 'D': ctl->deadline = strtou64_or_err(optarg, _("invalid deadline argument")); break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/schedutils/ionice.c b/schedutils/ionice.c index b4c6a82a2e..ae2c73ea5b 100644 --- a/schedutils/ionice.c +++ b/schedutils/ionice.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(); while ((c = getopt_long(argc, argv, "+n:c:p:P:u:tVh", longopts, NULL)) != EOF) switch (c) { @@ -197,9 +197,9 @@ int main(int argc, char **argv) case 't': tolerant = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/schedutils/taskset.c b/schedutils/taskset.c index fe79cd6314..56db817924 100644 --- a/schedutils/taskset.c +++ b/schedutils/taskset.c @@ -157,7 +157,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); memset(&ts, 0, sizeof(ts)); @@ -173,12 +173,11 @@ int main(int argc, char **argv) case 'c': ts.use_list = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); - break; default: errtryhelp(EXIT_FAILURE); } diff --git a/sys-utils/blkdiscard.c b/sys-utils/blkdiscard.c index c19b67bf4d..f9ba5e468e 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 1dcbdf5004..5fd5da7a36 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 4060a4ca4a..c4e5bc7e29 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 861f6cfd22..b3645be19d 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 eff95b6bf7..1096ab1863 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 ea662c4868..9ead946213 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 ba4e225283..f96e5bdf7e 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 81cd2bcff6..d2e76d2ffe 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 ba3867cae8..04a3eaff53 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 57153c8d9a..8dddebefd5 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 401ab5c980..4da1a6fa3c 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 830556458a..87a9031b7f 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 5f4c014fc5..9512f696ef 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 df836525a1..8aadffbbba 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 a9f2d1b9ad..5a27b7d209 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 73cf28ab1c..2d18a13cce 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 fb50711eb5..3019e5a9fd 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 3dbbcdd3eb..d862fd8e73 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 774a27b3a0..9a5a1aa5b5 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 e8ada571e7..5ba9cd7bfe 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 86383360ac..a1272ae609 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 38ea2e0098..c298d6a3cd 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 b1b43251e7..b391347fc6 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 00a74daf03..985130cba2 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 fbfcf98318..f294b12579 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 ea76d94bfe..aef1b12bb9 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 6f806362d1..607849066f 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 ca0037529c..1d484252ac 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 3ae71f9c1d..5efecdfd00 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 a93e8ba83f..b00bf753e3 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 029f00f9b5..1058e8af9c 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 fb4c4d333e..f84e90b5bf 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 828ddc12fd..717031d94a 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 8b4f83dd2e..5725e80090 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 0a3807fdac..a13d4f1e58 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 357dcb3f74..7e3135c729 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 a85ce24b93..a42bceca31 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 fe261f393c..b1e7f75df5 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 929da8d91b..e3734b0ec2 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 e9ddb09de3..21910a4ee8 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 642db85d22..4574e10da8 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 69267c860c..dedfa345e9 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: diff --git a/term-utils/mesg.c b/term-utils/mesg.c index 608f3cf61a..57d53379f2 100644 --- a/term-utils/mesg.c +++ b/term-utils/mesg.c @@ -102,16 +102,16 @@ 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, "vVh", longopts, NULL)) != -1) switch (ch) { case 'v': verbose = TRUE; break; + case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/term-utils/script.c b/term-utils/script.c index 7692f91e2b..c7bc1d6f27 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -793,7 +793,7 @@ int main(int argc, char **argv) setlocale(LC_NUMERIC, "C"); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); script_init_debug(); @@ -825,13 +825,11 @@ int main(int argc, char **argv) ctl.tname = optarg; ctl.timing = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - break; + print_version(EXIT_SUCCESS); case 'h': usage(); - break; default: errtryhelp(EXIT_FAILURE); } diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c index 7b59b6e244..926e56f11c 100644 --- a/term-utils/scriptreplay.c +++ b/term-utils/scriptreplay.c @@ -151,7 +151,7 @@ main(int argc, char *argv[]) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); while ((ch = getopt_long(argc, argv, "t:s:d:m:Vh", longopts, NULL)) != -1) switch(ch) { @@ -169,9 +169,9 @@ main(int argc, char *argv[]) maxdelayopt = TRUE; maxdelay = getnum(optarg); break; + case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/term-utils/setterm.c b/term-utils/setterm.c index 0d4b81292a..14fbafb107 100644 --- a/term-utils/setterm.c +++ b/term-utils/setterm.c @@ -673,9 +673,9 @@ static void parse_option(struct setterm_control *ctl, int ac, char **av) ctl->opt_bfreq = set_opt_flag(ctl->opt_bfreq); ctl->opt_bfreq_f = parse_bfreq(av, optarg, &optind); break; + case OPT_VERSION: - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case OPT_HELP: usage(); default: @@ -1173,7 +1173,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc < 2) { warnx(_("bad usage")); diff --git a/term-utils/wall.c b/term-utils/wall.c index ce5363c7e7..c606e63474 100644 --- a/term-utils/wall.c +++ b/term-utils/wall.c @@ -202,7 +202,7 @@ 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, "nt:g:Vh", longopts, NULL)) != -1) { switch (ch) { @@ -220,9 +220,9 @@ int main(int argc, char **argv) case 'g': group_buf = init_group_workspace(optarg); break; + case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/term-utils/write.c b/term-utils/write.c index bd64fc281a..3436fbda20 100644 --- a/term-utils/write.c +++ b/term-utils/write.c @@ -308,13 +308,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, "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/text-utils/col.c b/text-utils/col.c index 1ba195e246..5ad38bc97f 100644 --- a/text-utils/col.c +++ b/text-utils/col.c @@ -190,7 +190,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); max_bufd_lines = 128 * 2; compress_spaces = 1; /* compress spaces into tabs */ @@ -220,9 +220,9 @@ int main(int argc, char **argv) case 'x': /* do not compress spaces into tabs */ compress_spaces = 0; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'H': usage(); default: diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c index 6113880e40..798f5bd7b8 100644 --- a/text-utils/colcrt.c +++ b/text-utils/colcrt.c @@ -239,7 +239,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); /* Take care of lonely hyphen option. */ for (opt = 0; opt < argc; opt++) { @@ -260,9 +260,9 @@ int main(int argc, char **argv) case '2': ctl.half_lines = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/colrm.c b/text-utils/colrm.c index 8bb0ee9cce..d0ef2eb662 100644 --- a/text-utils/colrm.c +++ b/text-utils/colrm.c @@ -173,8 +173,7 @@ int main(int argc, char **argv) NULL)) != -1) switch (opt) { case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/column.c b/text-utils/column.c index 8961bd38b6..78eeddb8e4 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -706,7 +706,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); ctl.output_separator = " "; ctl.input_separator = mbs_to_wcs("\t "); @@ -731,9 +731,6 @@ int main(int argc, char **argv) case 'H': ctl.tab_colhide = optarg; break; - case 'h': - usage(); - break; case 'i': ctl.tree_id = optarg; break; @@ -776,15 +773,17 @@ int main(int argc, char **argv) case 't': ctl.mode = COLUMN_MODE_TABLE; break; - case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; case 'W': ctl.tab_colwrap = optarg; break; case 'x': ctl.mode = COLUMN_MODE_FILLROWS; break; + + case 'h': + usage(); + case 'V': + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c index 94c53b8e52..cbd593e5f9 100644 --- a/text-utils/hexdump.c +++ b/text-utils/hexdump.c @@ -130,12 +130,11 @@ parse_args(int argc, char **argv, struct hexdump *hex) add_fmt(hex_offt, hex); add_fmt("\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"", hex); break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - break; + print_version(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } @@ -193,7 +192,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); argv += parse_args(argc, argv, hex); diff --git a/text-utils/line.c b/text-utils/line.c index 63c001261d..e894076189 100644 --- a/text-utils/line.c +++ b/text-utils/line.c @@ -54,13 +54,12 @@ 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, "Vh", longopts, NULL)) != -1) switch (opt) { case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/more.c b/text-utils/more.c index 8d394bc304..6e1ca569c9 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -275,7 +275,7 @@ static void arg_parser(struct more_control *ctl, char *s) case '\t': break; case 'V': - printf(UTIL_LINUX_VERSION); + print_version(EXIT_SUCCESS); exit(EXIT_SUCCESS); break; default: @@ -1920,16 +1920,14 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (argc > 1) { /* first arg may be one of our standard longopts */ if (!strcmp(argv[1], "--help")) usage(); - if (!strcmp(argv[1], "--version")) { - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); - } + if (!strcmp(argv[1], "--version")) + print_version(EXIT_SUCCESS); } ctl.num_files = argc; diff --git a/text-utils/pg.c b/text-utils/pg.c index f441c04f01..7eef9b88be 100644 --- a/text-utils/pg.c +++ b/text-utils/pg.c @@ -1544,7 +1544,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); if (tcgetattr(STDOUT_FILENO, &otio) == 0) { ontty = 1; @@ -1570,7 +1570,7 @@ int main(int argc, char **argv) } if (!strcmp(argv[arg], "--version")) { - printf(UTIL_LINUX_VERSION); + print_version(EXIT_SUCCESS); return EXIT_SUCCESS; } @@ -1621,11 +1621,11 @@ int main(int argc, char **argv) case 's': sflag = 1; break; + case 'h': usage(); case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); default: invopt(&argv[arg][i]); } diff --git a/text-utils/rev.c b/text-utils/rev.c index 13a41f633e..57624e6fb1 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -121,8 +121,7 @@ int main(int argc, char *argv[]) while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch(ch) { case 'V': - printf(UTIL_LINUX_VERSION); - exit(EXIT_SUCCESS); + print_version(EXIT_SUCCESS); case 'h': usage(); default: diff --git a/text-utils/ul.c b/text-utils/ul.c index b5ce4db845..3a9e31bc7b 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -172,7 +172,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - atexit(close_stdout); + close_stdout_atexit(); signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); @@ -191,9 +191,9 @@ int main(int argc, char **argv) case 'i': iflag = 1; break; + case 'V': - printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + print_version(EXIT_SUCCESS); case 'h': usage(); default: -- 2.39.2