summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 5c1e16ab6e..47b1b443ff 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1735,14 +1735,59 @@ int release_terminal(void) {
return r;
}
-int ignore_signal(int sig) {
+int sigaction_many(const struct sigaction *sa, ...) {
+ va_list ap;
+ int r = 0, sig;
+
+ va_start(ap, sa);
+ while ((sig = va_arg(ap, int)) > 0)
+ if (sigaction(sig, sa, NULL) < 0)
+ r = -errno;
+ va_end(ap);
+
+ return r;
+}
+
+int ignore_signals(int sig, ...) {
struct sigaction sa;
+ va_list ap;
+ int r = 0;
zero(sa);
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
- return sigaction(sig, &sa, NULL);
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+
+ va_start(ap, sig);
+ while ((sig = va_arg(ap, int)) > 0)
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+ va_end(ap);
+
+ return r;
+}
+
+int default_signals(int sig, ...) {
+ struct sigaction sa;
+ va_list ap;
+ int r = 0;
+
+ zero(sa);
+ sa.sa_handler = SIG_DFL;
+ sa.sa_flags = SA_RESTART;
+
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+
+ va_start(ap, sig);
+ while ((sig = va_arg(ap, int)) > 0)
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+ va_end(ap);
+
+ return r;
}
int close_pipe(int p[]) {