From 1a82a852667894d7e6da85cafabe130b98e52856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 7 Feb 2024 14:44:39 +0100 Subject: [PATCH 1/2] Use _exit() in the fatal() function Since the fatal() isn't a correct but rather abrupt termination of the program, we want to skip the various atexit() calls because not all memory might be freed during fatal() call, etc. Using _exit() instead of exit() has this effect - the program will end, but no destructors or atexit routines will be called. (cherry picked from commit 4bec711fe3643f50f525b1879b43eeb9be1a0b7a) --- bin/check/named-checkzone.c | 36 ++++++++++++++++++------------------ bin/confgen/util.c | 6 ++++-- bin/delv/delv.c | 2 +- bin/dig/dighost.c | 12 ++++++------ bin/dnssec/dnssectool.c | 3 ++- bin/named/main.c | 6 +++--- bin/named/server.c | 9 +++++---- bin/nsupdate/nsupdate.c | 2 +- bin/rndc/util.c | 3 ++- bin/tools/dnstap-read.c | 3 ++- bin/tools/mdig.c | 2 +- bin/tools/named-rrchecker.c | 3 ++- bin/tools/nsec3hash.c | 3 ++- 13 files changed, 49 insertions(+), 41 deletions(-) diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index 5c74660c0c..6090d24282 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -82,7 +82,7 @@ usage(void) { "%s zonename [ (filename|-) ]\n", prog_name, progmode == progmode_check ? "[-o filename]" : "-o filename"); - exit(1); + exit(EXIT_FAILURE); } static void @@ -212,7 +212,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -i: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -246,7 +246,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -k: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -257,7 +257,7 @@ main(int argc, char **argv) { if (*endp != '\0') { fprintf(stderr, "source serial number " "must be numeric"); - exit(1); + exit(EXIT_FAILURE); } break; @@ -268,7 +268,7 @@ main(int argc, char **argv) { if (*endp != '\0') { fprintf(stderr, "maximum TTL " "must be numeric"); - exit(1); + exit(EXIT_FAILURE); } break; @@ -285,7 +285,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -n: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -302,7 +302,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -m: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -327,7 +327,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -r: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -340,7 +340,7 @@ main(int argc, char **argv) { fprintf(stderr, "unknown or unsupported style: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -350,7 +350,7 @@ main(int argc, char **argv) { fprintf(stderr, "isc_dir_chroot: %s: %s\n", isc_commandline_argument, isc_result_totext(result)); - exit(1); + exit(EXIT_FAILURE); } break; @@ -379,7 +379,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -M: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -396,7 +396,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -S: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -408,7 +408,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "invalid argument to -T: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -432,7 +432,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", prog_name, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } @@ -441,7 +441,7 @@ main(int argc, char **argv) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "isc_dir_chdir: %s: %s\n", workdir, isc_result_totext(result)); - exit(1); + exit(EXIT_FAILURE); } } @@ -457,7 +457,7 @@ main(int argc, char **argv) { } else { fprintf(stderr, "unknown file format: %s\n", inputformatstr); - exit(1); + exit(EXIT_FAILURE); } } @@ -475,12 +475,12 @@ main(int argc, char **argv) { rawversion > 1U) { fprintf(stderr, "unknown raw format version\n"); - exit(1); + exit(EXIT_FAILURE); } } else { fprintf(stderr, "unknown file format: %s\n", outputformatstr); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/confgen/util.c b/bin/confgen/util.c index b0085fe13d..254f139461 100644 --- a/bin/confgen/util.c +++ b/bin/confgen/util.c @@ -13,14 +13,16 @@ /*! \file */ -#include "util.h" #include #include #include #include +#include #include +#include "util.h" + extern bool verbose; extern const char *progname; @@ -45,5 +47,5 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + _exit(EXIT_FAILURE); } diff --git a/bin/delv/delv.c b/bin/delv/delv.c index e1e9e7fe3d..d47b99aac0 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -221,7 +221,7 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + _exit(EXIT_FAILURE); } static void diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index b5e27931e5..4d7e09ef15 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -383,8 +383,6 @@ get_reverse(char *reverse, size_t len, char *value, bool strict) { } } -void (*dighost_pre_exit_hook)(void) = NULL; - #if TARGET_OS_IPHONE void warn(const char *format, ...) { @@ -417,10 +415,7 @@ digexit(void) { exitcode = 10; } if (fatalexit != 0) { - exitcode = fatalexit; - } - if (dighost_pre_exit_hook != NULL) { - dighost_pre_exit_hook(); + _exit(fatalexit); } exit(exitcode); } @@ -435,6 +430,11 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); + if (fatalexit == 0 && exitcode != 0) { + fatalexit = exitcode; + } else if (fatalexit == 0) { + fatalexit = EXIT_FAILURE; + } digexit(); } diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index c07e091266..8250a127a4 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -81,7 +82,7 @@ fatal(const char *format, ...) { if (fatalcallback != NULL) { (*fatalcallback)(); } - exit(1); + _exit(EXIT_FAILURE); } void diff --git a/bin/named/main.c b/bin/named/main.c index 154e17efa7..eca30c6ab7 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -184,7 +184,7 @@ named_main_earlyfatal(const char *format, ...) { } va_end(args); - exit(1); + _exit(EXIT_FAILURE); } noreturn static void @@ -238,7 +238,7 @@ assertion_failed(const char *file, int line, isc_assertiontype_t type, if (named_g_coreok) { abort(); } - exit(1); + _exit(EXIT_FAILURE); } noreturn static void @@ -278,7 +278,7 @@ library_fatal_error(const char *file, int line, const char *func, if (named_g_coreok) { abort(); } - exit(1); + _exit(EXIT_FAILURE); } static void diff --git a/bin/named/server.c b/bin/named/server.c index 6ad090fd5f..c88a47574a 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -148,11 +148,11 @@ #endif /* HAVE_LMDB */ #ifndef SIZE_MAX -#define SIZE_MAX ((size_t) - 1) +#define SIZE_MAX ((size_t)-1) #endif /* ifndef SIZE_MAX */ #ifndef SIZE_AS_PERCENT -#define SIZE_AS_PERCENT ((size_t) - 2) +#define SIZE_AS_PERCENT ((size_t)-2) #endif /* ifndef SIZE_AS_PERCENT */ #ifdef TUNE_LARGE @@ -221,8 +221,9 @@ #define CHECKFATAL(op, msg) \ do { \ result = (op); \ - if (result != ISC_R_SUCCESS) \ + if (result != ISC_R_SUCCESS) { \ fatal(server, msg, result); \ + } \ } while (0) /*% @@ -10426,7 +10427,7 @@ fatal(named_server_t *server, const char *msg, isc_result_t result) { NAMED_LOGMODULE_SERVER, ISC_LOG_CRITICAL, "exiting (due to fatal error)"); named_os_shutdown(); - exit(1); + _exit(1); } static void diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 980d54328c..8e068bebef 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -266,7 +266,7 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + _exit(EXIT_FAILURE); } static void diff --git a/bin/rndc/util.c b/bin/rndc/util.c index b0085fe13d..bc892f0ca1 100644 --- a/bin/rndc/util.c +++ b/bin/rndc/util.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -45,5 +46,5 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + _exit(EXIT_FAILURE); } diff --git a/bin/tools/dnstap-read.c b/bin/tools/dnstap-read.c index 06dd561406..c55534feb4 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -83,7 +84,7 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + _exit(EXIT_FAILURE); } static void diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index f84f1daed0..12f289ffb2 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -901,7 +901,7 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(-2); + _exit(EXIT_FAILURE); } static isc_result_t diff --git a/bin/tools/named-rrchecker.c b/bin/tools/named-rrchecker.c index 4d8a318b5f..278a0a267d 100644 --- a/bin/tools/named-rrchecker.c +++ b/bin/tools/named-rrchecker.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -76,7 +77,7 @@ fatal(const char *format, ...) { va_end(args); fputc('\n', stderr); cleanup(); - exit(1); + _exit(EXIT_FAILURE); } int diff --git a/bin/tools/nsec3hash.c b/bin/tools/nsec3hash.c index a6a5ec3a71..e76f7be025 100644 --- a/bin/tools/nsec3hash.c +++ b/bin/tools/nsec3hash.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -47,7 +48,7 @@ fatal(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + _exit(EXIT_FAILURE); } static void From 236de53c52e8d6b84eefd0d6f039f249ab858500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 7 Feb 2024 14:50:38 +0100 Subject: [PATCH 2/2] Use EXIT_SUCCESS and EXIT_FAILURE Instead of randomly using -1 or 1 as a failure status, properly utilize the EXIT_FAILURE define that's platform specific (as it should be). (cherry picked from commit76997983fde02d9c32aa23bda30b65f1ebd4178c) --- bin/check/named-checkconf.c | 16 ++++----- bin/check/named-checkzone.c | 2 +- bin/confgen/rndc-confgen.c | 11 ++++--- bin/confgen/tsig-keygen.c | 20 +++++------ bin/delv/delv.c | 10 +++--- bin/dig/dig.c | 8 ++--- bin/dig/host.c | 4 +-- bin/dig/nslookup.c | 4 +-- bin/dnssec/dnssec-cds.c | 5 +-- bin/dnssec/dnssec-dsfromkey.c | 4 +-- bin/dnssec/dnssec-importkey.c | 4 +-- bin/dnssec/dnssec-keyfromlabel.c | 6 ++-- bin/dnssec/dnssec-keygen.c | 4 +-- bin/dnssec/dnssec-revoke.c | 4 +-- bin/dnssec/dnssec-settime.c | 4 +-- bin/dnssec/dnssec-signzone.c | 10 +++--- bin/dnssec/dnssec-verify.c | 4 +-- bin/dnssec/dnssectool.c | 2 +- bin/named/main.c | 8 ++--- bin/named/os.c | 4 +-- bin/named/server.c | 6 ++-- bin/nsupdate/nsupdate.c | 32 +++++++++--------- bin/rndc/rndc.c | 2 +- bin/tests/system/pipelined/pipequeries.c | 8 ++--- bin/tests/system/resolve.c | 42 ++++++++++++------------ bin/tests/system/rsabigexponent/bigkey.c | 6 ++-- bin/tests/system/tkey/keycreate.c | 8 ++--- bin/tests/system/tkey/keydelete.c | 10 +++--- bin/tests/test_client.c | 2 +- bin/tests/test_server.c | 2 +- bin/tests/wire_test.c | 14 ++++---- bin/tools/dnstap-read.c | 2 +- bin/tools/mdig.c | 10 +++--- bin/tools/named-journalprint.c | 4 +-- bin/tools/named-nzd2nzf.c | 17 +++++----- bin/tools/named-rrchecker.c | 8 ++--- bin/tools/nsec3hash.c | 2 +- doc/misc/cfg_test.c | 10 +++--- lib/dns/gen.c | 34 +++++++++---------- lib/dns/openssl_link.c | 2 +- lib/isc/app.c | 2 +- 41 files changed, 180 insertions(+), 177 deletions(-) diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index fd7cfa53bf..cc146ecd9d 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -67,7 +67,7 @@ usage(void) { "usage: %s [-chijlvz] [-p [-x]] [-t directory] " "[named.conf]\n", program); - exit(1); + exit(EXIT_SUCCESS); } /*% directory callback */ @@ -573,7 +573,7 @@ output(void *closure, const char *text, int textlen) { UNUSED(closure); if (fwrite(text, 1, textlen, stdout) != (size_t)textlen) { perror("fwrite"); - exit(1); + exit(EXIT_FAILURE); } } @@ -653,7 +653,7 @@ main(int argc, char **argv) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "isc_dir_chroot: %s\n", isc_result_totext(result)); - exit(1); + exit(EXIT_FAILURE); } break; @@ -663,7 +663,7 @@ main(int argc, char **argv) { case 'v': printf("%s\n", PACKAGE_VERSION); - exit(0); + exit(EXIT_SUCCESS); case 'x': flags |= CFG_PRINTER_XKEY; @@ -688,17 +688,17 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } if (((flags & CFG_PRINTER_XKEY) != 0) && !print) { fprintf(stderr, "%s: -x cannot be used without -p\n", program); - exit(1); + exit(EXIT_FAILURE); } if (print && list_zones) { fprintf(stderr, "%s: -l cannot be used with -p\n", program); - exit(1); + exit(EXIT_FAILURE); } if (isc_commandline_index + 1 < argc) { @@ -723,7 +723,7 @@ main(int argc, char **argv) { if (cfg_parse_file(parser, conffile, &cfg_type_namedconf, &config) != ISC_R_SUCCESS) { - exit(1); + exit(EXIT_FAILURE); } result = bind9_check_namedconf(config, loadplugins, nodeprecate, logc, diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index 6090d24282..b72a0ce4b0 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -356,7 +356,7 @@ main(int argc, char **argv) { case 'v': printf("%s\n", PACKAGE_VERSION); - exit(0); + exit(EXIT_SUCCESS); case 'w': workdir = isc_commandline_argument; diff --git a/bin/confgen/rndc-confgen.c b/bin/confgen/rndc-confgen.c index 817929544e..e8d51b9d23 100644 --- a/bin/confgen/rndc-confgen.c +++ b/bin/confgen/rndc-confgen.c @@ -147,7 +147,8 @@ main(int argc, char **argv) { keyfile = isc_commandline_argument; break; case 'h': - usage(0); + usage(EXIT_SUCCESS); + break; case 'k': case 'y': /* Compatible with rndc -y. */ keyname = isc_commandline_argument; @@ -193,15 +194,15 @@ main(int argc, char **argv) { if (isc_commandline_option != '?') { fprintf(stderr, "%s: invalid argument -%c\n", program, isc_commandline_option); - usage(1); + usage(EXIT_FAILURE); } else { - usage(0); + usage(EXIT_SUCCESS); } break; default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } @@ -210,7 +211,7 @@ main(int argc, char **argv) { POST(argv); if (argc > 0) { - usage(1); + usage(EXIT_FAILURE); } if (alg == DST_ALG_HMACMD5) { diff --git a/bin/confgen/tsig-keygen.c b/bin/confgen/tsig-keygen.c index b44f1a9158..6d6f766414 100644 --- a/bin/confgen/tsig-keygen.c +++ b/bin/confgen/tsig-keygen.c @@ -139,13 +139,13 @@ main(int argc, char **argv) { keysize = alg_bits(alg); break; case 'h': - usage(0); + usage(EXIT_SUCCESS); case 'k': case 'y': if (progmode == progmode_confgen) { keyname = isc_commandline_argument; } else { - usage(1); + usage(EXIT_FAILURE); } break; case 'M': @@ -158,7 +158,7 @@ main(int argc, char **argv) { if (progmode == progmode_confgen) { quiet = true; } else { - usage(1); + usage(EXIT_FAILURE); } break; case 'r': @@ -168,29 +168,29 @@ main(int argc, char **argv) { if (progmode == progmode_confgen) { self_domain = isc_commandline_argument; } else { - usage(1); + usage(EXIT_FAILURE); } break; case 'z': if (progmode == progmode_confgen) { zone = isc_commandline_argument; } else { - usage(1); + usage(EXIT_FAILURE); } break; case '?': if (isc_commandline_option != '?') { fprintf(stderr, "%s: invalid argument -%c\n", program, isc_commandline_option); - usage(1); + usage(EXIT_FAILURE); } else { - usage(0); + usage(EXIT_SUCCESS); } break; default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } @@ -201,11 +201,11 @@ main(int argc, char **argv) { POST(argv); if (self_domain != NULL && zone != NULL) { - usage(1); /* -s and -z cannot coexist */ + usage(EXIT_FAILURE); /* -s and -z cannot coexist */ } if (argc > isc_commandline_index) { - usage(1); + usage(EXIT_FAILURE); } /* Use canonical algorithm name */ diff --git a/bin/delv/delv.c b/bin/delv/delv.c index d47b99aac0..c750629517 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -205,7 +205,7 @@ usage(void) { "process)\n" " +[no]yaml (Present the results as " "YAML)\n"); - exit(1); + exit(EXIT_FAILURE); } noreturn static void @@ -1132,7 +1132,7 @@ plus_option(char *option) { if (state) { fprintf(stderr, "Invalid option: " "+dlv is obsolete\n"); - exit(1); + exit(EXIT_FAILURE); } break; case 'n': /* dnssec */ @@ -1329,7 +1329,7 @@ dash_option(char *option, char *next, bool *open_type_class) { break; case 'h': usage(); - exit(0); + exit(EXIT_SUCCESS); case 'i': no_sigs = true; root_validation = false; @@ -1339,7 +1339,7 @@ dash_option(char *option, char *next, bool *open_type_class) { break; case 'v': fprintf(stderr, "delv %s\n", PACKAGE_VERSION); - exit(0); + exit(EXIT_SUCCESS); default: UNREACHABLE(); } @@ -1472,7 +1472,7 @@ dash_option(char *option, char *next, bool *open_type_class) { typeset = true; } else { fprintf(stderr, "Invalid IP address %s\n", value); - exit(1); + exit(EXIT_FAILURE); } return (value_from_next); invalid_option: diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 04b3a9ba98..d4867cc282 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -121,7 +121,7 @@ usage(void) { print_usage(stderr); fprintf(stderr, "\nUse \"dig -h\" (or \"dig -h | more\") " "for complete list of options\n"); - exit(1); + exit(EXIT_FAILURE); } #endif /* if TARGET_OS_IPHONE */ @@ -2278,7 +2278,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup, break; case 'h': help(); - exit(0); + exit(EXIT_SUCCESS); break; case 'i': /* deprecated */ @@ -2298,7 +2298,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup, break; case 'v': version(); - exit(0); + exit(EXIT_SUCCESS); break; } if (strlen(option) > 1U) { @@ -2507,7 +2507,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup, ISC_LIST_APPEND(lookup_list, *lookup, link); } else { fprintf(stderr, "Invalid IP address %s\n", value); - exit(1); + exit(EXIT_FAILURE); } return (value_from_next); invalid_option: diff --git a/bin/dig/host.c b/bin/dig/host.c index 57c1fb492d..c8ab804923 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -134,7 +134,7 @@ show_usage(void) { " -W specifies how long to wait for a reply\n" " -4 use IPv4 query transport only\n" " -6 use IPv6 query transport only\n"); - exit(1); + exit(EXIT_FAILURE); } static void @@ -663,7 +663,7 @@ pre_parse_args(int argc, char **argv) { break; case 'V': version(); - exit(0); + exit(EXIT_SUCCESS); break; case 'w': break; diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index d8e7537255..6e4082ac15 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -870,7 +870,7 @@ usage(void) { "'host' using default server\n"); fprintf(stderr, " nslookup [-opt ...] host server # just look up " "'host' using 'server'\n"); - exit(1); + exit(EXIT_FAILURE); } static void @@ -883,7 +883,7 @@ parse_args(int argc, char **argv) { if (argv[0][0] == '-') { if (strncasecmp(argv[0], "-ver", 4) == 0) { version(); - exit(0); + exit(EXIT_SUCCESS); } else if (argv[0][1] != 0) { setoption(&argv[0][1]); } else { diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index 06b1f8c90b..673cabed4b 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -1059,7 +1059,7 @@ usage(void) { " -T TTL of DS records\n" " -V print version\n" " -v \n"); - exit(1); + exit(EXIT_FAILURE); } static void @@ -1357,5 +1357,6 @@ main(int argc, char *argv[]) { cleanup: print_mem_stats = true; cleanup(); - exit(0); + + return (0); } diff --git a/bin/dnssec/dnssec-dsfromkey.c b/bin/dnssec/dnssec-dsfromkey.c index 42aa9e5c7b..bf0530c123 100644 --- a/bin/dnssec/dnssec-dsfromkey.c +++ b/bin/dnssec/dnssec-dsfromkey.c @@ -354,7 +354,7 @@ usage(void) { " -V: print version information\n"); fprintf(stderr, "Output: DS or CDS RRs\n"); - exit(-1); + exit(EXIT_FAILURE); } int @@ -453,7 +453,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/dnssec/dnssec-importkey.c b/bin/dnssec/dnssec-importkey.c index 441f7c3f8b..ca89fc9f4e 100644 --- a/bin/dnssec/dnssec-importkey.c +++ b/bin/dnssec/dnssec-importkey.c @@ -290,7 +290,7 @@ usage(void) { fprintf(stderr, " -D sync date/[+-]offset/none: set/unset " "CDS and CDNSKEY deletion date\n"); - exit(-1); + exit(EXIT_FAILURE); } int @@ -397,7 +397,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/dnssec/dnssec-keyfromlabel.c b/bin/dnssec/dnssec-keyfromlabel.c index 53ca718784..cf207d33ff 100644 --- a/bin/dnssec/dnssec-keyfromlabel.c +++ b/bin/dnssec/dnssec-keyfromlabel.c @@ -103,7 +103,7 @@ usage(void) { fprintf(stderr, " K++.key, " "K++.private\n"); - exit(-1); + exit(EXIT_FAILURE); } int @@ -334,7 +334,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } @@ -619,7 +619,7 @@ main(int argc, char **argv) { fatal("failed to get key %s/%s: %s", namestr, algstr, isc_result_totext(ret)); UNREACHABLE(); - exit(-1); + exit(EXIT_FAILURE); } /* diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index 3d77976fab..08686cfe05 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -209,7 +209,7 @@ usage(void) { fprintf(stderr, " K++.key, " "K++.private\n"); - exit(-1); + exit(EXIT_FAILURE); } static void @@ -1132,7 +1132,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/dnssec/dnssec-revoke.c b/bin/dnssec/dnssec-revoke.c index 93ee20cca2..c3be1066ca 100644 --- a/bin/dnssec/dnssec-revoke.c +++ b/bin/dnssec/dnssec-revoke.c @@ -59,7 +59,7 @@ usage(void) { fprintf(stderr, " K++.key, " "K++.private\n"); - exit(-1); + exit(EXIT_FAILURE); } int @@ -131,7 +131,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/dnssec/dnssec-settime.c b/bin/dnssec/dnssec-settime.c index 100ff88fad..4df45125ca 100644 --- a/bin/dnssec/dnssec-settime.c +++ b/bin/dnssec/dnssec-settime.c @@ -102,7 +102,7 @@ usage(void) { fprintf(stderr, " K++.key, " "K++.private\n"); - exit(-1); + exit(EXIT_FAILURE); } static void @@ -539,7 +539,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 41f1fc1a47..229e9efb8c 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -3311,7 +3311,7 @@ usage(void) { fprintf(stderr, "(default: all zone keys that have private keys)\n"); fprintf(stderr, "\tkeyfile (Kname+alg+tag)\n"); - exit(0); + exit(EXIT_FAILURE); } static void @@ -3555,7 +3555,7 @@ main(int argc, char *argv[]) { if (*endp != '\0') { fprintf(stderr, "source serial number " "must be numeric"); - exit(1); + exit(EXIT_FAILURE); } break; @@ -3570,7 +3570,7 @@ main(int argc, char *argv[]) { if (*endp != '\0') { fprintf(stderr, "maximum TTL " "must be numeric"); - exit(1); + exit(EXIT_FAILURE); } break; @@ -3693,7 +3693,7 @@ main(int argc, char *argv[]) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } @@ -3799,7 +3799,7 @@ main(int argc, char *argv[]) { rawversion > 1U) { fprintf(stderr, "unknown raw format version\n"); - exit(1); + exit(EXIT_FAILURE); } } else { fatal("unknown file format: %s", outputformatstr); diff --git a/bin/dnssec/dnssec-verify.c b/bin/dnssec/dnssec-verify.c index 5f2f2d13e4..a2a849f655 100644 --- a/bin/dnssec/dnssec-verify.c +++ b/bin/dnssec/dnssec-verify.c @@ -165,7 +165,7 @@ usage(void) { fprintf(stderr, "\t-x:\tDNSKEY record signed with KSKs only, " "not ZSKs\n"); fprintf(stderr, "\t-z:\tAll records signed with KSKs\n"); - exit(0); + exit(EXIT_SUCCESS); } int @@ -271,7 +271,7 @@ main(int argc, char *argv[]) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index 8250a127a4..d2812536d3 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -112,7 +112,7 @@ vbprintf(int level, const char *fmt, ...) { void version(const char *name) { fprintf(stderr, "%s %s\n", name, PACKAGE_VERSION); - exit(0); + exit(EXIT_SUCCESS); } void diff --git a/bin/named/main.c b/bin/named/main.c index eca30c6ab7..843bf9e0ba 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -898,7 +898,7 @@ parse_command_line(int argc, char *argv[]) { printf("# Built-in default values. " "This is NOT the run-time configuration!\n"); printf("%s", named_config_getdefault()); - exit(0); + exit(EXIT_SUCCESS); case 'd': named_g_debuglevel = parse_int(isc_commandline_argument, "debug " @@ -963,10 +963,10 @@ parse_command_line(int argc, char *argv[]) { break; case 'v': printversion(false); - exit(0); + exit(EXIT_SUCCESS); case 'V': printversion(true); - exit(0); + exit(EXIT_SUCCESS); case 'x': /* Obsolete. No longer in use. Ignore. */ break; @@ -985,7 +985,7 @@ parse_command_line(int argc, char *argv[]) { case '?': usage(); if (isc_commandline_option == '?') { - exit(0); + exit(EXIT_SUCCESS); } p = strchr(NAMED_MAIN_ARGS, isc_commandline_option); if (p == NULL || *++p != ':') { diff --git a/bin/named/os.c b/bin/named/os.c index 0222abb7c2..9a53352599 100644 --- a/bin/named/os.c +++ b/bin/named/os.c @@ -300,10 +300,10 @@ named_os_daemonize(void) { char buf; n = read(dfd[0], &buf, 1); if (n == 1) { - _exit(0); + _exit(EXIT_SUCCESS); } } while (n == -1 && errno == EINTR); - _exit(1); + _exit(EXIT_FAILURE); } (void)close(dfd[0]); diff --git a/bin/named/server.c b/bin/named/server.c index c88a47574a..9ad6d6046b 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -148,11 +148,11 @@ #endif /* HAVE_LMDB */ #ifndef SIZE_MAX -#define SIZE_MAX ((size_t)-1) +#define SIZE_MAX ((size_t) - 1) #endif /* ifndef SIZE_MAX */ #ifndef SIZE_AS_PERCENT -#define SIZE_AS_PERCENT ((size_t)-2) +#define SIZE_AS_PERCENT ((size_t) - 2) #endif /* ifndef SIZE_AS_PERCENT */ #ifdef TUNE_LARGE @@ -10427,7 +10427,7 @@ fatal(named_server_t *server, const char *msg, isc_result_t result) { NAMED_LOGMODULE_SERVER, ISC_LOG_CRITICAL, "exiting (due to fatal error)"); named_os_shutdown(); - _exit(1); + _exit(EXIT_FAILURE); } static void diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 8e068bebef..45ba90fba7 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -499,7 +499,7 @@ setup_keystr(void) { name = secretstr; secretstr = n + 1; if (!parse_hmac(&hmacname, keystr, s - keystr, &digestbits)) { - exit(1); + exit(EXIT_FAILURE); } } else { hmacname = DNS_TSIG_HMACMD5_NAME; @@ -1027,7 +1027,7 @@ pre_parse_args(int argc, char **argv) { "| -k keyfile] [-p port] " "[-v] [-V] [-P] [-T] [-4 | -6] " "[filename]\n"); - exit(1); + exit(EXIT_FAILURE); case 'P': for (t = 0xff00; t <= 0xfffe; t++) { @@ -1065,7 +1065,7 @@ pre_parse_args(int argc, char **argv) { } } if (doexit) { - exit(0); + exit(EXIT_SUCCESS); } isc_commandline_reset = true; isc_commandline_index = 1; @@ -1124,7 +1124,7 @@ parse_args(int argc, char **argv) { "bad library debug value " "'%s'\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } logdebuglevel = i; break; @@ -1153,7 +1153,7 @@ parse_args(int argc, char **argv) { "bad port number " "'%s'\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; case 't': @@ -1162,7 +1162,7 @@ parse_args(int argc, char **argv) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "bad timeout '%s'\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } if (timeout == 0) { timeout = UINT_MAX; @@ -1174,7 +1174,7 @@ parse_args(int argc, char **argv) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "bad udp timeout '%s'\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; case 'r': @@ -1183,7 +1183,7 @@ parse_args(int argc, char **argv) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "bad udp retries '%s'\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; @@ -1194,19 +1194,19 @@ parse_args(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option: %c\n", argv[0], isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } if (keyfile != NULL && keystr != NULL) { fprintf(stderr, "%s: cannot specify both -k and -y\n", argv[0]); - exit(1); + exit(EXIT_FAILURE); } #if HAVE_GSSAPI if (usegsstsig && (keyfile != NULL || keystr != NULL)) { fprintf(stderr, "%s: cannot specify -g with -k or -y\n", argv[0]); - exit(1); + exit(EXIT_FAILURE); } #else /* HAVE_GSSAPI */ if (usegsstsig) { @@ -1214,7 +1214,7 @@ parse_args(int argc, char **argv) { "%s: cannot specify -g or -o, " "program not linked with GSS API Library\n", argv[0]); - exit(1); + exit(EXIT_FAILURE); } #endif /* HAVE_GSSAPI */ @@ -1228,7 +1228,7 @@ parse_args(int argc, char **argv) { fprintf(stderr, "could not open '%s': %s\n", argv[isc_commandline_index], isc_result_totext(result)); - exit(1); + exit(EXIT_FAILURE); } } if (!force_interactive) { @@ -2072,7 +2072,7 @@ show_message(FILE *stream, dns_message_t *msg, const char *description) { if (bufsz > MAXTEXT) { fprintf(stderr, "could not allocate large enough " "buffer to display message\n"); - exit(1); + exit(EXIT_FAILURE); } if (buf != NULL) { isc_buffer_free(&buf); @@ -3457,7 +3457,7 @@ main(int argc, char **argv) { if (seenerror) { return (2); - } else { - return (0); } + + return (0); } diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 87c36ba07a..882026bb95 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -1014,7 +1014,7 @@ main(int argc, char **argv) { default: fprintf(stderr, "%s: unhandled option -%c\n", program, isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index 7419d22b0e..52e2a54424 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -50,7 +50,7 @@ if ((x) != ISC_R_SUCCESS) { \ fprintf(stderr, "I:%s: %s\n", (str), \ isc_result_totext(x)); \ - exit(-1); \ + exit(EXIT_FAILURE); \ } \ } @@ -82,7 +82,7 @@ recvresponse(isc_task_t *task, isc_event_t *event) { if (reqev->result != ISC_R_SUCCESS) { fprintf(stderr, "I:request event result: %s\n", isc_result_totext(reqev->result)); - exit(-1); + exit(EXIT_FAILURE); } query = reqev->ev_arg; @@ -97,7 +97,7 @@ recvresponse(isc_task_t *task, isc_event_t *event) { result = dns_result_fromrcode(response->rcode); fprintf(stderr, "I:response rcode: %s\n", isc_result_totext(result)); - exit(-1); + exit(EXIT_FAILURE); } if (response->counts[DNS_SECTION_ANSWER] != 1U) { fprintf(stderr, "I:response answer count (%u!=1)\n", @@ -221,7 +221,7 @@ main(int argc, char *argv[]) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "bad port '%s'\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; case 'r': diff --git a/bin/tests/system/resolve.c b/bin/tests/system/resolve.c index 3142757d58..14df6c0b83 100644 --- a/bin/tests/system/resolve.c +++ b/bin/tests/system/resolve.c @@ -137,7 +137,7 @@ usage(void) { "[-S domain:serveraddr_for_domain ] [-s server_address]" "[-b address[#port]] hostname\n"); - exit(1); + exit(EXIT_FAILURE); } static void @@ -162,7 +162,7 @@ set_key(dns_client_t *client, char *keynamestr, char *keystr, bool is_sep) { result = dns_secalg_fromtext(&alg, &tr); if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to identify the algorithm\n"); - exit(1); + exit(EXIT_FAILURE); } } else { alg = DNS_KEYALG_RSASHA1; @@ -182,7 +182,7 @@ set_key(dns_client_t *client, char *keynamestr, char *keystr, bool is_sep) { result = isc_base64_decodestring(keystr, &keydatabuf); if (result != ISC_R_SUCCESS) { fprintf(stderr, "base64 decode failed\n"); - exit(1); + exit(EXIT_FAILURE); } isc_buffer_usedregion(&keydatabuf, &r); keystruct.datalen = r.length; @@ -193,7 +193,7 @@ set_key(dns_client_t *client, char *keynamestr, char *keystr, bool is_sep) { &rrdatabuf); if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to construct key rdata\n"); - exit(1); + exit(EXIT_FAILURE); } namelen = strlen(keynamestr); isc_buffer_init(&b, keynamestr, namelen); @@ -202,14 +202,14 @@ set_key(dns_client_t *client, char *keynamestr, char *keystr, bool is_sep) { result = dns_name_fromtext(keyname, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to construct key name\n"); - exit(1); + exit(EXIT_FAILURE); } result = dns_client_addtrustedkey(client, dns_rdataclass_in, dns_rdatatype_dnskey, keyname, &rrdatabuf); if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to add key for %s\n", keynamestr); - exit(1); + exit(EXIT_FAILURE); } } @@ -234,7 +234,7 @@ addserver(dns_client_t *client, const char *addrstr, const char *port, if (gaierror != 0) { fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(gaierror)); - exit(1); + exit(EXIT_FAILURE); } INSIST(res->ai_addrlen <= sizeof(sa.type)); memmove(&sa.type, res->ai_addr, res->ai_addrlen); @@ -253,7 +253,7 @@ addserver(dns_client_t *client, const char *addrstr, const char *port, if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to convert qname: %u\n", result); - exit(1); + exit(EXIT_FAILURE); } } @@ -261,7 +261,7 @@ addserver(dns_client_t *client, const char *addrstr, const char *port, &servers); if (result != ISC_R_SUCCESS) { fprintf(stderr, "set server failed: %u\n", result); - exit(1); + exit(EXIT_FAILURE); } } @@ -303,7 +303,7 @@ main(int argc, char *argv[]) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "invalid RRtype: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; case 'a': @@ -317,7 +317,7 @@ main(int argc, char *argv[]) { fprintf(stderr, "only one local " "address per family " "can be specified\n"); - exit(1); + exit(EXIT_FAILURE); } isc_sockaddr_fromin(&a4, &in4, 0); addr4 = &a4; @@ -328,14 +328,14 @@ main(int argc, char *argv[]) { fprintf(stderr, "only one local " "address per family " "can be specified\n"); - exit(1); + exit(EXIT_FAILURE); } isc_sockaddr_fromin6(&a6, &in6, 0); addr6 = &a6; } else { fprintf(stderr, "invalid address %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; case 'e': @@ -347,7 +347,7 @@ main(int argc, char *argv[]) { "alternate server " "already defined: %s\n", altserver); - exit(1); + exit(EXIT_FAILURE); } altserver = isc_commandline_argument; break; @@ -357,7 +357,7 @@ main(int argc, char *argv[]) { "server " "already defined: %s\n", server); - exit(1); + exit(EXIT_FAILURE); } server = isc_commandline_argument; break; @@ -388,7 +388,7 @@ main(int argc, char *argv[]) { if (cp == NULL) { fprintf(stderr, "invalid alternate server: %s\n", altserver); - exit(1); + exit(EXIT_FAILURE); } *cp = '\0'; altservername = altserver; @@ -403,7 +403,7 @@ main(int argc, char *argv[]) { result = dst_lib_init(ctxs_mctx, NULL); if (result != ISC_R_SUCCESS) { fprintf(stderr, "dst_lib_init failed: %u\n", result); - exit(1); + exit(EXIT_FAILURE); } clientopt = 0; @@ -413,7 +413,7 @@ main(int argc, char *argv[]) { if (result != ISC_R_SUCCESS) { fprintf(stderr, "dns_client_create failed: %u, %s\n", result, isc_result_totext(result)); - exit(1); + exit(EXIT_FAILURE); } /* Set the nameserver */ @@ -426,7 +426,7 @@ main(int argc, char *argv[]) { if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) { fprintf(stderr, "irs_resconf_load failed: %u\n", result); - exit(1); + exit(EXIT_FAILURE); } nameservers = irs_resconf_getnameservers(resconf); result = dns_client_setservers(client, dns_rdataclass_in, NULL, @@ -435,7 +435,7 @@ main(int argc, char *argv[]) { irs_resconf_destroy(&resconf); fprintf(stderr, "dns_client_setservers failed: %u\n", result); - exit(1); + exit(EXIT_FAILURE); } irs_resconf_destroy(&resconf); } else { @@ -452,7 +452,7 @@ main(int argc, char *argv[]) { if (keystr == NULL) { fprintf(stderr, "key string is missing " "while key name is provided\n"); - exit(1); + exit(EXIT_FAILURE); } set_key(client, keynamestr, keystr, is_sep); } diff --git a/bin/tests/system/rsabigexponent/bigkey.c b/bin/tests/system/rsabigexponent/bigkey.c index 19fc9bad08..59525da53e 100644 --- a/bin/tests/system/rsabigexponent/bigkey.c +++ b/bin/tests/system/rsabigexponent/bigkey.c @@ -68,7 +68,7 @@ EVP_PKEY *pkey; msg, isc_result_totext(result), __FILE__, \ __LINE__); \ ERR_clear_error(); \ - exit(1); \ + exit(EXIT_FAILURE); \ } \ } while (0) @@ -86,7 +86,7 @@ main(int argc, char **argv) { { fprintf(stderr, "fatal error: basic OpenSSL failure\n"); ERR_clear_error(); - exit(1); + exit(EXIT_FAILURE); } /* e = 0x1000000000001 */ @@ -102,7 +102,7 @@ main(int argc, char **argv) { "at file %s line %d\n", __FILE__, __LINE__); ERR_clear_error(); - exit(1); + exit(EXIT_FAILURE); } isc_mem_create(&mctx); diff --git a/bin/tests/system/tkey/keycreate.c b/bin/tests/system/tkey/keycreate.c index 37f6e48cb6..50f3eb275e 100644 --- a/bin/tests/system/tkey/keycreate.c +++ b/bin/tests/system/tkey/keycreate.c @@ -45,7 +45,7 @@ if ((x) != ISC_R_SUCCESS) { \ fprintf(stderr, "I:%s: %s\n", (str), \ isc_result_totext(x)); \ - exit(-1); \ + exit(EXIT_FAILURE); \ } \ } @@ -81,7 +81,7 @@ recvquery(isc_task_t *task, isc_event_t *event) { if (reqev->result != ISC_R_SUCCESS) { fprintf(stderr, "I:request event result: %s\n", isc_result_totext(reqev->result)); - exit(-1); + exit(EXIT_FAILURE); } query = reqev->ev_arg; @@ -96,7 +96,7 @@ recvquery(isc_task_t *task, isc_event_t *event) { result = dns_result_fromrcode(response->rcode); fprintf(stderr, "I:response rcode: %s\n", isc_result_totext(result)); - exit(-1); + exit(EXIT_FAILURE); } result = dns_tkey_processdhresponse(query, response, ourkey, &nonce, @@ -204,7 +204,7 @@ main(int argc, char *argv[]) { if (argc < 4) { fprintf(stderr, "I:no DH key provided\n"); - exit(-1); + exit(EXIT_FAILURE); } ip_address = argv[1]; port = atoi(argv[2]); diff --git a/bin/tests/system/tkey/keydelete.c b/bin/tests/system/tkey/keydelete.c index f653a183df..563f5914c1 100644 --- a/bin/tests/system/tkey/keydelete.c +++ b/bin/tests/system/tkey/keydelete.c @@ -44,7 +44,7 @@ if ((x) != ISC_R_SUCCESS) { \ fprintf(stderr, "I:%s: %s\n", (str), \ isc_result_totext(x)); \ - exit(-1); \ + exit(EXIT_FAILURE); \ } \ } @@ -72,7 +72,7 @@ recvquery(isc_task_t *task, isc_event_t *event) { if (reqev->result != ISC_R_SUCCESS) { fprintf(stderr, "I:request event result: %s\n", isc_result_totext(reqev->result)); - exit(-1); + exit(EXIT_FAILURE); } query = reqev->ev_arg; @@ -87,7 +87,7 @@ recvquery(isc_task_t *task, isc_event_t *event) { result = dns_result_fromrcode(response->rcode); fprintf(stderr, "I:response rcode: %s\n", isc_result_totext(result)); - exit(-1); + exit(EXIT_FAILURE); } result = dns_tkey_processdeleteresponse(query, response, ring); @@ -149,11 +149,11 @@ main(int argc, char **argv) { if (argc < 4) { fprintf(stderr, "I:no key to delete\n"); - exit(-1); + exit(EXIT_FAILURE); } if (strcmp(argv[1], "-r") == 0) { fprintf(stderr, "I:The -r options has been deprecated\n"); - exit(-1); + exit(EXIT_FAILURE); } ip_address = argv[1]; port = atoi(argv[2]); diff --git a/bin/tests/test_client.c b/bin/tests/test_client.c index ad6a4c7f41..39d2aa589b 100644 --- a/bin/tests/test_client.c +++ b/bin/tests/test_client.c @@ -449,5 +449,5 @@ main(int argc, char **argv) { teardown(); - exit(EXIT_SUCCESS); + return (EXIT_SUCCESS); } diff --git a/bin/tests/test_server.c b/bin/tests/test_server.c index 3dedf6a610..2c03a20a88 100644 --- a/bin/tests/test_server.c +++ b/bin/tests/test_server.c @@ -322,5 +322,5 @@ main(int argc, char **argv) { teardown(); - exit(EXIT_SUCCESS); + return (EXIT_SUCCESS); } diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index b21f5f0f52..e7d28898bc 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -42,7 +42,7 @@ CHECKRESULT(isc_result_t result, const char *msg) { if (result != ISC_R_SUCCESS) { printf("%s: %s\n", msg, isc_result_totext(result)); - exit(1); + exit(EXIT_FAILURE); } } @@ -57,7 +57,7 @@ fromhex(char c) { } fprintf(stderr, "bad input format: %02x\n", c); - exit(3); + exit(EXIT_FAILURE); } static void @@ -164,7 +164,7 @@ main(int argc, char *argv[]) { break; default: usage(); - exit(1); + exit(EXIT_FAILURE); } } @@ -175,7 +175,7 @@ main(int argc, char *argv[]) { f = fopen(argv[0], "r"); if (f == NULL) { fprintf(stderr, "%s: fopen failed\n", argv[0]); - exit(1); + exit(EXIT_FAILURE); } need_close = true; } else { @@ -215,7 +215,7 @@ main(int argc, char *argv[]) { if (len % 2 != 0U) { fprintf(stderr, "bad input format: %lu\n", (unsigned long)len); - exit(1); + exit(EXIT_FAILURE); } rp = s; @@ -240,13 +240,13 @@ main(int argc, char *argv[]) { if (isc_buffer_remaininglength(input) < 2) { fprintf(stderr, "premature end of packet\n"); - exit(1); + exit(EXIT_FAILURE); } tcplen = isc_buffer_getuint16(input); if (isc_buffer_remaininglength(input) < tcplen) { fprintf(stderr, "premature end of packet\n"); - exit(1); + exit(EXIT_FAILURE); } process_message(input); } diff --git a/bin/tools/dnstap-read.c b/bin/tools/dnstap-read.c index c55534feb4..a1d0243a1a 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -349,7 +349,7 @@ main(int argc, char *argv[]) { break; default: usage(); - exit(1); + exit(EXIT_FAILURE); } } diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index 12f289ffb2..b0ff68718a 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -61,7 +61,7 @@ if ((x) != ISC_R_SUCCESS) { \ fprintf(stderr, "mdig: %s failed with %s\n", (str), \ isc_result_totext(x)); \ - exit(-1); \ + exit(EXIT_FAILURE); \ } \ } @@ -208,7 +208,7 @@ recvresponse(isc_task_t *task, isc_event_t *event) { if (continue_on_error) { goto cleanup; } else { - exit(-1); + exit(EXIT_FAILURE); } } @@ -789,7 +789,7 @@ usage(void) { " {local-opt} [ host {local-opt} [...]]\n" "\nUse \"mdig -h\" (or \"mdig -h | more\") " "for complete list of options\n"); - exit(1); + exit(EXIT_FAILURE); } /*% help */ @@ -1703,7 +1703,7 @@ dash_option(const char *option, char *next, struct query *query, bool global, break; case 'h': help(); - exit(0); + exit(EXIT_SUCCESS); break; case 'i': /* deprecated */ @@ -1715,7 +1715,7 @@ dash_option(const char *option, char *next, struct query *query, bool global, break; case 'v': fprintf(stderr, "mDiG %s\n", PACKAGE_VERSION); - exit(0); + exit(EXIT_SUCCESS); break; } if (strlen(option) > 1U) { diff --git a/bin/tools/named-journalprint.c b/bin/tools/named-journalprint.c index 402163df4f..8f38969c3b 100644 --- a/bin/tools/named-journalprint.c +++ b/bin/tools/named-journalprint.c @@ -31,7 +31,7 @@ const char *progname = NULL; static void usage(void) { fprintf(stderr, "Usage: %s [-dux] journal\n", progname); - exit(1); + exit(EXIT_FAILURE); } /* @@ -85,7 +85,7 @@ main(int argc, char **argv) { if (endp == isc_commandline_argument || *endp != 0) { fprintf(stderr, "invalid serial: %s\n", isc_commandline_argument); - exit(1); + exit(EXIT_FAILURE); } break; case 'd': diff --git a/bin/tools/named-nzd2nzf.c b/bin/tools/named-nzd2nzf.c index 630b65bcf6..49e4232e33 100644 --- a/bin/tools/named-nzd2nzf.c +++ b/bin/tools/named-nzd2nzf.c @@ -35,7 +35,7 @@ main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: named-nzd2nzf \n"); - exit(1); + exit(EXIT_FAILURE); } path = argv[1]; @@ -44,35 +44,35 @@ main(int argc, char *argv[]) { if (status != MDB_SUCCESS) { fprintf(stderr, "named-nzd2nzf: mdb_env_create: %s", mdb_strerror(status)); - exit(1); + exit(EXIT_FAILURE); } status = mdb_env_open(env, path, DNS_LMDB_FLAGS, 0600); if (status != MDB_SUCCESS) { fprintf(stderr, "named-nzd2nzf: mdb_env_open: %s", mdb_strerror(status)); - exit(1); + exit(EXIT_FAILURE); } status = mdb_txn_begin(env, 0, MDB_RDONLY, &txn); if (status != MDB_SUCCESS) { fprintf(stderr, "named-nzd2nzf: mdb_txn_begin: %s", mdb_strerror(status)); - exit(1); + exit(EXIT_FAILURE); } status = mdb_dbi_open(txn, NULL, 0, &dbi); if (status != MDB_SUCCESS) { fprintf(stderr, "named-nzd2nzf: mdb_dbi_open: %s", mdb_strerror(status)); - exit(1); + exit(EXIT_FAILURE); } status = mdb_cursor_open(txn, dbi, &cursor); if (status != MDB_SUCCESS) { fprintf(stderr, "named-nzd2nzf: mdb_cursor_open: %s", mdb_strerror(status)); - exit(1); + exit(EXIT_FAILURE); } for (status = mdb_cursor_get(cursor, &key, &data, MDB_FIRST); @@ -86,7 +86,7 @@ main(int argc, char *argv[]) { "named-nzd2nzf: empty column found in " "database '%s'", path); - exit(1); + exit(EXIT_FAILURE); } /* zone zonename { config; }; */ @@ -98,5 +98,6 @@ main(int argc, char *argv[]) { mdb_cursor_close(cursor); mdb_txn_abort(txn); mdb_env_close(env); - exit(0); + + return (0); } diff --git a/bin/tools/named-rrchecker.c b/bin/tools/named-rrchecker.c index 278a0a267d..e695805763 100644 --- a/bin/tools/named-rrchecker.c +++ b/bin/tools/named-rrchecker.c @@ -50,7 +50,7 @@ usage(void) { fprintf(stderr, "\t-P: list the supported private type names\n"); fprintf(stderr, "\t-T: list the supported standard type names\n"); fprintf(stderr, "\t-u: print the record in unknown record format\n"); - exit(0); + exit(EXIT_SUCCESS); } static void @@ -126,7 +126,7 @@ main(int argc, char *argv[]) { fprintf(stdout, "%s\n", text); } } - exit(0); + exit(EXIT_SUCCESS); case 'P': for (t = 0xff00; t <= 0xfffeu; t++) { @@ -162,11 +162,11 @@ main(int argc, char *argv[]) { default: fprintf(stderr, "%s: unhandled option -%c\n", argv[0], isc_commandline_option); - exit(1); + exit(EXIT_FAILURE); } } if (doexit) { - exit(0); + exit(EXIT_SUCCESS); } isc_mem_create(&mctx); diff --git a/bin/tools/nsec3hash.c b/bin/tools/nsec3hash.c index e76f7be025..2f0119d2e9 100644 --- a/bin/tools/nsec3hash.c +++ b/bin/tools/nsec3hash.c @@ -64,7 +64,7 @@ usage(void) { program); fprintf(stderr, " %s -r algorithm flags iterations salt domain\n", program); - exit(1); + exit(EXIT_FAILURE); } typedef void diff --git a/doc/misc/cfg_test.c b/doc/misc/cfg_test.c index d5f36549e2..ff86177414 100644 --- a/doc/misc/cfg_test.c +++ b/doc/misc/cfg_test.c @@ -39,7 +39,7 @@ check_result(isc_result_t result, const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, ": %s\n", isc_result_totext(result)); - exit(1); + exit(EXIT_FAILURE); } static void @@ -53,7 +53,7 @@ usage(void) { fprintf(stderr, "usage: cfg_test --rndc|--named " "[--grammar] [--zonegrammar] [--active] " "[--memstats] conffile\n"); - exit(1); + exit(EXIT_FAILURE); } int @@ -169,7 +169,7 @@ main(int argc, char **argv) { fprintf(stderr, "read config: %s\n", isc_result_totext(result)); if (result != ISC_R_SUCCESS) { - exit(1); + exit(EXIT_FAILURE); } cfg_print(cfg, output, NULL); @@ -189,7 +189,7 @@ main(int argc, char **argv) { if (ferror(stdout)) { fprintf(stderr, "write error\n"); return (1); - } else { - return (0); } + + return (0); } diff --git a/lib/dns/gen.c b/lib/dns/gen.c index 7cbdf0a6c2..d73557e1cb 100644 --- a/lib/dns/gen.c +++ b/lib/dns/gen.c @@ -204,7 +204,7 @@ next_file(isc_dir_t *dir) { fprintf(stderr, "Error: reading directory: %s\n", strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } } } @@ -363,7 +363,7 @@ insert_into_typenames(int type, const char *typebuf, const char *attr) { fprintf(stderr, "Error: type %d has two names: %s, %s\n", type, typenames[i].typebuf, typebuf); - exit(1); + exit(EXIT_FAILURE); } if (typenames[i].typebuf[0] == 0 && ttn == NULL) { ttn = &typenames[i]; @@ -371,13 +371,13 @@ insert_into_typenames(int type, const char *typebuf, const char *attr) { } if (ttn == NULL) { fprintf(stderr, "Error: typenames array too small\n"); - exit(1); + exit(EXIT_FAILURE); } /* XXXMUKS: This is redundant due to the INSIST above. */ if (strlen(typebuf) > sizeof(ttn->typebuf) - 1) { fprintf(stderr, "Error: type name %s is too long\n", typebuf); - exit(1); + exit(EXIT_FAILURE); } strncpy(ttn->typebuf, typebuf, sizeof(ttn->typebuf)); @@ -407,13 +407,13 @@ insert_into_typenames(int type, const char *typebuf, const char *attr) { "Error: type %d has different attributes: " "%s, %s\n", type, ttn->attr, attr); - exit(1); + exit(EXIT_FAILURE); } if (strlen(attr) > sizeof(ttn->attr) - 1) { fprintf(stderr, "Error: attr (%s) [name %s] is too long\n", attr, typebuf); - exit(1); + exit(EXIT_FAILURE); } strncpy(ttn->attr, attr, sizeof(ttn->attr)); @@ -441,7 +441,7 @@ add(unsigned int rdclass, const char *classbuf, int type, const char *typebuf, if (newtt == NULL) { fprintf(stderr, "malloc() failed\n"); - exit(1); + exit(EXIT_FAILURE); } newtt->next = NULL; @@ -470,14 +470,14 @@ add(unsigned int rdclass, const char *classbuf, int type, const char *typebuf, while ((tt != NULL) && (tt->type == type) && (tt->rdclass < rdclass)) { if (strcmp(tt->typebuf, typebuf) != 0) { - exit(1); + exit(EXIT_FAILURE); } oldtt = tt; tt = tt->next; } if ((tt != NULL) && (tt->type == type) && (tt->rdclass == rdclass)) { - exit(1); + exit(EXIT_FAILURE); } newtt->next = tt; @@ -497,7 +497,7 @@ add(unsigned int rdclass, const char *classbuf, int type, const char *typebuf, newcc = (struct cc *)malloc(sizeof(*newcc)); if (newcc == NULL) { fprintf(stderr, "malloc() failed\n"); - exit(1); + exit(EXIT_FAILURE); } newcc->rdclass = rdclass; strncpy(newcc->classbuf, classbuf, sizeof(newcc->classbuf)); @@ -555,7 +555,7 @@ sd(unsigned int rdclass, const char *classbuf, const char *dirbuf, if (type > 65535) { fprintf(stderr, "Error: type value > 65535 (%s)\n", dir.filename); - exit(1); + exit(EXIT_FAILURE); } add(rdclass, classbuf, type, typebuf, dirbuf); } @@ -571,7 +571,7 @@ HASH(char *string) { n = strlen(string); if (n == 0) { fprintf(stderr, "n == 0?\n"); - exit(1); + exit(EXIT_FAILURE); } a = tolower((unsigned char)string[0]); b = tolower((unsigned char)string[n - 1]); @@ -654,7 +654,7 @@ main(int argc, char **argv) { sizeof("/rdata/_65535_65535")) { fprintf(stderr, "\"%s\" too long\n", optarg); - exit(1); + exit(EXIT_FAILURE); } n = snprintf(srcdir, sizeof(srcdir), "%s/", optarg); INSIST(n > 0 && (unsigned)n < sizeof(srcdir)); @@ -669,7 +669,7 @@ main(int argc, char **argv) { suffix = optarg; break; case '?': - exit(1); + exit(EXIT_FAILURE); } } @@ -677,7 +677,7 @@ main(int argc, char **argv) { INSIST(n > 0 && (unsigned)n < sizeof(srcdir)); if (!start_directory(buf, &dir)) { - exit(1); + exit(EXIT_FAILURE); } while (next_file(&dir)) { @@ -700,7 +700,7 @@ main(int argc, char **argv) { if (rdclass > 65535) { fprintf(stderr, "Error: class value > 65535 (%s)\n", dir.filename); - exit(1); + exit(EXIT_FAILURE); } sd(rdclass, classbuf, buf, filetype); } @@ -1055,7 +1055,7 @@ main(int argc, char **argv) { } if (ferror(stdout) != 0) { - exit(1); + exit(EXIT_FAILURE); } return (0); diff --git a/lib/dns/openssl_link.c b/lib/dns/openssl_link.c index addf16ad98..09625b8d17 100644 --- a/lib/dns/openssl_link.c +++ b/lib/dns/openssl_link.c @@ -63,7 +63,7 @@ enable_fips_mode(void) { if (FIPS_mode_set(1) == 0) { dst__openssl_toresult2("FIPS_mode_set", DST_R_OPENSSLFAILURE); - exit(1); + exit(EXIT_FAILURE); } #endif /* HAVE_FIPS_MODE */ } diff --git a/lib/isc/app.c b/lib/isc/app.c index da438d72a5..6a60b36fdb 100644 --- a/lib/isc/app.c +++ b/lib/isc/app.c @@ -260,7 +260,7 @@ isc_app_ctxrun(isc_appctx_t *ctx) { if (atomic_load_acquire(&ctx->want_shutdown) && atomic_load_acquire(&ctx->blocked)) { - exit(1); + exit(EXIT_FAILURE); } }