Mercurial > hg > nginx-vendor-0-6
view src/os/unix/ngx_daemon.c @ 330:5e3b425174f6 NGINX_0_6_9
nginx 0.6.9
*) Bugfix: a worker process may got caught in an endless loop, if the
HTTPS protocol was used; bug appeared in 0.6.7.
*) Bugfix: if server listened on two addresses or ports and trailing
wildcard was used, then nginx did not run.
*) Bugfix: the "ip_hash" directive might incorrectly mark servers as
down.
*) Bugfix: nginx could not be built on amd64; bug appeared in 0.6.8.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 28 Aug 2007 00:00:00 +0400 |
parents | 6cfc63e68377 |
children |
line wrap: on
line source
/* * Copyright (C) Igor Sysoev */ #include <ngx_config.h> #include <ngx_core.h> ngx_int_t ngx_daemon(ngx_log_t *log) { int fd; switch (fork()) { case -1: ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "fork() failed"); return NGX_ERROR; case 0: break; default: exit(0); } ngx_pid = ngx_getpid(); if (setsid() == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "setsid() failed"); return NGX_ERROR; } umask(0); fd = open("/dev/null", O_RDWR); if (fd == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "open(\"/dev/null\") failed"); return NGX_ERROR; } if (dup2(fd, STDIN_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDIN) failed"); return NGX_ERROR; } if (dup2(fd, STDOUT_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDOUT) failed"); return NGX_ERROR; } #if 0 if (dup2(fd, STDERR_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed"); return NGX_ERROR; } #endif if (fd > STDERR_FILENO) { if (close(fd) == -1) { ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "close() failed"); return NGX_ERROR; } } return NGX_OK; }