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 /misc-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 'misc-utils')
-rw-r--r-- | misc-utils/blkid.c | 2 | ||||
-rw-r--r-- | misc-utils/cal.c | 5 | ||||
-rw-r--r-- | misc-utils/fincore.c | 5 | ||||
-rw-r--r-- | misc-utils/findfs.c | 5 | ||||
-rw-r--r-- | misc-utils/findmnt.c | 13 | ||||
-rw-r--r-- | misc-utils/getopt.c | 10 | ||||
-rw-r--r-- | misc-utils/hardlink.c | 5 | ||||
-rw-r--r-- | misc-utils/kill.c | 8 | ||||
-rw-r--r-- | misc-utils/logger.c | 12 | ||||
-rw-r--r-- | misc-utils/look.c | 5 | ||||
-rw-r--r-- | misc-utils/lsblk.c | 16 | ||||
-rw-r--r-- | misc-utils/lslocks.c | 12 | ||||
-rw-r--r-- | misc-utils/mcookie.c | 6 | ||||
-rw-r--r-- | misc-utils/namei.c | 13 | ||||
-rw-r--r-- | misc-utils/rename.c | 6 | ||||
-rw-r--r-- | misc-utils/uuidd.c | 6 | ||||
-rw-r--r-- | misc-utils/uuidgen.c | 8 | ||||
-rw-r--r-- | misc-utils/uuidparse.c | 6 | ||||
-rw-r--r-- | misc-utils/whereis.c | 12 | ||||
-rw-r--r-- | misc-utils/wipefs.c | 11 |
20 files changed, 77 insertions, 89 deletions
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index c03e1bb8d..2b13f71c0 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 bbb22505e..c7e8d9511 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 6bad2c040..0fb1a759a 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 a437bda84..0997e1b49 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 331460bd1..eea772f0e 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 9b4f35279..3fa158eb3 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 f7cfc961b..2a1e216a2 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 726768bd1..1ac61cf5a 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 d6cee8287..a99a0c96c 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 d2699bfdd..d3f0622c3 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 915a062ba..c8683854c 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 f83fb76f2..18922e546 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 8598ac345..ea29a8209 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 60171f600..9c5f5fa4a 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 1d9315793..a9378af59 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 0382bac47..af24efc14 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 c19706953..fa148abae 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 6a13f2a2b..eae0b71a1 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 2d4c58125..21f381321 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 13a720e85..78e5ac376 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); } |