aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/signal.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-28 18:17:23 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-28 19:42:28 +0200
commit4835e38f6f2005073e06907021d91dde2f4d2d4f (patch)
tree76d62a95b2eb080d3f5b9e12663971ee6f96098d /src/signal.c
parentadd missing #include (diff)
downloadcimple-4835e38f6f2005073e06907021d91dde2f4d2d4f.tar.gz
cimple-4835e38f6f2005073e06907021d91dde2f4d2d4f.zip
don't use the latest glibc features
pthread_attr_setsigmask_np is only available since 2.32, which is too modern.
Diffstat (limited to '')
-rw-r--r--src/signal.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/signal.c b/src/signal.c
index a0b9c3d..c3ea7c3 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -1,26 +1,36 @@
#include "signal.h"
#include "log.h"
-#include <pthread.h>
#include <signal.h>
volatile sig_atomic_t global_stop_flag = 0;
-int signal_set_thread_attr(pthread_attr_t *attr)
+int signal_set(const sigset_t *new, sigset_t *old)
{
int ret = 0;
+ ret = sigprocmask(SIG_SETMASK, new, old);
+ if (ret < 0) {
+ print_errno("sigprocmask");
+ return ret;
+ }
+
+ return ret;
+}
+
+int signal_block_parent(sigset_t *old)
+{
+ sigset_t new;
+ sigfillset(&new);
+ return signal_set(&new, old);
+}
+
+int signal_block_child()
+{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGQUIT);
sigaddset(&set, SIGTERM);
-
- ret = pthread_attr_setsigmask_np(attr, &set);
- if (ret) {
- pthread_print_errno(ret, "pthread_attr_setsigmask_np");
- return ret;
- }
-
- return ret;
+ return signal_set(&set, NULL);
}