projects
/
project
/
uhttpd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
32760c4
)
add forking
author
Felix Fietkau
<nbd@openwrt.org>
Sun, 30 Dec 2012 21:13:33 +0000
(22:13 +0100)
committer
Felix Fietkau
<nbd@openwrt.org>
Sun, 30 Dec 2012 21:13:33 +0000
(22:13 +0100)
main.c
patch
|
blob
|
history
diff --git
a/main.c
b/main.c
index
66d12b1
..
41b8eba
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-136,6
+136,7
@@
int main(int argc, char **argv)
bool nofork = false;
char *port;
int opt, ch;
bool nofork = false;
char *port;
int opt, ch;
+ int cur_fd;
init_defaults();
signal(SIGPIPE, SIG_IGN);
init_defaults();
signal(SIGPIPE, SIG_IGN);
@@
-251,5
+252,31
@@
int main(int argc, char **argv)
uh_config_parse();
uh_config_parse();
+ /* fork (if not disabled) */
+ if (!nofork) {
+ switch (fork()) {
+ case -1:
+ perror("fork()");
+ exit(1);
+
+ case 0:
+ /* daemon setup */
+ if (chdir("/"))
+ perror("chdir()");
+
+ cur_fd = open("/dev/null", O_WRONLY);
+ if (cur_fd > 0) {
+ dup2(cur_fd, 0);
+ dup2(cur_fd, 1);
+ dup2(cur_fd, 2);
+ }
+
+ break;
+
+ default:
+ exit(0);
+ }
+ }
+
return run_server();
}
return run_server();
}