repo.or.cz
/
tftp-hpa.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
tftpd: make it possible to adjust the remap deadman
[tftp-hpa.git]
/
lib
/
daemon.c
blob
0eb39c91336a8443de6168c3ee0030d1c7783259
1
/*
2
* daemon.c - "daemonize" a process
3
*/
4
5
#include
"config.h"
6
7
int
daemon
(
int
nochdir
,
int
noclose
)
8
{
9
int
nullfd
;
10
pid_t f
;
11
12
if
(!
nochdir
) {
13
if
(
chdir
(
"/"
))
14
return
-
1
;
15
}
16
17
if
(!
noclose
) {
18
if
((
nullfd
=
open
(
"/dev/null"
,
O_RDWR
)) <
0
||
19
dup2
(
nullfd
,
0
) <
0
||
20
dup2
(
nullfd
,
1
) <
0
||
dup2
(
nullfd
,
2
) <
0
)
21
return
-
1
;
22
close
(
nullfd
);
23
}
24
25
f
=
fork
();
26
if
(
f
<
0
)
27
return
-
1
;
28
else if
(
f
>
0
)
29
_exit
(
0
);
30
31
#ifdef HAVE_SETSID
32
return
setsid
();
33
#else
34
return
0
;
35
#endif
36
}