<html><head></head><body data-style="font-family: Monospace;"><div><br></div><div><br></div><div>Hello,</div><div><br></div><div>In the ngx_daemon.c the dup2 result code is checked but the earlier opened /dev/null handle is not closed in case of an error. Please consider this path to add to the source base.</div><div><br></div><div>Regards,</div><div><br></div><div>B.</div><div><br></div><div><br></div><div># HG changeset patch</div><div># User Bart Warmerdam <<a href="mailto:bartw@xs4all.nl">bartw@xs4all.nl</a>></div><div># Date 1444773372 -7200</div><div># Tue Oct 13 23:56:12 2015 +0200</div><div># Branch close_fd_on_error</div><div># Node ID e1e25db76cdf7583f1145b91b9dbcdff417d6f16</div><div># Parent 2f34ea503ac4e015cc08f6efbb279b360eda609c</div><div>Close file handle on error as well</div><div><br></div><div>diff -r 2f34ea503ac4 -r e1e25db76cdf src/os/unix/ngx_daemon.c</div><div>--- a/src/os/unix/ngx_daemon.c<span class="Apple-tab-span" style="white-space:pre"> </span>Wed Oct 07 22:19:42 2015 +0300</div><div>+++ b/src/os/unix/ngx_daemon.c<span class="Apple-tab-span" style="white-space:pre"> </span>Tue Oct 13 23:56:12 2015 +0200</div><div>@@ -9,6 +9,20 @@</div><div> #include <ngx_core.h></div><div> </div><div> </div><div>+static ngx_int_t</div><div>+ngx_close_handle(ngx_log_t *log, int fd)</div><div>+{</div><div>+ if (fd > STDERR_FILENO) {</div><div>+ if (close(fd) == -1) {</div><div>+ ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "close() failed");</div><div>+ return NGX_ERROR;</div><div>+ }</div><div>+ }</div><div>+</div><div>+ return NGX_OK;</div><div>+}</div><div>+</div><div>+</div><div> ngx_int_t</div><div> ngx_daemon(ngx_log_t *log)</div><div> {</div><div>@@ -44,26 +58,26 @@</div><div> </div><div> if (dup2(fd, STDIN_FILENO) == -1) {</div><div> ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDIN) failed");</div><div>+ ngx_close_handle(log, fd);</div><div> return NGX_ERROR;</div><div> }</div><div> </div><div> if (dup2(fd, STDOUT_FILENO) == -1) {</div><div> ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDOUT) failed");</div><div>+ ngx_close_handle(log, fd);</div><div> return NGX_ERROR;</div><div> }</div><div> </div><div> #if 0</div><div> if (dup2(fd, STDERR_FILENO) == -1) {</div><div> ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed");</div><div>+ ngx_close_handle(log, fd);</div><div> return NGX_ERROR;</div><div> }</div><div> #endif</div><div> </div><div>- if (fd > STDERR_FILENO) {</div><div>- if (close(fd) == -1) {</div><div>- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "close() failed");</div><div>- return NGX_ERROR;</div><div>- }</div><div>+ if (ngx_close_handle(log, fd) == NGX_ERROR) {</div><div>+ return NGX_ERROR;</div><div> }</div><div> </div><div> return NGX_OK;</div></body></html>