-
Notifications
You must be signed in to change notification settings - Fork 0
/
g_boot.c
executable file
·74 lines (60 loc) · 1.77 KB
/
g_boot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*-----------------------------------------*
g_boot.c
coded by H.B. Lee
Feb/2007
Revisoned May/2009
*-----------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/wait.h>
#include "g_macros.h"
#include "g_config.h"
char *av[3];
main(int ac, char *av[])
{
FILE *lp;
int st;
time_t ct;
lp = fopen("/tmp/mb3/Eboot.log", "a");
//lp = fopen("./Eboot.log", "a");
//lp = fopen(Log_file_nam2, "a");
av[0] = "Egtwy";
av[1] = NULL;
time(&ct);
if(lp)
fprintf(lp, "Gateway starts at %s", ctime(&ct));
for( ; ; ) {
sleep(3);
if (fork() > 0) { /* parent */
wait(&st);
time(&ct);
if(WIFEXITED(st)) {
D02("Gateway restarts(exit status=%d) at %s", WEXITSTATUS(st), ctime(&ct));
if(lp)
fprintf(lp, "Gateway restarts(exit status=%d) at %s", WEXITSTATUS(st), ctime(&ct));
}
else if(WIFSIGNALED(st)) {
D02("Gateway restarts(signal=%d) at %s", WTERMSIG(st), ctime(&ct));
if(lp)
fprintf(lp, "Gateway restarts(signal=%d) at %s", WTERMSIG(st), ctime(&ct));
}
else {
D01("Gateway restarts(cause unknown) at %s", ctime(&ct));
if(lp)
fprintf(lp, "Gateway restarts(cause unknown) at %s", ctime(&ct));
}
if(lp) {
D01("Gateway at %s", ctime(&ct));
fflush(lp);
}
}
else {
D01("Gateway restarts at %s", ctime(&ct));
execv("/tmp/mb3/Egtwy", av);
//execv("./Egtwy", av);
//execv(Execute_file, av);
exit(0);
}
}
}