[pacman-dev] [PATCH 08/11] extract SIGWINCH handler
Andrew Gregory
andrew.gregory.8 at gmail.com
Fri Dec 4 20:31:39 UTC 2015
Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
src/pacman/pacman.c | 5 ++++-
src/pacman/sighandler.c | 21 +++++++++++++++++----
src/pacman/sighandler.h | 1 +
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 0f115c2..e1f9039 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -1107,9 +1107,12 @@ int main(int argc, char *argv[])
cleanup(1);
}
- /* disable progressbar if the output is redirected */
if(!isatty(fileno(stdout))) {
+ /* disable progressbar if the output is redirected */
config->noprogressbar = 1;
+ } else {
+ /* install signal handler to update output width */
+ install_winch_handler();
}
/* Priority of options:
diff --git a/src/pacman/sighandler.c b/src/pacman/sighandler.c
index d488ece..76f7e9d 100644
--- a/src/pacman/sighandler.c
+++ b/src/pacman/sighandler.c
@@ -61,9 +61,6 @@ static void handler(int signum)
/* a transaction is being interrupted, don't exit pacman yet. */
return;
}
- } else if(signum == SIGWINCH) {
- columns_cache_reset();
- return;
}
/* SIGINT/SIGHUP: no committing transaction, release it now and then exit pacman */
alpm_unlock(config->handle);
@@ -72,11 +69,27 @@ static void handler(int signum)
_Exit(128 + signum);
}
+static void winch_handler(int signum)
+{
+ (void)signum; /* suppress unused variable warnings */
+ columns_cache_reset();
+}
+
+void install_winch_handler(void)
+{
+ struct sigaction new_action;
+ new_action.sa_handler = winch_handler;
+ sigemptyset(&new_action.sa_mask);
+ new_action.sa_flags = SA_RESTART;
+ sigaction(SIGWINCH, &new_action, NULL);
+}
+
void install_signal_handlers(void)
{
struct sigaction new_action;
- const int signals[] = { SIGHUP, SIGINT, SIGSEGV, SIGWINCH };
+ const int signals[] = { SIGHUP, SIGINT, SIGSEGV };
size_t i;
+
/* Set signal handlers */
/* Set up the structure to specify the new action. */
new_action.sa_handler = handler;
diff --git a/src/pacman/sighandler.h b/src/pacman/sighandler.h
index f7abc9e..bcf7d88 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_winch_handler(void);
void install_signal_handlers(void);
#endif /* _PM_SIGHANDLER_H */
--
2.6.3
More information about the pacman-dev
mailing list