#include #include #include #include #include #include #include #include #include #include #include static void *thread_func(void *arg __attribute__ ((unused))) { while (1) { /* do nothing */ } return NULL; } static void setup_main_signals(void) { pthread_t tid; struct sigaction sa; sigset_t *s = malloc(sizeof(*s)); if (!s) { perror("malloc"); exit(1); } sigfillset(s); pthread_sigmask(SIG_SETMASK, s, NULL); memset(&sa, 0, sizeof(sa)); sigfillset(&sa.sa_mask); sa.sa_handler = SIG_IGN; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); sigemptyset(s); sigaddset(s, SIGINT); sigaddset(s, SIGTERM); sigaddset(s, SIGHUP); sigaddset(s, SIGQUIT); pthread_sigmask(SIG_SETMASK, s, NULL); if (pthread_create(&tid, NULL, thread_func, s) < 0) { perror("pthread_create"); exit(1); } } void cleanup_and_exit(void) { const char *test1 = "./test1"; fprintf(stderr, "cleanup and exit\n"); if (execlp(test1, basename (test1), "-d", NULL) < 0) { perror(test1); _exit(1); } _exit(0); } int main(int argc __attribute__ ((unused)), char **argv) { char *prog = argv[0]; fprintf(stderr, "%s: uid = %d, euid = %d\n", prog, (int)getuid(), (int)geteuid()); setup_main_signals(); cleanup_and_exit(); return 0; }