Mercurial > hg > nginx-quic
view src/os/unix/ngx_daemon.c @ 173:4fb2a2cff023
nginx-0.0.1-2003-11-04-20:09:19 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 04 Nov 2003 17:09:19 +0000 |
parents | 00bee6e7b485 |
children | 71ce40b3c37b |
line wrap: on
line source
#include <ngx_config.h> #include <ngx_core.h> int ngx_daemon(ngx_log_t *log) { int fd; switch (fork()) { case -1: ngx_log_error(NGX_LOG_EMERG, log, errno, "fork() failed"); return NGX_ERROR; case 0: break; default: exit(0); } if (setsid() == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "setsid() failed"); return NGX_ERROR; } umask(0); fd = open("/dev/null", O_RDWR); if (fd == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "open(\"/dev/null\") failed"); return NGX_ERROR; } if (dup2(fd, STDIN_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDIN) failed"); return NGX_ERROR; } if (dup2(fd, STDOUT_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDOUT) failed"); return NGX_ERROR; } #if 0 if (dup2(fd, STDERR_FILENO) == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed"); return NGX_ERROR; } #endif if (fd > STDERR_FILENO) { if (close(fd) == -1) { ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed"); return NGX_ERROR; } } return NGX_OK; }