1: # include "defs.h"
2: /*
3: * this is a simple program to start up the net daemon,
4: * and when it fails, restart it
5: *
6: */
7: static int daemon = 32767; /* a nice safe process number */
8: main(argc,argv)
9: char **argv; {
10: int r,killit(),pid;
11: while((pid = fork()) == -1)sleep(2);
12: if(pid != 0)exit(EX_OK);
13: submit(getpid());
14: signal(SIGQUIT,SIG_IGN);
15: signal(SIGHUP,SIG_IGN);
16: signal(SIGINT,SIG_IGN);
17: signal(SIGTERM,killit);
18: /* will set remote */
19: parseargs(argc,argv);
20: addtolog(remote,"Netstart started, process id #%d\n",getpid());
21: for(;;){
22: while((daemon=fork()) == -1)sleep(2);
23: if(daemon == 0){
24: argv[0] = "netdaemon";
25: argv[argc] = 0;
26: execv(NETDAEMON,argv);
27: exit(EX_UNAVAILABLE);
28: }
29: wait(&r);
30: addtolog(remote,"Net daemon exit code %d, low byte 0%o\n",
31: (r>>8), (r&0377));
32: sleep(100); /* avoid looping too fast */
33: }
34: }
35: killit(){
36: kill(daemon,SIGTERM); /* send terminate */
37: sleep(2); /* wait till cleanup */
38: kill(daemon,SIGKILL); /* kill in case too */
39: exit(EX_OK);
40: }
41: /* add to allow netstart.c to load */
42: initseqno(){};
Defined functions
main
defined in line
8;
never used
Defined variables
daemon
defined in line
7; used 4 times