]> pd.if.org Git - startuptools/blob - monitor.c
fix empty module list handling
[startuptools] / monitor.c
1 /*
2  * daemonize and exec
3  */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7
8 #include <sys/types.h>
9 #include <sys/stat.h>
10
11 #include <unistd.h>
12
13 #include "exec.c"
14
15 int main(int ac, char *av[]) {
16         pid_t child = 0;
17
18         /* create the child */
19         child = fork();
20         if (child < 0) {
21                 fprintf(stderr, "fork fail!\n");
22                 exit(EXIT_FAILURE);
23         }
24
25         /* parent, actually does the monitoring */
26         if (child > 0) {
27                 exit(EXIT_SUCCESS);
28         }
29
30         pid = fork();
31         if (pid < 0) {
32                 fprintf(stderr, "fork fail!\n");
33                 exit(EXIT_FAILURE);
34         }
35         if (pid > 0) {
36                 /* fprintf(stderr, "pid = %d\n", pid); */
37                 exit(EXIT_SUCCESS);
38         }
39
40         if (chdir("/") < 0) {
41                 exit(EXIT_FAILURE);
42         }
43
44         do_exec(1, ac, av);
45
46         /* shouldn't get here... */
47         return EXIT_FAILURE;
48 }