extract SIGSEGV handler

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Andrew Gregory 2015-11-12 18:56:26 -05:00 committed by Allan McRae
parent c74495a3b2
commit 8089081ef9
3 changed files with 29 additions and 17 deletions

View File

@ -1091,6 +1091,7 @@ int main(int argc, char *argv[])
size_t i;
uid_t myuid = getuid();
install_segv_handler();
install_signal_handlers();
/* i18n init */

View File

@ -44,23 +44,16 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
*/
static void handler(int signum)
{
if(signum == SIGSEGV) {
const char msg[] = "\nerror: segmentation fault\n"
"Please submit a full bug report with --debug if appropriate.\n";
if(signum == SIGINT) {
const char msg[] = "\nInterrupt signal received\n";
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
exit(signum);
} else if(signum == SIGINT || signum == SIGHUP) {
if(signum == SIGINT) {
const char msg[] = "\nInterrupt signal received\n";
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
} else {
const char msg[] = "\nHangup signal received\n";
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
}
if(alpm_trans_interrupt(config->handle) == 0) {
/* a transaction is being interrupted, don't exit pacman yet. */
return;
}
} else {
const char msg[] = "\nHangup signal received\n";
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
}
if(alpm_trans_interrupt(config->handle) == 0) {
/* a transaction is being interrupted, don't exit pacman yet. */
return;
}
/* SIGINT/SIGHUP: no committing transaction, release it now and then exit pacman */
alpm_unlock(config->handle);
@ -69,6 +62,23 @@ static void handler(int signum)
_Exit(128 + signum);
}
static void segv_handler(int signum)
{
const char msg[] = "\nerror: segmentation fault\n"
"Please submit a full bug report with --debug if appropriate.\n";
xwrite(STDERR_FILENO, msg, sizeof(msg) - 1);
_Exit(signum);
}
void install_segv_handler(void)
{
struct sigaction new_action;
new_action.sa_handler = segv_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = SA_RESTART;
sigaction(SIGSEGV, &new_action, NULL);
}
static void winch_handler(int signum)
{
(void)signum; /* suppress unused variable warnings */
@ -87,7 +97,7 @@ void install_winch_handler(void)
void install_signal_handlers(void)
{
struct sigaction new_action;
const int signals[] = { SIGHUP, SIGINT, SIGSEGV };
const int signals[] = { SIGHUP, SIGINT };
size_t i;
/* Set signal handlers */

View File

@ -20,6 +20,7 @@
#ifndef _PM_SIGHANDLER_H
#define _PM_SIGHANDLER_H
void install_segv_handler(void);
void install_winch_handler(void);
void install_signal_handlers(void);