summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pacman/pacman.c3
-rw-r--r--src/pacman/sighandler.c34
-rw-r--r--src/pacman/sighandler.h2
3 files changed, 17 insertions, 22 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 6a0eb97d..4237b4d4 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -1092,7 +1092,6 @@ int main(int argc, char *argv[])
uid_t myuid = getuid();
install_segv_handler();
- install_signal_handlers();
/* i18n init */
#if defined(ENABLE_NLS)
@@ -1108,6 +1107,8 @@ int main(int argc, char *argv[])
cleanup(1);
}
+ install_soft_interrupt_handler();
+
if(!isatty(fileno(stdout))) {
/* disable progressbar if the output is redirected */
config->noprogressbar = 1;
diff --git a/src/pacman/sighandler.c b/src/pacman/sighandler.c
index 36f87d78..e88375aa 100644
--- a/src/pacman/sighandler.c
+++ b/src/pacman/sighandler.c
@@ -42,7 +42,7 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
* in a consistent state.
* @param signum the thrown signal
*/
-static void handler(int signum)
+static void soft_interrupt_handler(int signum)
{
if(signum == SIGINT) {
const char msg[] = "\nInterrupt signal received\n";
@@ -55,13 +55,25 @@ static void handler(int signum)
/* 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);
/* output a newline to be sure we clear any line we may be on */
xwrite(STDOUT_FILENO, "\n", 1);
_Exit(128 + signum);
}
+void install_soft_interrupt_handler(void)
+{
+ struct sigaction new_action;
+ new_action.sa_handler = soft_interrupt_handler;
+ new_action.sa_flags = SA_RESTART;
+ sigemptyset(&new_action.sa_mask);
+ sigaddset(&new_action.sa_mask, SIGINT);
+ sigaddset(&new_action.sa_mask, SIGHUP);
+
+ sigaction(SIGINT, &new_action, NULL);
+ sigaction(SIGHUP, &new_action, NULL);
+}
+
static void segv_handler(int signum)
{
const char msg[] = "\nerror: segmentation fault\n"
@@ -94,22 +106,4 @@ void install_winch_handler(void)
sigaction(SIGWINCH, &new_action, NULL);
}
-void install_signal_handlers(void)
-{
- struct sigaction new_action;
- const int signals[] = { SIGHUP, SIGINT };
- size_t i;
-
- /* Set signal handlers */
- /* Set up the structure to specify the new action. */
- new_action.sa_handler = handler;
- sigemptyset(&new_action.sa_mask);
- new_action.sa_flags = SA_RESTART;
-
- /* assign our handler to any signals we care about */
- for(i = 0; i < ARRAYSIZE(signals); i++) {
- sigaction(signals[i], &new_action, NULL);
- }
-}
-
/* vim: set noet: */
diff --git a/src/pacman/sighandler.h b/src/pacman/sighandler.h
index 037d54f5..51f347b6 100644
--- a/src/pacman/sighandler.h
+++ b/src/pacman/sighandler.h
@@ -22,7 +22,7 @@
void install_segv_handler(void);
void install_winch_handler(void);
-void install_signal_handlers(void);
+void install_soft_interrupt_handler(void);
#endif /* _PM_SIGHANDLER_H */