Add 'tools/arvbox/' from commit 'd3d368758db1f4a9fa5b89f77b5ee61d68ef5b72'
[arvados.git] / tools / arvbox / lib / arvbox / docker / runit-docker / runit-docker.c
1 #include <signal.h>
2 #include <dlfcn.h>
3 #include <stdlib.h>
4
5
6 int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
7 {
8   static int (*real_sigaction)(int signum, const struct sigaction *act, struct sigaction *oldact) = NULL;
9
10   // Retrieve the real sigaction we just shadowed.
11   if (real_sigaction == NULL) {
12     real_sigaction = (void *) dlsym(RTLD_NEXT, "sigaction");
13     // Prevent further shadowing in children.
14     unsetenv("LD_PRELOAD");
15   }
16
17   if (signum == SIGTERM) {
18     // Skip this handler, it doesn't do what we want.
19     return 0;
20   }
21
22   if (signum == SIGHUP) {
23     // Install this handler for others as well.
24     real_sigaction(SIGTERM, act, oldact);
25     real_sigaction(SIGINT, act, oldact);
26   }
27
28   // Forward the call the the real sigaction.
29   return real_sigaction(signum, act, oldact);
30 }
31
32 // vim: ts=2 sw=2 et