comparison src/os/unix/ngx_daemon.c @ 92:19cc647ecd91

nginx-0.0.1-2003-05-20-19:37:55 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 20 May 2003 15:37:55 +0000
parents 3973260705cc
children 00bee6e7b485
comparison
equal deleted inserted replaced
91:637625a2acdb 92:19cc647ecd91
9 { 9 {
10 int fd; 10 int fd;
11 11
12 switch (fork()) { 12 switch (fork()) {
13 case -1: 13 case -1:
14 ngx_log_error(NGX_LOG_ALERT, log, errno, "fork() failed"); 14 ngx_log_error(NGX_LOG_EMERG, log, errno, "fork() failed");
15 return NGX_ERROR; 15 return NGX_ERROR;
16 16
17 case 0: 17 case 0:
18 break; 18 break;
19 19
20 default: 20 default:
21 exit(0); 21 exit(0);
22 } 22 }
23 23
24 if (setsid() == -1) { 24 if (setsid() == -1) {
25 ngx_log_error(NGX_LOG_ALERT, log, errno, "setsid() failed"); 25 ngx_log_error(NGX_LOG_EMERG, log, errno, "setsid() failed");
26 return NGX_ERROR; 26 return NGX_ERROR;
27 } 27 }
28 28
29 #if (__SVR4 || linux) 29 #if (__SVR4 || linux)
30 30
31 /* need HUP IGN ? check in Solaris and Linux */ 31 /* need HUP IGN ? check in Solaris and Linux */
32 32
33 switch (fork()) { 33 switch (fork()) {
34 case -1: 34 case -1:
35 ngx_log_error(NGX_LOG_ALERT, log, errno, "fork() failed"); 35 ngx_log_error(NGX_LOG_EMERG, log, errno, "fork() failed");
36 return NGX_ERROR; 36 return NGX_ERROR;
37 37
38 case 0: 38 case 0:
39 break; 39 break;
40 40
47 umask(0); 47 umask(0);
48 48
49 #if 0 49 #if 0
50 fd = open("/dev/null", O_RDWR); 50 fd = open("/dev/null", O_RDWR);
51 if (fd == -1) { 51 if (fd == -1) {
52 ngx_log_error(NGX_LOG_ALERT, log, errno, "open(\"/dev/null\") failed"); 52 ngx_log_error(NGX_LOG_EMERG, log, errno, "open(\"/dev/null\") failed");
53 return NGX_ERROR; 53 return NGX_ERROR;
54 } 54 }
55 55
56 if (dup2(fd, STDIN_FILENO) == -1) { 56 if (dup2(fd, STDIN_FILENO) == -1) {
57 ngx_log_error(NGX_LOG_ALERT, log, errno, "dup2(STDIN) failed"); 57 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDIN) failed");
58 return NGX_ERROR; 58 return NGX_ERROR;
59 } 59 }
60 60
61 if (dup2(fd, STDOUT_FILENO) == -1) { 61 if (dup2(fd, STDOUT_FILENO) == -1) {
62 ngx_log_error(NGX_LOG_ALERT, log, errno, "dup2(STDOUT) failed"); 62 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDOUT) failed");
63 return NGX_ERROR; 63 return NGX_ERROR;
64 } 64 }
65 65
66 if (dup2(fd, STDERR_FILENO) == -1) { 66 if (dup2(fd, STDERR_FILENO) == -1) {
67 ngx_log_error(NGX_LOG_ALERT, log, errno, "dup2(STDERR) failed"); 67 ngx_log_error(NGX_LOG_EMERG, log, errno, "dup2(STDERR) failed");
68 return NGX_ERROR; 68 return NGX_ERROR;
69 } 69 }
70 70
71 if (fd > STDERR_FILENO) { 71 if (fd > STDERR_FILENO) {
72 if (close(fd) == -1) { 72 if (close(fd) == -1) {
73 ngx_log_error(NGX_LOG_ALERT, log, errno, "close() failed"); 73 ngx_log_error(NGX_LOG_EMERG, log, errno, "close() failed");
74 return NGX_ERROR; 74 return NGX_ERROR;
75 } 75 }
76 } 76 }
77 #endif 77 #endif
78 78