Commit | Line | Data |
---|---|---|
60cd0afa ES |
1 | /* Copyright (c) 1979 Regents of the University of California */ |
2 | # include <stdio.h> | |
3 | # include "mach.h" | |
4 | # include "Paths.h" | |
5 | /* | |
6 | * this is a simple program to start up the net daemon, | |
7 | * and when it fails, restart it | |
8 | * | |
9 | * | |
10 | */ | |
11 | static int daemon = 32767; /* a nice safe process number */ | |
12 | main(argc,argv) | |
13 | char **argv; { | |
14 | char *s; | |
15 | int i,r,killit(); | |
16 | if(fork() != 0)exit(0); | |
17 | submit(getpid()); | |
18 | signal(SIGQUIT,SIG_IGN); | |
19 | signal(SIGHUP,SIG_IGN); | |
20 | signal(SIGINT,SIG_IGN); | |
21 | signal(SIGTERM,killit); | |
22 | s = argc == 1 ? 0 : argv[1]; | |
23 | for(;;){ | |
24 | while((daemon=fork()) == -1)sleep(2); | |
25 | if(daemon == 0){ | |
26 | execl(NETDAEMON,"netdaemon",s,0); | |
27 | exit(1); | |
28 | } | |
29 | wait(&r); | |
30 | sleep(100); /* avoid looping too fast */ | |
31 | } | |
32 | } | |
33 | killit(){ | |
34 | kill(daemon,SIGTERM); /* send terminate */ | |
35 | sleep(2); /* wait till cleanup */ | |
36 | kill(daemon,SIGKILL); /* kill in case too */ | |
37 | exit(0); | |
38 | } |