-
Notifications
You must be signed in to change notification settings - Fork 10
/
dinit.c
executable file
·59 lines (43 loc) · 949 Bytes
/
dinit.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
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
char *garg1;
char *garg2;
char *garg3;
char *garg4;
char cmd[256];
void sig_handler (int signo)
{
if (signo == SIGINT || signo == SIGTERM)
{
printf("Shutdown Signal Received:\n");
sprintf(cmd, "%s %s", garg3, garg4);
system(cmd);
}
printf("Received signal %d\n",signo);
}
int main(int argc, char *argv[])
{
garg1=argv[1];
garg2=argv[2];
garg3=argv[3];
garg4=argv[4];
printf("argv[1]: %s\n", garg1);
printf("argv[2]: %s\n", garg2);
printf("argv[3]: %s\n", garg3);
printf("argv[4]: %s\n", garg4);
if (signal(SIGINT, sig_handler) == SIG_ERR)
printf("Can't catch SIGINT\n");
if (signal(SIGTERM, sig_handler) == SIG_ERR)
printf("Can't catch SIGTERM\n");
if (signal(SIGKILL, sig_handler) == SIG_ERR)
printf("Can't catch SIGKILL\n");
sprintf(cmd, "%s %s", garg1, garg2);
system(cmd);
while (1)
{
sleep(10);
}
return 0;
}