aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/signal.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 05:51:53 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 05:54:22 +0200
commit1de2aaa4001eb2d0ddfc4f86ab2c2a3eebdc9841 (patch)
tree85b0290fd51c220a9a621e98c0b88d92ce776e33 /src/signal.c
parentworker: capture process output (diff)
downloadcimple-1de2aaa4001eb2d0ddfc4f86ab2c2a3eebdc9841.tar.gz
cimple-1de2aaa4001eb2d0ddfc4f86ab2c2a3eebdc9841.zip
worker: allow graceful shutdowns
Well, maybe "graceful" is a strong word, but now you _can_ do ./server & ./worker & ./client ci_run URL REV && kill "$( pidof worker )" and the worker will wait for the CI run to complete.
Diffstat (limited to '')
-rw-r--r--src/signal.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/signal.c b/src/signal.c
new file mode 100644
index 0000000..fc4ac8b
--- /dev/null
+++ b/src/signal.c
@@ -0,0 +1,23 @@
+#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)
+{
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGINT);
+ sigaddset(&set, SIGQUIT);
+ sigaddset(&set, SIGTERM);
+
+ if (pthread_attr_setsigmask_np(attr, &set)) {
+ print_errno("pthread_attr_setsigmask_np");
+ return -1;
+ }
+
+ return 0;
+}