Klaus Demo nginx / aad1b89
nginx-0.1.0-2004-10-04-00:02:06 import Igor Sysoev 15 years ago
16 changed file(s) with 224 addition(s) and 145 deletion(s). Raw diff Collapse all Expand all
8888 ngx_core_commands, /* module directives */
8989 NGX_CORE_MODULE, /* module type */
9090 NULL, /* init module */
91 NULL /* init child */
91 NULL /* init process */
9292 };
9393
9494
145145
146146 if (ngx_test_config) {
147147 log->log_level = NGX_LOG_INFO;
148 } else {
149 if (ngx_log_init_error_log() == NGX_ERROR) {
150 return 1;
151 }
152148 }
153149
154150 if (ngx_os_init(log) == NGX_ERROR) {
181177 init_cycle.conf_file.data);
182178 return 0;
183179 }
180
181 ngx_os_status(cycle->log);
184182
185183 ngx_cycle = cycle;
186184
559559 return NGX_CONF_ERROR;
560560 }
561561
562 ngx_log_error(NGX_LOG_INFO, cf->log, 0, "include %s", file.data);
562 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
563563
564564 return ngx_conf_parse(cf, &file);
565565 }
595595 ngx_uint_t i;
596596 ngx_list_part_t *part;
597597 ngx_open_file_t *file;
598
599 #if (NGX_SUPPRESS_WARN)
600 full.len = 0;
601 full.data = NULL;
602 #endif
598603
599604 if (name) {
600605 full = *name;
636641 file->name = full;
637642
638643 } else {
639 file->fd = STDERR_FILENO;
644 file->fd = ngx_stderr_fileno;
640645 file->name.len = 0;
641646 file->name.data = NULL;
642647 }
327327 }
328328 }
329329
330 #if !(WIN32)
331
332 if (!failed && !ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
333
334 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
335 "dup2: %0X %d \"%s\"",
336 cycle->log->file,
337 cycle->log->file->fd, cycle->log->file->name.data);
338
339 if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
340 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
341 "dup2(STDERR) failed");
342 failed = 1;
343 }
344 }
345
346 #endif
347
348330 if (failed) {
349331
350332 /* rollback the new cycle configuration */
363345 i = 0;
364346 }
365347
366 if (file[i].fd == NGX_INVALID_FILE) {
348 if (file[i].fd == NGX_INVALID_FILE
349 || file[i].fd == ngx_stderr_fileno)
350 {
367351 continue;
368352 }
369353
399383
400384 /* commit the new cycle configuration */
401385
386 #if !(WIN32)
387
388 if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
389
390 ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
391 "dup2: %0X %d \"%s\"",
392 cycle->log->file,
393 cycle->log->file->fd, cycle->log->file->name.data);
394
395 if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
396 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
397 "dup2(STDERR) failed");
398 /* fatal */
399 exit(1);
400 }
401 }
402
403 #endif
404
402405 pool->log = cycle->log;
403
404406
405407 for (i = 0; ngx_modules[i]; i++) {
406408 if (ngx_modules[i]->init_module) {
445447 i = 0;
446448 }
447449
448 if (file[i].fd == NGX_INVALID_FILE) {
450 if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr_fileno) {
449451 continue;
450452 }
451453
227227 {
228228 #if (WIN32)
229229
230 ngx_stderr.fd = GetStdHandle(STD_ERROR_HANDLE);
231
232 if (ngx_stderr.fd == NGX_INVALID_FILE) {
230 ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE);
231 ngx_stderr.fd = ngx_stderr_fileno;
232
233 if (ngx_stderr_fileno == NGX_INVALID_FILE) {
234
233235 /* TODO: where can we log error ? */
236
234237 return NULL;
235238
236 } else if (ngx_stderr.fd == NULL) {
239 } else if (ngx_stderr_fileno == NULL) {
237240
238241 /* there are no associated standard handles */
239242
254257 return &ngx_log;
255258 }
256259
260
261 #if 0
257262
258263 ngx_int_t ngx_log_init_error_log()
259264 {
297302
298303 return NGX_OK;
299304 }
305
306 #endif
300307
301308
302309 ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
195195 #define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t))
196196
197197 ngx_log_t *ngx_log_init_stderr();
198 #if 0
198199 ngx_int_t ngx_log_init_error_log();
200 #endif
199201 ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args);
200202 char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
201203
4646
4747 "client %s sent invalid header, URL: %s",
4848 "client %s sent too long header line, URL: %s",
49 "client %s sent too many headers, URL: %s",
5049 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s",
5150 "client %s sent invalid \"Content-Length\" header, URL: %s",
5251 "client %s sent POST method without \"Content-Length\" header, URL: %s",
756755 if (n == NGX_AGAIN || n == NGX_ERROR) {
757756 return;
758757 }
759 }
760
761 if (r->headers_n > 100) {
762 ngx_http_client_error(r, NGX_HTTP_PARSE_TOO_MANY_HEADERS,
763 NGX_HTTP_BAD_REQUEST);
764 return;
765758 }
766759
767760 rc = ngx_http_parse_header_line(r, r->header_in);
3737 #define NGX_HTTP_PARSE_HEADER_ERROR 14
3838 #define NGX_HTTP_PARSE_INVALID_HEADER 14
3939 #define NGX_HTTP_PARSE_TOO_LONG_HEADER 15
40 #define NGX_HTTP_PARSE_TOO_MANY_HEADERS 16
4140 #define NGX_HTTP_PARSE_NO_HOST_HEADER 17
4241 #define NGX_HTTP_PARSE_INVALID_CL_HEADER 18
4342 #define NGX_HTTP_PARSE_POST_WO_CL_HEADER 19
1414 extern int ngx_freebsd_kern_osreldate;
1515 extern int ngx_freebsd_hw_ncpu;
1616 extern int ngx_freebsd_net_inet_tcp_sendspace;
17 extern int ngx_freebsd_sendfile_nbytes_bug;
1817 extern int ngx_freebsd_kern_ipc_zero_copy_send;
19 extern int ngx_freebsd_use_tcp_nopush;
18
19 extern ngx_uint_t ngx_freebsd_sendfile_nbytes_bug;
20 extern ngx_uint_t ngx_freebsd_use_tcp_nopush;
2021
2122
2223 #endif /* _NGX_FREEBSD_H_INCLUDED_ */
2121 int ngx_freebsd_kern_ipc_zero_copy_send;
2222
2323
24 int ngx_freebsd_sendfile_nbytes_bug;
25 int ngx_freebsd_use_tcp_nopush;
24 ngx_uint_t ngx_freebsd_sendfile_nbytes_bug;
25 ngx_uint_t ngx_freebsd_use_tcp_nopush;
2626
2727
2828 ngx_os_io_t ngx_os_io = {
4040
4141
4242 typedef struct {
43 char *name;
44 int *value;
45 size_t size;
43 char *name;
44 int *value;
45 size_t size;
46 ngx_uint_t exists;
4647 } sysctl_t;
4748
4849
4950 sysctl_t sysctls[] = {
50 {"hw.ncpu",
51 &ngx_freebsd_hw_ncpu,
52 sizeof(int)},
53
54 {"machdep.hlt_logical_cpus",
55 &ngx_freebsd_machdep_hlt_logical_cpus,
56 sizeof(int)},
57
58 {"net.inet.tcp.sendspace",
59 &ngx_freebsd_net_inet_tcp_sendspace,
60 sizeof(int)},
61
62 /* FreeBSD 5.0 */
63
64 {"kern.ipc.zero_copy.send",
65 &ngx_freebsd_kern_ipc_zero_copy_send,
66 sizeof(int)},
67
68 {NULL, NULL, 0}
51 { "hw.ncpu",
52 &ngx_freebsd_hw_ncpu,
53 sizeof(int), 0 },
54
55 { "machdep.hlt_logical_cpus",
56 &ngx_freebsd_machdep_hlt_logical_cpus,
57 sizeof(int), 0 },
58
59 { "net.inet.tcp.sendspace",
60 &ngx_freebsd_net_inet_tcp_sendspace,
61 sizeof(int), 0 },
62
63 { "kern.ipc.zero_copy.send",
64 &ngx_freebsd_kern_ipc_zero_copy_send,
65 sizeof(int), 0 },
66
67 { NULL, NULL, 0, 0 }
6968 };
7069
7170
8382 }
8483
8584
86 int ngx_os_init(ngx_log_t *log)
85 ngx_int_t ngx_os_init(ngx_log_t *log)
8786 {
88 int i, version;
89 size_t size;
90 ngx_err_t err;
87 int version;
88 size_t size;
89 ngx_err_t err;
90 ngx_uint_t i;
9191
9292 size = sizeof(ngx_freebsd_kern_ostype);
9393 if (sysctlbyname("kern.ostype",
105105 return NGX_ERROR;
106106 }
107107
108 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
109 ngx_freebsd_kern_ostype, ngx_freebsd_kern_osrelease);
110
111108
112109 size = sizeof(int);
113110 if (sysctlbyname("kern.osreldate",
119116
120117 version = ngx_freebsd_kern_osreldate;
121118
122 #ifdef __DragonFly_version
123 ngx_log_error(NGX_LOG_INFO, log, 0,
124 "kern.osreldate: %d, built on %d",
125 version, __DragonFly_version);
126 #else
127 ngx_log_error(NGX_LOG_INFO, log, 0,
128 "kern.osreldate: %d, built on %d",
129 version, __FreeBSD_version);
130 #endif
131
132
133119
134120 #if (HAVE_SENDFILE)
135121
138124 * There are two sendfile() syscalls: a new #393 has no bug while
139125 * an old #336 has the bug in some versions and has not in others.
140126 * Besides libc_r wrapper also emulates the bug in some versions.
141 * There's no way to say exactly if a given FreeBSD version has the bug.
142 * We use the algorithm that is correct at least for RELEASEs
143 * and for syscalls only (not libc_r wrapper).
127 * There is no way to say exactly if syscall #336 in FreeBSD circa 4.6
128 * has the bug. We use the algorithm that is correct at least for
129 * RELEASEs and for syscalls only (not libc_r wrapper).
144130 *
145131 * 4.6.1-RELEASE and below have the bug
146132 * 4.6.2-RELEASE and above have the new syscall
175161 for (i = 0; sysctls[i].name; i++) {
176162 *sysctls[i].value = 0;
177163 size = sysctls[i].size;
164
178165 if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0)
179 == -1) {
180 err = ngx_errno;
181 if (err != NGX_ENOENT) {
182 if (sysctls[i].value == &ngx_freebsd_machdep_hlt_logical_cpus) {
183 continue;
184 }
185
186 ngx_log_error(NGX_LOG_ALERT, log, err,
187 "sysctlbyname(%s) failed", sysctls[i].name);
188 return NGX_ERROR;
189 }
190
191 } else {
192 ngx_log_error(NGX_LOG_INFO, log, 0, "%s: %d",
193 sysctls[i].name, *sysctls[i].value);
194 }
166 == 0)
167 {
168 sysctls[i].exists = 1;
169 continue;
170 }
171
172 err = ngx_errno;
173
174 if (err == NGX_ENOENT) {
175 continue;
176 }
177
178 #if 0
179 if (sysctls[i].value == &ngx_freebsd_machdep_hlt_logical_cpus) {
180 continue;
181 }
182 #endif
183
184 ngx_log_error(NGX_LOG_ALERT, log, err,
185 "sysctlbyname(%s) failed", sysctls[i].name);
186 return NGX_ERROR;
195187 }
196188
197189 if (ngx_freebsd_machdep_hlt_logical_cpus) {
202194
203195 return ngx_posix_init(log);
204196 }
197
198
199 void ngx_os_status(ngx_log_t *log)
200 {
201 ngx_uint_t i;
202
203 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
204 ngx_freebsd_kern_ostype, ngx_freebsd_kern_osrelease);
205
206 #ifdef __DragonFly_version
207 ngx_log_error(NGX_LOG_INFO, log, 0,
208 "kern.osreldate: %d, built on %d",
209 ngx_freebsd_kern_osreldate, __DragonFly_version);
210 #else
211 ngx_log_error(NGX_LOG_INFO, log, 0,
212 "kern.osreldate: %d, built on %d",
213 ngx_freebsd_kern_osreldate, __FreeBSD_version);
214 #endif
215
216 for (i = 0; sysctls[i].name; i++) {
217 if (sysctls[i].exists) {
218 ngx_log_error(NGX_LOG_INFO, log, 0, "%s: %d",
219 sysctls[i].name, *sysctls[i].value);
220 }
221 }
222
223 ngx_posix_status(log);
224 }
2727 };
2828
2929
30 int ngx_os_init(ngx_log_t *log)
30 ngx_int_t ngx_os_init(ngx_log_t *log)
3131 {
32 int name[2], len, rtsig_max;
32 int name[2], len;
3333
3434 name[0] = CTL_KERN;
3535 name[1] = KERN_OSTYPE;
5151 return NGX_ERROR;
5252 }
5353
54 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
55 ngx_linux_kern_ostype, ngx_linux_kern_osrelease);
56
5754
5855 name[0] = CTL_KERN;
5956 name[1] = KERN_RTSIGMAX;
6057 len = sizeof(rtsig_max);
61 if (sysctl(name, sizeof(name), &rtsig_max, &len, NULL, 0) == -1) {
58 if (sysctl(name, sizeof(name), &ngx_linux_rtsig_max, &len, NULL, 0) == -1) {
6259 ngx_log_error(NGX_LOG_INFO, log, ngx_errno,
6360 "sysctl(KERN_RTSIGMAX) failed");
64 } else {
65 ngx_linux_rtsig_max = 1;
61 ngx_linux_rtsig_max = 0;
62
6663 }
6764
6865
6966 return ngx_posix_init(log);
7067 }
68
69
70 void ngx_os_status(ngx_log_t *log)
71 {
72 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
73 ngx_linux_kern_ostype, ngx_linux_kern_osrelease);
74
75 ngx_log_error(NGX_LOG_INFO, log, 0, "sysctl(KERN_RTSIGMAX): %d",
76 ngx_linux_rtsig_max);
77
78 ngx_posix_status(log);
79 }
4343
4444
4545 void ngx_debug_init();
46 int ngx_os_init(ngx_log_t *log);
47 int ngx_daemon(ngx_log_t *log);
48 int ngx_posix_init(ngx_log_t *log);
49 int ngx_posix_post_conf_init(ngx_log_t *log);
46 ngx_int_t ngx_os_init(ngx_log_t *log);
47 void ngx_os_status(ngx_log_t *log);
48 ngx_int_t ngx_daemon(ngx_log_t *log);
49 ngx_int_t ngx_posix_init(ngx_log_t *log);
50 void ngx_posix_status(ngx_log_t *log);
51 ngx_int_t ngx_posix_post_conf_init(ngx_log_t *log);
5052
5153
5254 ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size);
5759
5860
5961 extern ngx_os_io_t ngx_os_io;
60 extern int ngx_ncpu;
61 extern int ngx_max_sockets;
62 extern int ngx_inherited_nonblocking;
62 extern ngx_int_t ngx_ncpu;
63 extern ngx_int_t ngx_max_sockets;
64 extern ngx_int_t ngx_inherited_nonblocking;
6365
66 #define ngx_stderr_fileno STDERR_FILENO
6467
6568 #ifdef __FreeBSD__
6669 #include <ngx_freebsd.h>
77 #include <ngx_core.h>
88
99
10 int ngx_ncpu;
11 int ngx_max_sockets;
12 int ngx_inherited_nonblocking;
10 ngx_int_t ngx_ncpu;
11 ngx_int_t ngx_max_sockets;
12 ngx_int_t ngx_inherited_nonblocking;
13
14
15 struct rlimit rlmt;
1316
1417
1518 #if (NGX_POSIX_IO)
8184 };
8285
8386
84 int ngx_posix_init(ngx_log_t *log)
87 ngx_int_t ngx_posix_init(ngx_log_t *log)
8588 {
8689 ngx_signal_t *sig;
87 struct rlimit rlmt;
8890 struct sigaction sa;
8991
9092 ngx_pagesize = getpagesize();
110112 return NGX_ERROR;
111113 }
112114
113 ngx_log_error(NGX_LOG_INFO, log, 0,
114 "getrlimit(RLIMIT_NOFILE): " RLIM_T_FMT ":" RLIM_T_FMT,
115 rlmt.rlim_cur, rlmt.rlim_max);
116
117115 ngx_max_sockets = rlmt.rlim_cur;
118116
119117 #if (HAVE_INHERITED_NONBLOCK)
123121 #endif
124122
125123 return NGX_OK;
124 }
125
126
127 void ngx_posix_status(ngx_log_t *log)
128 {
129 ngx_log_error(NGX_LOG_INFO, log, 0,
130 "getrlimit(RLIMIT_NOFILE): " RLIM_T_FMT ":" RLIM_T_FMT,
131 rlmt.rlim_cur, rlmt.rlim_max);
126132 }
127133
128134
188188 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "start new workers");
189189
190190 ngx_start_worker_processes(cycle, ccf->worker_processes,
191 NGX_PROCESS_JUST_RESPAWN);
191 NGX_PROCESS_RESPAWN);
192 ngx_noaccepting = 0;
193
192194 continue;
193195 }
194196
312314
313315 for (i = 0; i < ngx_last_process; i++) {
314316
315 if (i == ngx_process_slot || ngx_processes[i].pid == -1) {
317 if (i == ngx_process_slot
318 || ngx_processes[i].pid == -1
319 || ngx_processes[i].channel[0] == -1)
320 {
316321 continue;
317322 }
318323
319 ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0,
324 ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
320325 "pass channel s:%d pid:" PID_T_FMT
321 " fd:%d to s:%d pid:" PID_T_FMT,
326 " fd:%d to s:%d pid:" PID_T_FMT " fd:%d",
322327 ch.slot, ch.pid, ch.fd,
323 i, ngx_processes[i].pid);
328 i, ngx_processes[i].pid,
329 ngx_processes[i].channel[0]);
324330
325331 /* TODO: NGX_AGAIN */
326332
376382
377383
378384 for (i = 0; i < ngx_last_process; i++) {
385
386 ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
387 "child: %d " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d",
388 i,
389 ngx_processes[i].pid,
390 ngx_processes[i].exiting,
391 ngx_processes[i].exited,
392 ngx_processes[i].detached,
393 ngx_processes[i].respawn,
394 ngx_processes[i].just_respawn);
379395
380396 if (ngx_processes[i].detached || ngx_processes[i].pid == -1) {
381397 continue;
631647 continue;
632648 }
633649
650 if (ngx_processes[n].channel[1] == -1) {
651 continue;
652 }
653
634654 if (close(ngx_processes[n].channel[1]) == -1) {
635655 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
636656 "close() failed");
2626 };
2727
2828
29 int ngx_os_init(ngx_log_t *log)
29 ngx_int_t ngx_os_init(ngx_log_t *log)
3030 {
3131 if (sysinfo(SI_SYSNAME, ngx_solaris_sysname, sizeof(ngx_solaris_sysname))
3232 == -1)
5252 return NGX_ERROR;
5353 }
5454
55 return ngx_posix_init(log);
56 }
57
58
59 void ngx_os_status(ngx_log_t *log)
60 {
61
5562 ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
5663 ngx_solaris_sysname, ngx_solaris_release);
5764
5865 ngx_log_error(NGX_LOG_INFO, log, 0, "version: %s",
5966 ngx_solaris_version);
6067
61
62 return ngx_posix_init(log);
68 ngx_posix_status(log);
6369 }
4141 } ngx_os_io_t;
4242
4343
44 int ngx_os_init(ngx_log_t *log);
44 ngx_int_t ngx_os_init(ngx_log_t *log);
45 void ngx_os_status(ngx_log_t *log);
4546
4647 ssize_t ngx_wsarecv(ngx_connection_t *c, u_char *buf, size_t size);
4748 ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size);
5354
5455
5556 extern ngx_os_io_t ngx_os_io;
56 extern int ngx_ncpu;
57 extern int ngx_max_sockets;
58 extern int ngx_inherited_nonblocking;
59 extern int ngx_win32_version;
57 extern ngx_uint_t ngx_ncpu;
58 extern ngx_int_t ngx_max_sockets;
59 extern ngx_uint_t ngx_inherited_nonblocking;
60 extern ngx_uint_t ngx_win32_version;
61 extern ngx_fd_t ngx_stderr_fileno;
6062
6163
6264
77 #include <ngx_core.h>
88
99
10 int ngx_win32_version;
11 int ngx_ncpu;
12 int ngx_max_sockets;
13 int ngx_inherited_nonblocking = 1;
10 ngx_uint_t ngx_win32_version;
11 ngx_uint_t ngx_ncpu;
12 ngx_int_t ngx_max_sockets;
13 ngx_uint_t ngx_inherited_nonblocking = 1;
14 ngx_fd_t ngx_stderr_fileno;
1415
1516
1617 ngx_os_io_t ngx_os_io = {
3940 static GUID tf_guid = WSAID_TRANSMITFILE;
4041
4142
42 int ngx_os_init(ngx_log_t *log)
43 ngx_int_t ngx_os_init(ngx_log_t *log)
4344 {
4445 u_int osviex;
4546 DWORD bytes;
188189
189190 return NGX_OK;
190191 }
192
193
194 void ngx_os_status(ngx_log_t *log)
195 {
196 }