Add compile option to disable internal handling of fatal signals

By default, charon and its derivatives internally handle the SIGSEGV,
SIGILL, and SIGBUS signals raised by threads (segv_handler).  Add a compile
option so that the signal handling can optionally be done externally.

Closes strongswan/strongswan#132.
This commit is contained in:
Sheena Mira-ato 2019-03-21 16:28:08 +13:00 committed by Tobias Brunner
parent 71141cc8c9
commit fe3ae5be5d
5 changed files with 46 additions and 11 deletions

View File

@ -174,6 +174,7 @@ static bool lookup_uid_gid()
return TRUE;
}
#ifndef DISABLE_SIGNAL_HANDLER
/**
* Handle SIGSEGV/SIGILL signals raised by threads
*/
@ -189,6 +190,7 @@ static void segv_handler(int signal)
DBG1(DBG_DMN, "killing ourself, received critical signal");
abort();
}
#endif /* DISABLE_SIGNAL_HANDLER */
/**
* Print command line usage and exit
@ -372,18 +374,23 @@ int main(int argc, char *argv[])
/* handle all arguments */
handle_arguments(argc, argv, FALSE);
/* add handler for SEGV and ILL,
* INT, TERM and HUP are handled by sigwaitinfo() in run() */
action.sa_handler = segv_handler;
/* add handler for fatal signals,
* INT, TERM, HUP and USR1 are handled by sigwaitinfo() in run() */
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGINT);
sigaddset(&action.sa_mask, SIGTERM);
sigaddset(&action.sa_mask, SIGHUP);
sigaddset(&action.sa_mask, SIGUSR1);
/* optionally let the external system handle fatal signals */
#ifndef DISABLE_SIGNAL_HANDLER
action.sa_handler = segv_handler;
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGBUS, &action, NULL);
#endif /* DISABLE_SIGNAL_HANDLER */
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);

View File

@ -109,6 +109,7 @@ static void run()
}
}
#ifndef DISABLE_SIGNAL_HANDLER
/**
* Handle SIGSEGV/SIGILL signals raised by threads
*/
@ -124,6 +125,7 @@ static void segv_handler(int signal)
DBG1(DBG_DMN, "killing ourself, received critical signal");
abort();
}
#endif /* DISABLE_SIGNAL_HANDLER */
/**
* Lookup UID and GID
@ -225,16 +227,21 @@ int main(int argc, char *argv[])
goto deinit;
}
/* add handler for SEGV and ILL,
/* add handler for fatal signals,
* INT and TERM are handled by sigwaitinfo() in run() */
action.sa_handler = segv_handler;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGINT);
sigaddset(&action.sa_mask, SIGTERM);
/* optionally let the external system handle fatal signals */
#ifndef DISABLE_SIGNAL_HANDLER
action.sa_handler = segv_handler;
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGBUS, &action, NULL);
#endif /* DISABLE_SIGNAL_HANDLER */
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);

View File

@ -281,6 +281,7 @@ static bool lookup_uid_gid()
return TRUE;
}
#ifndef DISABLE_SIGNAL_HANDLER
/**
* Handle SIGSEGV/SIGILL signals raised by threads
*/
@ -297,6 +298,7 @@ static void segv_handler(int signal)
DBG1(DBG_DMN, "killing ourself, received critical signal");
abort();
}
#endif /* DISABLE_SIGNAL_HANDLER */
/**
* Add namespace alias
@ -380,17 +382,22 @@ int main(int argc, char *argv[])
goto error;
}
/* add handler for SEGV and ILL,
/* add handler for fatal signals,
* INT, TERM and HUP are handled by sigwaitinfo() in run() */
action.sa_handler = segv_handler;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGINT);
sigaddset(&action.sa_mask, SIGTERM);
sigaddset(&action.sa_mask, SIGHUP);
/* optionally let the external system handle fatal signals */
#ifndef DISABLE_SIGNAL_HANDLER
action.sa_handler = segv_handler;
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGBUS, &action, NULL);
#endif /* DISABLE_SIGNAL_HANDLER */
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);

View File

@ -133,6 +133,7 @@ static void run()
}
}
#ifndef DISABLE_SIGNAL_HANDLER
/**
* Handle SIGSEGV/SIGILL signals raised by threads
*/
@ -148,6 +149,7 @@ static void segv_handler(int signal)
DBG1(DBG_DMN, "killing ourself, received critical signal");
abort();
}
#endif /* DISABLE_SIGNAL_HANDLER */
/**
* Lookup UID and GID
@ -372,16 +374,21 @@ int main(int argc, char *argv[])
/* register TKM credential encoder */
lib->encoding->add_encoder(lib->encoding, tkm_encoder_encode);
/* add handler for SEGV and ILL,
/* add handler for fatal signals,
* INT and TERM are handled by sigwaitinfo() in run() */
action.sa_handler = segv_handler;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGINT);
sigaddset(&action.sa_mask, SIGTERM);
/* optionally let the external system handle fatal signals */
#ifndef DISABLE_SIGNAL_HANDLER
action.sa_handler = segv_handler;
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGBUS, &action, NULL);
#endif /* DISABLE_SIGNAL_HANDLER */
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);

View File

@ -167,6 +167,7 @@ static bool lookup_uid_gid()
/**
* Handle SIGSEGV/SIGILL signals raised by threads
*/
#ifndef DISABLE_SIGNAL_HANDLER
static void segv_handler(int signal)
{
backtrace_t *backtrace;
@ -180,6 +181,7 @@ static void segv_handler(int signal)
DBG1(DBG_DMN, "killing ourself, received critical signal");
abort();
}
#endif /* DISABLE_SIGNAL_HANDLER */
/**
* Check/create PID file, return TRUE if already running
@ -438,17 +440,22 @@ int main(int argc, char *argv[])
goto deinit;
}
/* add handler for SEGV and ILL,
/* add handler for fatal signals,
* INT, TERM and HUP are handled by sigwaitinfo() in run() */
action.sa_handler = segv_handler;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGINT);
sigaddset(&action.sa_mask, SIGTERM);
sigaddset(&action.sa_mask, SIGHUP);
/* optionally let the external system handle fatal signals */
#ifndef DISABLE_SIGNAL_HANDLER
action.sa_handler = segv_handler;
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGILL, &action, NULL);
sigaction(SIGBUS, &action, NULL);
#endif /* DISABLE_SIGNAL_HANDLER */
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);