Skip to content

Commit

Permalink
Deal with _exit() not letting our destructor run.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 6, 2019
1 parent 6fd46e0 commit fc5d6a0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions altrace/altrace_record.c
Expand Up @@ -53,6 +53,15 @@ static ContextItem *current_context;

static void quit_altrace_record(void) __attribute__((destructor));

// override _exit(), which terminates the process without running library
// destructors, so we can close our log file, etc.
void _exit(int status)
{
quit_altrace_record();
_Exit(status); // just use _Exit(), which does the same thing but no one really uses. :P
}


NORETURN static void IO_WRITE_FAIL(void)
{
fprintf(stderr, APPNAME ": failed to write to log: %s\n", strerror(errno));
Expand Down

0 comments on commit fc5d6a0

Please sign in to comment.