summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroberto@fiorenzo <roberto@fiorenzo>2012-04-13 17:08:52 +0200
committerroberto@fiorenzo <roberto@fiorenzo>2012-04-13 17:08:52 +0200
commit0d3bf93c76b2a1460ee1a89db0b9f7a0e192371b (patch)
treea34598306150e2a7eb1aa3094039ca8526ba44e0
parent57b9bdb95888a9184680bb9d1983c68432e23074 (diff)
downloaduwsgi-0d3bf93c76b2a1460ee1a89db0b9f7a0e192371b.tar.gz
fixed fd leak in daemonize
-rw-r--r--utils.c10
-rw-r--r--uwsgi.c5
2 files changed, 9 insertions, 6 deletions
diff --git a/utils.c b/utils.c
index cc366741..07b15f53 100644
--- a/utils.c
+++ b/utils.c
@@ -187,9 +187,12 @@ void daemonize(char *logfile) {
}
/* stdin */
- if (dup2(fdin, 0) < 0) {
- uwsgi_error("dup2()");
- exit(1);
+ if (fdin != 0) {
+ if (dup2(fdin, 0) < 0) {
+ uwsgi_error("dup2()");
+ exit(1);
+ }
+ close(fdin);
}
@@ -2696,6 +2699,7 @@ void spawn_daemon(struct uwsgi_daemon *ud) {
uwsgi_error("dup2()");
exit(1);
}
+ close(devnull);
}
if (setsid() < 0) {
diff --git a/uwsgi.c b/uwsgi.c
index e0de65ea..a5a2b2f5 100644
--- a/uwsgi.c
+++ b/uwsgi.c
@@ -2821,9 +2821,8 @@ nextsock:
}
if (!enabled) {
- int fd = uwsgi_sock->fd;
- close(fd);
- fd = open("/dev/null", O_RDONLY);
+ close(uwsgi_sock->fd);
+ int fd = open("/dev/null", O_RDONLY);
if (fd < 0) {
uwsgi_error_open("/dev/null");
exit(1);