confirm results
[tridge/junkcode.git] / setuid_signal.c
1 /*
2   test program to demonstrate use of signals with setreuid() and setresuid()
3
4   tridge@samba.org August 2008
5  */
6
7 #define _XOPEN_SOURCE 500
8 #define _GNU_SOURCE 
9
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <stdlib.h>
13 #include <errno.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <string.h>
17 #include <getopt.h>
18 #include <signal.h>
19 #include <utime.h>
20 #include <stdbool.h>
21 #include <sys/time.h>
22 #include <sys/wait.h>
23 #include <time.h>
24 #include <aio.h>
25
26
27 static void sig_handler(int signum)
28 {
29         printf("Got signal %d\n", signum);
30 }
31
32 int main(int argc, const char *argv[])
33 {
34         signal(SIGUSR1, sig_handler);
35         signal(SIGUSR2, sig_handler);
36         alarm(5);
37
38         if (fork() == 0) {
39                 setreuid(-1, 1);
40                 sleep(1);
41                 kill(getppid(), SIGUSR1);
42                 sleep(1);
43                 setreuid(-1, 0);
44                 setresuid(1, 1, -1);
45                 kill(getppid(), SIGUSR2);
46         }
47
48         pause();
49         pause();
50
51         return 0;
52 }