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
Update version for release
[tftp-hpa.git]
/
lib
/
daemon.c
blob
c3106b5096a909a6207939312a59581931ad908e
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
||
21
dup2
(
nullfd
,
2
) <
0
)
22
return
-
1
;
23
close
(
nullfd
);
24
}
25
26
f
=
fork
();
27
if
(
f
<
0
)
28
return
-
1
;
29
else if
(
f
>
0
)
30
_exit
(
0
);
31
32
#ifdef HAVE_SETSID
33
return
setsid
();
34
#else
35
return
0
;
36
#endif
37
}