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:
parent
c74495a3b2
commit
8089081ef9
|
@ -1091,6 +1091,7 @@ int main(int argc, char *argv[])
|
||||||
size_t i;
|
size_t i;
|
||||||
uid_t myuid = getuid();
|
uid_t myuid = getuid();
|
||||||
|
|
||||||
|
install_segv_handler();
|
||||||
install_signal_handlers();
|
install_signal_handlers();
|
||||||
|
|
||||||
/* i18n init */
|
/* i18n init */
|
||||||
|
|
|
@ -44,23 +44,16 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
|
||||||
*/
|
*/
|
||||||
static void handler(int signum)
|
static void handler(int signum)
|
||||||
{
|
{
|
||||||
if(signum == SIGSEGV) {
|
if(signum == SIGINT) {
|
||||||
const char msg[] = "\nerror: segmentation fault\n"
|
const char msg[] = "\nInterrupt signal received\n";
|
||||||
"Please submit a full bug report with --debug if appropriate.\n";
|
|
||||||
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
|
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
|
||||||
exit(signum);
|
} else {
|
||||||
} else if(signum == SIGINT || signum == SIGHUP) {
|
const char msg[] = "\nHangup signal received\n";
|
||||||
if(signum == SIGINT) {
|
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
|
||||||
const char msg[] = "\nInterrupt signal received\n";
|
}
|
||||||
xwrite(STDERR_FILENO, msg, ARRAYSIZE(msg) - 1);
|
if(alpm_trans_interrupt(config->handle) == 0) {
|
||||||
} else {
|
/* a transaction is being interrupted, don't exit pacman yet. */
|
||||||
const char msg[] = "\nHangup signal received\n";
|
return;
|
||||||
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 */
|
/* SIGINT/SIGHUP: no committing transaction, release it now and then exit pacman */
|
||||||
alpm_unlock(config->handle);
|
alpm_unlock(config->handle);
|
||||||
|
@ -69,6 +62,23 @@ static void handler(int signum)
|
||||||
_Exit(128 + 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)
|
static void winch_handler(int signum)
|
||||||
{
|
{
|
||||||
(void)signum; /* suppress unused variable warnings */
|
(void)signum; /* suppress unused variable warnings */
|
||||||
|
@ -87,7 +97,7 @@ void install_winch_handler(void)
|
||||||
void install_signal_handlers(void)
|
void install_signal_handlers(void)
|
||||||
{
|
{
|
||||||
struct sigaction new_action;
|
struct sigaction new_action;
|
||||||
const int signals[] = { SIGHUP, SIGINT, SIGSEGV };
|
const int signals[] = { SIGHUP, SIGINT };
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* Set signal handlers */
|
/* Set signal handlers */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#ifndef _PM_SIGHANDLER_H
|
#ifndef _PM_SIGHANDLER_H
|
||||||
#define _PM_SIGHANDLER_H
|
#define _PM_SIGHANDLER_H
|
||||||
|
|
||||||
|
void install_segv_handler(void);
|
||||||
void install_winch_handler(void);
|
void install_winch_handler(void);
|
||||||
void install_signal_handlers(void);
|
void install_signal_handlers(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue