69c5277a944f5d384de04882b457f15167002484
[citadel.git] / webcit / ctdlsvc.c
1 /*
2  * $Id: $
3  *
4  * This is just a quick little hack to start a program and automatically
5  * restart it if it exits with a nonzero exit status.
6  *
7  */
8
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <sys/types.h>
13 #include <sys/wait.h>
14 #include <errno.h>
15
16
17 int main(int argc, char **argv)
18 {
19         pid_t child = 0;
20         int status = 0;
21
22         --argc;
23         ++argv;
24
25         do {
26                 child = fork();
27         
28                 if (child < 0) {
29                         perror("fork");
30                         exit(errno);
31                 }
32         
33                 else if (child == 0) {
34                         exit(execvp(argv[0], &argv[0]));
35                 }
36         
37                 else {
38                         printf("%s: started.  pid = %d\n", argv[0], child);
39                         waitpid(child, &status, 0);
40                         printf("Exit code %d\n", status);
41                 }
42
43         } while (status != 0);
44
45         exit(0);
46 }
47