Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit ec18947

Browse files
committed
Add a signal handler for SIGHUB, SIGINT, and SIGTERM
If nothing else, just to be able to test the cleanup of the pidfile... Signed-off-by: Jan Dubois <[email protected]>
1 parent 81f2eb3 commit ec18947

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

main.c

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <assert.h>
2+
#include <setjmp.h>
23
#include <stdio.h>
34
#include <stdlib.h>
45
#include <sys/uio.h>
@@ -215,6 +216,12 @@ static interface_ref start(VDECONN *vdeconn, struct cli_options *cliopt) {
215216
return iface;
216217
}
217218

219+
static sigjmp_buf jmpbuf;
220+
static void signalhandler(int signal) {
221+
printf("\nReceived signal %d\n", signal);
222+
siglongjmp(jmpbuf, 1);
223+
}
224+
218225
static void stop(interface_ref iface) {
219226
if (iface == NULL) {
220227
return;
@@ -249,6 +256,14 @@ int main(int argc, char *argv[]) {
249256
fprintf(stderr, "WARNING: Seems running with SETUID. This is insecure and "
250257
"highly discouraged. See README.md .\n");
251258
}
259+
260+
if (sigsetjmp(jmpbuf, 1) != 0) {
261+
goto done;
262+
}
263+
signal(SIGHUP, signalhandler);
264+
signal(SIGINT, signalhandler);
265+
signal(SIGTERM, signalhandler);
266+
252267
int pid_fd = -1;
253268
if (cliopt->pidfile != NULL) {
254269
pid_fd = open(cliopt->pidfile, O_WRONLY | O_CREAT | O_EXLOCK | O_TRUNC | O_NONBLOCK, 0644);

0 commit comments

Comments
 (0)