Mercurial > hg > nginx-quic
comparison src/os/unix/ngx_daemon.c @ 105:00bee6e7b485
nginx-0.0.1-2003-06-15-22:32:13 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 15 Jun 2003 18:32:13 +0000 |
parents | 19cc647ecd91 |
children | 71ce40b3c37b |
comparison
equal
deleted
inserted
replaced
104:7db96f59bc29 | 105:00bee6e7b485 |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_log.h> | |
5 | 4 |
6 /* daemon in Linux */ | |
7 | 5 |
8 int ngx_daemon(ngx_log_t *log) | 6 int ngx_daemon(ngx_log_t *log) |
9 { | 7 { |
10 int fd; | 8 int fd; |
11 | 9 |
24 if (setsid() == -1) { | 22 if (setsid() == -1) { |
25 ngx_log_error(NGX_LOG_EMERG, log, errno, "setsid() failed"); | 23 ngx_log_error(NGX_LOG_EMERG, log, errno, "setsid() failed"); |
26 return NGX_ERROR; | 24 return NGX_ERROR; |
27 } | 25 } |
28 | 26 |
29 #if (__SVR4 || linux) | |
30 | |
31 /* need HUP IGN ? check in Solaris and Linux */ | |
32 | |
33 switch (fork()) { | |
34 case -1: | |
35 ngx_log_error(NGX_LOG_EMERG, log, errno, "fork() failed"); | |
36 return NGX_ERROR; | |
37 | |
38 case 0: | |
39 break; | |
40 | |
41 default: | |
42 exit(0); | |
43 } | |
44 | |
45 #endif | |
46 | |
47 umask(0); | 27 umask(0); |
48 | 28 |
49 #if 0 | |
50 fd = open("/dev/null", O_RDWR); | 29 fd = open("/dev/null", O_RDWR); |
51 if (fd == -1) { | 30 if (fd == -1) { |
52 ngx_log_error(NGX_LOG_EMERG, log, errno, "open(\"/dev/null\") failed"); | 31 ngx_log_error(NGX_LOG_EMERG, log, errno, "open(\"/dev/null\") failed"); |
53 return NGX_ERROR; | 32 return NGX_ERROR; |
54 } | 33 } |
61 if (dup2(fd, STDOUT_FILENO) == -1) { | 40 if (dup2(fd, STDOUT_FILENO) == -1) { |
62 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDOUT) failed"); | 41 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDOUT) failed"); |
63 return NGX_ERROR; | 42 return NGX_ERROR; |
64 } | 43 } |
65 | 44 |
45 #if 0 | |
66 if (dup2(fd, STDERR_FILENO) == -1) { | 46 if (dup2(fd, STDERR_FILENO) == -1) { |
67 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed"); | 47 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed"); |
68 return NGX_ERROR; | 48 return NGX_ERROR; |
69 } | 49 } |
50 #endif | |
70 | 51 |
71 if (fd > STDERR_FILENO) { | 52 if (fd > STDERR_FILENO) { |
72 if (close(fd) == -1) { | 53 if (close(fd) == -1) { |
73 ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed"); | 54 ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed"); |
74 return NGX_ERROR; | 55 return NGX_ERROR; |
75 } | 56 } |
76 } | 57 } |
77 #endif | |
78 | 58 |
79 return NGX_OK; | 59 return NGX_OK; |
80 } | 60 } |