diff options
author | roberto@fiorenzo <roberto@fiorenzo> | 2012-04-13 17:08:52 +0200 |
---|---|---|
committer | roberto@fiorenzo <roberto@fiorenzo> | 2012-04-13 17:08:52 +0200 |
commit | 0d3bf93c76b2a1460ee1a89db0b9f7a0e192371b (patch) | |
tree | a34598306150e2a7eb1aa3094039ca8526ba44e0 | |
parent | 57b9bdb95888a9184680bb9d1983c68432e23074 (diff) | |
download | uwsgi-0d3bf93c76b2a1460ee1a89db0b9f7a0e192371b.tar.gz |
fixed fd leak in daemonize
-rw-r--r-- | utils.c | 10 | ||||
-rw-r--r-- | uwsgi.c | 5 |
2 files changed, 9 insertions, 6 deletions
@@ -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) { @@ -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); |