diff options
author | Karel Zak | 2017-06-26 13:47:04 +0200 |
---|---|---|
committer | Karel Zak | 2017-06-26 13:47:04 +0200 |
commit | dfdb1ca8186cfc84ad95d5e356334ce8633a28f7 (patch) | |
tree | 37b568d27fa12194ec63f8122901fc8b2fd7bf1d | |
parent | Merge branch 'usage-part1' of https://github.com/rudimeier/util-linux (diff) | |
parent | misc: fix optutils.h related exit codes (diff) | |
download | kernel-qcow2-util-linux-dfdb1ca8186cfc84ad95d5e356334ce8633a28f7.tar.gz kernel-qcow2-util-linux-dfdb1ca8186cfc84ad95d5e356334ce8633a28f7.tar.xz kernel-qcow2-util-linux-dfdb1ca8186cfc84ad95d5e356334ce8633a28f7.zip |
Merge branch 'fix-exit-codes' of https://github.com/rudimeier/util-linux
* 'fix-exit-codes' of https://github.com/rudimeier/util-linux:
misc: fix optutils.h related exit codes
misc: fix xalloc.h related exit codes
misc: fix more strutils related exit codes
lib: fix strutils.h, remove STRTOXX_EXIT_CODE
misc: fix some broken exit codes
-rw-r--r-- | disk-utils/fsck.c | 3 | ||||
-rw-r--r-- | disk-utils/fsck.cramfs.c | 4 | ||||
-rw-r--r-- | disk-utils/fsck.minix.c | 2 | ||||
-rw-r--r-- | disk-utils/mkfs.cramfs.c | 3 | ||||
-rw-r--r-- | disk-utils/mkfs.minix.c | 4 | ||||
-rw-r--r-- | include/strutils.h | 7 | ||||
-rw-r--r-- | lib/strutils.c | 6 | ||||
-rw-r--r-- | misc-utils/blkid.c | 5 | ||||
-rw-r--r-- | misc-utils/findfs.c | 4 | ||||
-rw-r--r-- | sys-utils/flock.c | 2 | ||||
-rw-r--r-- | sys-utils/hwclock.c | 3 | ||||
-rw-r--r-- | sys-utils/mount.c | 6 | ||||
-rw-r--r-- | sys-utils/tunelp.c | 10 | ||||
-rw-r--r-- | sys-utils/umount.c | 6 |
14 files changed, 48 insertions, 17 deletions
diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index cbe179ba6..918103ac0 100644 --- a/disk-utils/fsck.c +++ b/disk-utils/fsck.c @@ -54,8 +54,6 @@ #include "c.h" #include "fileutils.h" #include "monotonic.h" - -#define STRTOXX_EXIT_CODE FSCK_EX_ERROR #include "strutils.h" #define XALLOC_EXIT_CODE FSCK_EX_ERROR @@ -1612,6 +1610,7 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(FSCK_EX_USAGE); mnt_init_debug(0); /* init libmount debug mask */ mntcache = mnt_new_cache(); /* no fatal error if failed */ diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c index 63033d626..1dba95eb5 100644 --- a/disk-utils/fsck.cramfs.c +++ b/disk-utils/fsck.cramfs.c @@ -660,6 +660,8 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(FSCK_EX_USAGE); + /* command line options */ while ((c = getopt_long(argc, argv, "ayvVhb:", longopts, NULL)) != EOF) switch (c) { @@ -671,7 +673,7 @@ int main(int argc, char **argv) break; case 'V': printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + return 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 dea3436d4..bff810ec3 100644 --- a/disk-utils/fsck.minix.c +++ b/disk-utils/fsck.minix.c @@ -1293,6 +1293,8 @@ main(int argc, char **argv) { textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(FSCK_EX_USAGE); + if (INODE_SIZE * MINIX_INODES_PER_BLOCK != MINIX_BLOCK_SIZE) die(_("bad inode size")); if (INODE2_SIZE * MINIX2_INODES_PER_BLOCK != MINIX_BLOCK_SIZE) diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index 87b378c81..74664a811 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -726,6 +726,7 @@ int main(int argc, char **argv) exit(MKFS_EX_OK); } } + strutils_set_exitcode(MKFS_EX_USAGE); /* command line options */ while ((c = getopt(argc, argv, "hb:Ee:i:n:N:psVvz")) != EOF) { @@ -922,5 +923,5 @@ int main(int argc, char **argv) (warn_namelen|warn_skip|warn_size|warn_uid|warn_gid|warn_dev)) exit(MKFS_EX_ERROR); - return EXIT_SUCCESS; + return MKFS_EX_OK; } diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c index 47a155c55..98a62668a 100644 --- a/disk-utils/mkfs.minix.c +++ b/disk-utils/mkfs.minix.c @@ -77,6 +77,8 @@ #include "all-io.h" #include "closestream.h" #include "ismounted.h" + +#define XALLOC_EXIT_CODE MKFS_EX_ERROR #include "xalloc.h" #define MINIX_ROOT_INO 1 @@ -758,6 +760,8 @@ int main(int argc, char ** argv) textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(MKFS_EX_USAGE); + while ((i = getopt_long(argc, argv, "1v23n:i:cl:Vh", longopts, NULL)) != -1) switch (i) { case '1': diff --git a/include/strutils.h b/include/strutils.h index 28c1b5e5d..be1ba6737 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -9,11 +9,8 @@ #include <stdio.h> #include <errno.h> -/* default strtoxx_or_err() exit code */ -#ifndef STRTOXX_EXIT_CODE -# define STRTOXX_EXIT_CODE EXIT_FAILURE -#endif - +/* initialize a custom exit code for all *_or_err functions */ +extern void strutils_set_exitcode(int exit_code); extern int parse_size(const char *str, uintmax_t *res, int *power); extern int strtosize(const char *str, uintmax_t *res); diff --git a/lib/strutils.c b/lib/strutils.c index 45127b5a2..74d2e5aa9 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -17,6 +17,12 @@ #include "strutils.h" #include "bitops.h" +static int STRTOXX_EXIT_CODE = EXIT_FAILURE; + +void strutils_set_exitcode(int ex) { + STRTOXX_EXIT_CODE = ex; +} + static int do_scale_by_power (uintmax_t *x, int base, int power) { while (power--) { diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index f95f673a2..52179e5e1 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -34,7 +34,6 @@ #include "ismounted.h" -#define STRTOXX_EXIT_CODE BLKID_EXIT_OTHER /* strtoxx_or_err() */ #include "strutils.h" #define OPTUTILS_EXIT_CODE BLKID_EXIT_OTHER /* exclusive_option() */ #include "optutils.h" @@ -43,6 +42,8 @@ #include "nls.h" #include "ttyutils.h" + +#define XALLOC_EXIT_CODE BLKID_EXIT_OTHER /* x.*alloc(), xstrndup() */ #include "xalloc.h" struct blkid_control { @@ -691,6 +692,8 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(BLKID_EXIT_OTHER); + while ((c = getopt_long (argc, argv, "c:dghilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts, NULL)) != -1) { diff --git a/misc-utils/findfs.c b/misc-utils/findfs.c index 7935232eb..7d2d803dd 100644 --- a/misc-utils/findfs.c +++ b/misc-utils/findfs.c @@ -63,11 +63,11 @@ int main(int argc, char **argv) switch (c) { case 'V': printf(UTIL_LINUX_VERSION); - return EXIT_SUCCESS; + return FINDFS_SUCCESS; case 'h': usage(FINDFS_SUCCESS); default: - errtryhelp(EXIT_FAILURE); + errtryhelp(FINDFS_USAGE_ERROR); } dev = blkid_evaluate_tag(argv[1], NULL, NULL); diff --git a/sys-utils/flock.c b/sys-utils/flock.c index 50194bdb9..003a12618 100644 --- a/sys-utils/flock.c +++ b/sys-utils/flock.c @@ -170,6 +170,8 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(EX_USAGE); + if (argc < 2) usage(EX_USAGE); diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index 0f604960c..07ad61385 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -71,6 +71,7 @@ #include <unistd.h> #define OPTUTILS_EXIT_CODE EX_USAGE +#define XALLOC_EXIT_CODE EX_OSERR #include "c.h" #include "closestream.h" @@ -1326,6 +1327,8 @@ int main(int argc, char **argv) }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; + strutils_set_exitcode(EX_USAGE); + /* Remember what time we were invoked */ gettimeofday(&startup_time, NULL); diff --git a/sys-utils/mount.c b/sys-utils/mount.c index 4d7a5fc73..ffe294e3f 100644 --- a/sys-utils/mount.c +++ b/sys-utils/mount.c @@ -36,10 +36,12 @@ #include "c.h" #include "env.h" #include "strutils.h" -#include "xalloc.h" #include "closestream.h" #include "canonicalize.h" +#define XALLOC_EXIT_CODE MNT_EX_SYSERR +#include "xalloc.h" + #define OPTUTILS_EXIT_CODE MNT_EX_USAGE #include "optutils.h" @@ -534,6 +536,8 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(MNT_EX_USAGE); + mnt_init_debug(0); cxt = mnt_new_context(); if (!cxt) diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c index 8cfbe80a2..2749dd1c8 100644 --- a/sys-utils/tunelp.c +++ b/sys-utils/tunelp.c @@ -71,13 +71,15 @@ #include "lp.h" #include "nls.h" -#include "xalloc.h" #include "closestream.h" +#include "strutils.h" -#define STRTOXX_EXIT_CODE 3 +#define EXIT_LP_MALLOC 2 +#define EXIT_LP_BADVAL 3 #define EXIT_LP_IO_ERR 4 -#include "strutils.h" +#define XALLOC_EXIT_CODE EXIT_LP_MALLOC +#include "xalloc.h" struct command { long op; @@ -144,6 +146,8 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); + strutils_set_exitcode(EXIT_LP_BADVAL); + if (argc < 2) print_usage(stderr); diff --git a/sys-utils/umount.c b/sys-utils/umount.c index ed8fd4fe2..57140a660 100644 --- a/sys-utils/umount.c +++ b/sys-utils/umount.c @@ -32,12 +32,16 @@ #include "nls.h" #include "c.h" #include "env.h" -#include "optutils.h" #include "closestream.h" #include "pathnames.h" #include "canonicalize.h" + +#define XALLOC_EXIT_CODE MNT_EX_SYSERR #include "xalloc.h" +#define OPTUTILS_EXIT_CODE MNT_EX_USAGE +#include "optutils.h" + static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)), const char *filename, int line) { |