diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-26 05:51:53 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-26 05:54:22 +0200 |
commit | 1de2aaa4001eb2d0ddfc4f86ab2c2a3eebdc9841 (patch) | |
tree | 85b0290fd51c220a9a621e98c0b88d92ce776e33 /src/signal.h | |
parent | worker: capture process output (diff) | |
download | cimple-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 'src/signal.h')
-rw-r--r-- | src/signal.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/signal.h b/src/signal.h new file mode 100644 index 0000000..ac6da9d --- /dev/null +++ b/src/signal.h @@ -0,0 +1,28 @@ +#ifndef __SIGNAL_H__ +#define __SIGNAL_H__ + +#include <pthread.h> +#include <signal.h> +#include <string.h> + +extern volatile sig_atomic_t global_stop_flag; + +static void signal_handler(int) +{ + global_stop_flag = 1; +} + +static __attribute__((constructor)) void signal_handler_install() +{ + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = signal_handler; + + sigaction(SIGINT, &sa, NULL); + sigaction(SIGQUIT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); +} + +int signal_set_thread_attr(pthread_attr_t *attr); + +#endif |