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.
This commit is contained in:
Ondřej Surý 2024-02-07 14:44:39 +01:00
parent 4e2e2a13b7
commit 4bec711fe3
No known key found for this signature in database
GPG key ID: 2820F37E873DEA41
13 changed files with 48 additions and 39 deletions

View file

@ -79,7 +79,7 @@ usage(void) {
"%s zonename [ (filename|-) ]\n",
prog_name,
progmode == progmode_check ? "[-o filename]" : "-o filename");
exit(1);
exit(EXIT_FAILURE);
}
static void
@ -206,7 +206,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -i: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -240,7 +240,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -k: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -251,7 +251,7 @@ main(int argc, char **argv) {
if (*endp != '\0') {
fprintf(stderr, "source serial number "
"must be numeric");
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -262,7 +262,7 @@ main(int argc, char **argv) {
if (*endp != '\0') {
fprintf(stderr, "maximum TTL "
"must be numeric");
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -279,7 +279,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -n: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -296,7 +296,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -m: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -321,7 +321,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -r: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -334,7 +334,7 @@ main(int argc, char **argv) {
fprintf(stderr,
"unknown or unsupported style: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -344,7 +344,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;
@ -364,7 +364,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -C: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -385,7 +385,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -M: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -402,7 +402,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -S: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -414,7 +414,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "invalid argument to -T: %s\n",
isc_commandline_argument);
exit(1);
exit(EXIT_FAILURE);
}
break;
@ -438,7 +438,7 @@ main(int argc, char **argv) {
default:
fprintf(stderr, "%s: unhandled option -%c\n", prog_name,
isc_commandline_option);
exit(1);
exit(EXIT_FAILURE);
}
}
@ -447,7 +447,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);
}
}
@ -463,7 +463,7 @@ main(int argc, char **argv) {
} else {
fprintf(stderr, "unknown file format: %s\n",
inputformatstr);
exit(1);
exit(EXIT_FAILURE);
}
}
@ -481,12 +481,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);
}
}

View file

@ -13,14 +13,16 @@
/*! \file */
#include "util.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/tls.h>
#include "util.h"
extern bool verbose;
extern const char *progname;
@ -46,5 +48,5 @@ fatal(const char *format, ...) {
va_end(args);
fprintf(stderr, "\n");
isc__tls_setfatalmode();
exit(1);
_exit(EXIT_FAILURE);
}

View file

@ -264,7 +264,7 @@ fatal(const char *format, ...) {
va_end(args);
fprintf(stderr, "\n");
isc__tls_setfatalmode();
exit(1);
_exit(EXIT_FAILURE);
}
static void

View file

@ -359,8 +359,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, ...) {
@ -393,10 +391,7 @@ digexit(void) {
exitcode = 10;
}
if (fatalexit != 0) {
exitcode = fatalexit;
}
if (dighost_pre_exit_hook != NULL) {
dighost_pre_exit_hook();
_exit(fatalexit);
}
exit(exitcode);
}
@ -412,6 +407,11 @@ fatal(const char *format, ...) {
va_end(args);
fprintf(stderr, "\n");
isc__tls_setfatalmode();
if (fatalexit == 0 && exitcode != 0) {
fatalexit = exitcode;
} else if (fatalexit == 0) {
fatalexit = EXIT_FAILURE;
}
digexit();
}

View file

@ -20,6 +20,7 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/base32.h>
#include <isc/buffer.h>
@ -84,7 +85,9 @@ fatal(const char *format, ...) {
(*fatalcallback)();
}
isc__tls_setfatalmode();
exit(1);
/* Make sure that various atexit() calls are skipped */
_exit(EXIT_FAILURE);
}
void

View file

@ -194,7 +194,7 @@ named_main_earlyfatal(const char *format, ...) {
}
va_end(args);
exit(1);
_exit(EXIT_FAILURE);
}
noreturn static void
@ -233,7 +233,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
@ -273,7 +273,7 @@ library_fatal_error(const char *file, int line, const char *func,
if (named_g_coreok) {
abort();
}
exit(1);
_exit(EXIT_FAILURE);
}
static void

View file

@ -10204,7 +10204,7 @@ fatal(const char *msg, isc_result_t result) {
"exiting (due to fatal error)");
named_os_shutdown();
isc__tls_setfatalmode();
exit(1);
_exit(EXIT_FAILURE);
}
static isc_result_t

View file

@ -280,7 +280,7 @@ fatal(const char *format, ...) {
va_end(args);
fprintf(stderr, "\n");
isc__tls_setfatalmode();
exit(1);
_exit(EXIT_FAILURE);
}
static void

View file

@ -18,6 +18,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/tls.h>
@ -46,5 +47,5 @@ fatal(const char *format, ...) {
va_end(args);
fprintf(stderr, "\n");
isc__tls_setfatalmode();
exit(1);
_exit(EXIT_FAILURE);
}

View file

@ -32,6 +32,7 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <protobuf-c/protobuf-c.h>
@ -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

View file

@ -898,7 +898,7 @@ fatal(const char *format, ...) {
va_end(args);
fprintf(stderr, "\n");
isc__tls_setfatalmode();
exit(-2);
_exit(EXIT_FAILURE);
}
static isc_result_t

View file

@ -13,6 +13,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/attributes.h>
#include <isc/buffer.h>
@ -75,7 +76,7 @@ fatal(const char *format, ...) {
va_end(args);
fputc('\n', stderr);
cleanup();
exit(1);
_exit(EXIT_FAILURE);
}
int

View file

@ -14,6 +14,7 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <isc/attributes.h>
#include <isc/base32.h>
@ -48,7 +49,7 @@ fatal(const char *format, ...) {
va_end(args);
fprintf(stderr, "\n");
isc__tls_setfatalmode();
exit(1);
_exit(1);
}
static void