-
Notifications
You must be signed in to change notification settings - Fork 6
/
initd.cpp
62 lines (52 loc) · 861 Bytes
/
initd.cpp
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
#include "initd.h"
#if defined(_HAVE_INITD)
# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# include <signal.h>
# include <sys/param.h>
# include <sys/types.h>
# include <sys/stat.h>
void sighandler(int signum)
{
if (SIGUSR1 == signum)
printf("%s", "catched external stop signal, now stop the server...\npost stop signals to "
"server sucessfully.\n");
}
void sinitd(void)
{
signal(SIGHUP, sighandler);
signal(SIGUSR1, sighandler);
}
void pinitd(void)
{
int pid;
int i;
int ret = 0;
if ((pid = fork()))
{
exit(0);
}
if (pid < 0)
{
exit(1);
}
setsid();
if ((pid = fork()))
{
exit(0);
}
if (pid < 0)
{
exit(1);
}
for (i = 0; i < NOFILE; ++i)
{
close(i);
}
ret = chdir("/tmp");
printf("chdir result=%d\n", ret);
umask(0);
return;
}
#endif