From 05691d9e8857de4e83b343f042e9f4590f15425d Mon Sep 17 00:00:00 2001 From: Ruediger Meier Date: Tue, 20 Jun 2017 20:01:32 +0200 Subject: misc: fix some broken exit codes These tools have special exit codes. They got changed mistakenly. See: findfs 0e1fa6b6 fsck 658c0891 fsck.cramfs 922ec175 mkfs.cramfs 16154b1f tunelp 2ab428f6 FIXME: STRTOXX_EXIT_CODE doesn't work as it should. Signed-off-by: Ruediger Meier --- disk-utils/fsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'disk-utils/fsck.c') diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index cb1b21278..5a418fc1f 100644 --- a/disk-utils/fsck.c +++ b/disk-utils/fsck.c @@ -55,7 +55,7 @@ #include "fileutils.h" #include "monotonic.h" -#define STRTOXX_EXIT_CODE FSCK_EX_ERROR +#define STRTOXX_EXIT_CODE FSCK_EX_USAGE #include "strutils.h" #define XALLOC_EXIT_CODE FSCK_EX_ERROR -- cgit v1.2.3-55-g7522 From 9c8b9fbacc043164c5ac8adc2b5bdc25402e912c Mon Sep 17 00:00:00 2001 From: Ruediger Meier Date: Thu, 22 Jun 2017 22:15:14 +0200 Subject: lib: fix strutils.h, remove STRTOXX_EXIT_CODE As discussed on the mailing list. We fix all places where the non-working define STRTOXX_EXIT_CODE was used. Regarding tunelp, also see 7e3c80a7. Signed-off-by: Ruediger Meier --- disk-utils/fsck.c | 3 +-- include/strutils.h | 7 ++----- lib/strutils.c | 6 ++++++ misc-utils/blkid.c | 3 ++- sys-utils/tunelp.c | 7 ++++--- 5 files changed, 15 insertions(+), 11 deletions(-) (limited to 'disk-utils/fsck.c') diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index 5a418fc1f..e310fc394 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_USAGE #include "strutils.h" #define XALLOC_EXIT_CODE FSCK_EX_ERROR @@ -1599,6 +1597,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/include/strutils.h b/include/strutils.h index 28c1b5e5d..be1ba6737 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -9,11 +9,8 @@ #include #include -/* 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 1dc8f4085..73731f0b8 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" @@ -691,6 +690,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/sys-utils/tunelp.c b/sys-utils/tunelp.c index 89afff1ba..2749dd1c8 100644 --- a/sys-utils/tunelp.c +++ b/sys-utils/tunelp.c @@ -72,13 +72,12 @@ #include "lp.h" #include "nls.h" #include "closestream.h" +#include "strutils.h" #define EXIT_LP_MALLOC 2 -#define STRTOXX_EXIT_CODE 3 +#define EXIT_LP_BADVAL 3 #define EXIT_LP_IO_ERR 4 -#include "strutils.h" - #define XALLOC_EXIT_CODE EXIT_LP_MALLOC #include "xalloc.h" @@ -147,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); -- cgit v1.2.3-55-g7522