diff options
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2015-11-12 18:56:26 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2015-12-05 18:10:06 +1000 |
commit | 8089081ef962337d9ff445213cdb160fc47da7c8 (patch) | |
tree | f5348c95c754e4b27f6b242b24fca0257aa51d3c /src/pacman | |
parent | c74495a3b217249e3a14d616b38367b6dbb006e4 (diff) |
extract SIGSEGV handler
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman')
-rw-r--r-- | src/pacman/pacman.c | 1 | ||||
-rw-r--r-- | src/pacman/sighandler.c | 44 | ||||
-rw-r--r-- | src/pacman/sighandler.h | 1 |
3 files changed, 29 insertions, 17 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index e1f90398..6a0eb97d 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -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 */ diff --git a/src/pacman/sighandler.c b/src/pacman/sighandler.c index 76f7e9d2..36f87d78 100644 --- a/src/pacman/sighandler.c +++ b/src/pacman/sighandler.c @@ -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 */ diff --git a/src/pacman/sighandler.h b/src/pacman/sighandler.h index bcf7d88a..037d54f5 100644 --- a/src/pacman/sighandler.h +++ b/src/pacman/sighandler.h @@ -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); |