nginx-0.1.0-2004-10-04-00:02:06 import

This commit is contained in:
Igor Sysoev 2004-10-03 20:02:06 +00:00
parent 8035fd2791
commit aad1b89b68
16 changed files with 218 additions and 139 deletions

View File

@ -89,7 +89,7 @@ ngx_module_t ngx_core_module = {
ngx_core_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */
NULL /* init child */
NULL /* init process */
};
@ -146,10 +146,6 @@ int main(int argc, char *const *argv)
if (ngx_test_config) {
log->log_level = NGX_LOG_INFO;
} else {
if (ngx_log_init_error_log() == NGX_ERROR) {
return 1;
}
}
if (ngx_os_init(log) == NGX_ERROR) {
@ -183,6 +179,8 @@ int main(int argc, char *const *argv)
return 0;
}
ngx_os_status(cycle->log);
ngx_cycle = cycle;
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);

View File

@ -560,7 +560,7 @@ static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
ngx_log_error(NGX_LOG_INFO, cf->log, 0, "include %s", file.data);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
return ngx_conf_parse(cf, &file);
}
@ -597,6 +597,11 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
ngx_list_part_t *part;
ngx_open_file_t *file;
#if (NGX_SUPPRESS_WARN)
full.len = 0;
full.data = NULL;
#endif
if (name) {
full = *name;
@ -637,7 +642,7 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
file->name = full;
} else {
file->fd = STDERR_FILENO;
file->fd = ngx_stderr_fileno;
file->name.len = 0;
file->name.data = NULL;
}

View File

@ -328,24 +328,6 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
}
}
#if !(WIN32)
if (!failed && !ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
"dup2: %0X %d \"%s\"",
cycle->log->file,
cycle->log->file->fd, cycle->log->file->name.data);
if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"dup2(STDERR) failed");
failed = 1;
}
}
#endif
if (failed) {
/* rollback the new cycle configuration */
@ -364,7 +346,9 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
i = 0;
}
if (file[i].fd == NGX_INVALID_FILE) {
if (file[i].fd == NGX_INVALID_FILE
|| file[i].fd == ngx_stderr_fileno)
{
continue;
}
@ -400,8 +384,26 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
/* commit the new cycle configuration */
pool->log = cycle->log;
#if !(WIN32)
if (!ngx_test_config && cycle->log->file->fd != STDERR_FILENO) {
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
"dup2: %0X %d \"%s\"",
cycle->log->file,
cycle->log->file->fd, cycle->log->file->name.data);
if (dup2(cycle->log->file->fd, STDERR_FILENO) == NGX_ERROR) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"dup2(STDERR) failed");
/* fatal */
exit(1);
}
}
#endif
pool->log = cycle->log;
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->init_module) {
@ -446,7 +448,7 @@ ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle)
i = 0;
}
if (file[i].fd == NGX_INVALID_FILE) {
if (file[i].fd == NGX_INVALID_FILE || file[i].fd == ngx_stderr_fileno) {
continue;
}

View File

@ -228,13 +228,16 @@ ngx_log_t *ngx_log_init_stderr()
{
#if (WIN32)
ngx_stderr.fd = GetStdHandle(STD_ERROR_HANDLE);
ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE);
ngx_stderr.fd = ngx_stderr_fileno;
if (ngx_stderr_fileno == NGX_INVALID_FILE) {
if (ngx_stderr.fd == NGX_INVALID_FILE) {
/* TODO: where can we log error ? */
return NULL;
} else if (ngx_stderr.fd == NULL) {
} else if (ngx_stderr_fileno == NULL) {
/* there are no associated standard handles */
@ -256,6 +259,8 @@ ngx_log_t *ngx_log_init_stderr()
}
#if 0
ngx_int_t ngx_log_init_error_log()
{
ngx_fd_t fd;
@ -299,6 +304,8 @@ ngx_int_t ngx_log_init_error_log()
return NGX_OK;
}
#endif
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
{

View File

@ -196,7 +196,9 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#define ngx_log_copy_log(new, old) ngx_memcpy(new, old, sizeof(ngx_log_t))
ngx_log_t *ngx_log_init_stderr();
#if 0
ngx_int_t ngx_log_init_error_log();
#endif
ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args);
char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);

View File

@ -47,7 +47,6 @@ static char *client_header_errors[] = {
"client %s sent invalid header, URL: %s",
"client %s sent too long header line, URL: %s",
"client %s sent too many headers, URL: %s",
"client %s sent HTTP/1.1 request without \"Host\" header, URL: %s",
"client %s sent invalid \"Content-Length\" header, URL: %s",
"client %s sent POST method without \"Content-Length\" header, URL: %s",
@ -759,12 +758,6 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
}
}
if (r->headers_n > 100) {
ngx_http_client_error(r, NGX_HTTP_PARSE_TOO_MANY_HEADERS,
NGX_HTTP_BAD_REQUEST);
return;
}
rc = ngx_http_parse_header_line(r, r->header_in);
if (rc == NGX_OK) {

View File

@ -38,7 +38,6 @@
#define NGX_HTTP_PARSE_HEADER_ERROR 14
#define NGX_HTTP_PARSE_INVALID_HEADER 14
#define NGX_HTTP_PARSE_TOO_LONG_HEADER 15
#define NGX_HTTP_PARSE_TOO_MANY_HEADERS 16
#define NGX_HTTP_PARSE_NO_HOST_HEADER 17
#define NGX_HTTP_PARSE_INVALID_CL_HEADER 18
#define NGX_HTTP_PARSE_POST_WO_CL_HEADER 19

View File

@ -15,9 +15,10 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
extern int ngx_freebsd_kern_osreldate;
extern int ngx_freebsd_hw_ncpu;
extern int ngx_freebsd_net_inet_tcp_sendspace;
extern int ngx_freebsd_sendfile_nbytes_bug;
extern int ngx_freebsd_kern_ipc_zero_copy_send;
extern int ngx_freebsd_use_tcp_nopush;
extern ngx_uint_t ngx_freebsd_sendfile_nbytes_bug;
extern ngx_uint_t ngx_freebsd_use_tcp_nopush;
#endif /* _NGX_FREEBSD_H_INCLUDED_ */

View File

@ -22,8 +22,8 @@ int ngx_freebsd_machdep_hlt_logical_cpus;
int ngx_freebsd_kern_ipc_zero_copy_send;
int ngx_freebsd_sendfile_nbytes_bug;
int ngx_freebsd_use_tcp_nopush;
ngx_uint_t ngx_freebsd_sendfile_nbytes_bug;
ngx_uint_t ngx_freebsd_use_tcp_nopush;
ngx_os_io_t ngx_os_io = {
@ -41,32 +41,31 @@ ngx_os_io_t ngx_os_io = {
typedef struct {
char *name;
int *value;
size_t size;
char *name;
int *value;
size_t size;
ngx_uint_t exists;
} sysctl_t;
sysctl_t sysctls[] = {
{"hw.ncpu",
&ngx_freebsd_hw_ncpu,
sizeof(int)},
{ "hw.ncpu",
&ngx_freebsd_hw_ncpu,
sizeof(int), 0 },
{"machdep.hlt_logical_cpus",
&ngx_freebsd_machdep_hlt_logical_cpus,
sizeof(int)},
{ "machdep.hlt_logical_cpus",
&ngx_freebsd_machdep_hlt_logical_cpus,
sizeof(int), 0 },
{"net.inet.tcp.sendspace",
&ngx_freebsd_net_inet_tcp_sendspace,
sizeof(int)},
{ "net.inet.tcp.sendspace",
&ngx_freebsd_net_inet_tcp_sendspace,
sizeof(int), 0 },
/* FreeBSD 5.0 */
{ "kern.ipc.zero_copy.send",
&ngx_freebsd_kern_ipc_zero_copy_send,
sizeof(int), 0 },
{"kern.ipc.zero_copy.send",
&ngx_freebsd_kern_ipc_zero_copy_send,
sizeof(int)},
{NULL, NULL, 0}
{ NULL, NULL, 0, 0 }
};
@ -84,11 +83,12 @@ void ngx_debug_init()
}
int ngx_os_init(ngx_log_t *log)
ngx_int_t ngx_os_init(ngx_log_t *log)
{
int i, version;
size_t size;
ngx_err_t err;
int version;
size_t size;
ngx_err_t err;
ngx_uint_t i;
size = sizeof(ngx_freebsd_kern_ostype);
if (sysctlbyname("kern.ostype",
@ -106,9 +106,6 @@ int ngx_os_init(ngx_log_t *log)
return NGX_ERROR;
}
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
ngx_freebsd_kern_ostype, ngx_freebsd_kern_osrelease);
size = sizeof(int);
if (sysctlbyname("kern.osreldate",
@ -120,17 +117,6 @@ int ngx_os_init(ngx_log_t *log)
version = ngx_freebsd_kern_osreldate;
#ifdef __DragonFly_version
ngx_log_error(NGX_LOG_INFO, log, 0,
"kern.osreldate: %d, built on %d",
version, __DragonFly_version);
#else
ngx_log_error(NGX_LOG_INFO, log, 0,
"kern.osreldate: %d, built on %d",
version, __FreeBSD_version);
#endif
#if (HAVE_SENDFILE)
@ -139,9 +125,9 @@ int ngx_os_init(ngx_log_t *log)
* There are two sendfile() syscalls: a new #393 has no bug while
* an old #336 has the bug in some versions and has not in others.
* Besides libc_r wrapper also emulates the bug in some versions.
* There's no way to say exactly if a given FreeBSD version has the bug.
* We use the algorithm that is correct at least for RELEASEs
* and for syscalls only (not libc_r wrapper).
* There is no way to say exactly if syscall #336 in FreeBSD circa 4.6
* has the bug. We use the algorithm that is correct at least for
* RELEASEs and for syscalls only (not libc_r wrapper).
*
* 4.6.1-RELEASE and below have the bug
* 4.6.2-RELEASE and above have the new syscall
@ -176,23 +162,29 @@ int ngx_os_init(ngx_log_t *log)
for (i = 0; sysctls[i].name; i++) {
*sysctls[i].value = 0;
size = sysctls[i].size;
if (sysctlbyname(sysctls[i].name, sysctls[i].value, &size, NULL, 0)
== -1) {
err = ngx_errno;
if (err != NGX_ENOENT) {
if (sysctls[i].value == &ngx_freebsd_machdep_hlt_logical_cpus) {
continue;
}
ngx_log_error(NGX_LOG_ALERT, log, err,
"sysctlbyname(%s) failed", sysctls[i].name);
return NGX_ERROR;
}
} else {
ngx_log_error(NGX_LOG_INFO, log, 0, "%s: %d",
sysctls[i].name, *sysctls[i].value);
== 0)
{
sysctls[i].exists = 1;
continue;
}
err = ngx_errno;
if (err == NGX_ENOENT) {
continue;
}
#if 0
if (sysctls[i].value == &ngx_freebsd_machdep_hlt_logical_cpus) {
continue;
}
#endif
ngx_log_error(NGX_LOG_ALERT, log, err,
"sysctlbyname(%s) failed", sysctls[i].name);
return NGX_ERROR;
}
if (ngx_freebsd_machdep_hlt_logical_cpus) {
@ -203,3 +195,31 @@ int ngx_os_init(ngx_log_t *log)
return ngx_posix_init(log);
}
void ngx_os_status(ngx_log_t *log)
{
ngx_uint_t i;
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
ngx_freebsd_kern_ostype, ngx_freebsd_kern_osrelease);
#ifdef __DragonFly_version
ngx_log_error(NGX_LOG_INFO, log, 0,
"kern.osreldate: %d, built on %d",
ngx_freebsd_kern_osreldate, __DragonFly_version);
#else
ngx_log_error(NGX_LOG_INFO, log, 0,
"kern.osreldate: %d, built on %d",
ngx_freebsd_kern_osreldate, __FreeBSD_version);
#endif
for (i = 0; sysctls[i].name; i++) {
if (sysctls[i].exists) {
ngx_log_error(NGX_LOG_INFO, log, 0, "%s: %d",
sysctls[i].name, *sysctls[i].value);
}
}
ngx_posix_status(log);
}

View File

@ -28,9 +28,9 @@ ngx_os_io_t ngx_os_io = {
};
int ngx_os_init(ngx_log_t *log)
ngx_int_t ngx_os_init(ngx_log_t *log)
{
int name[2], len, rtsig_max;
int name[2], len;
name[0] = CTL_KERN;
name[1] = KERN_OSTYPE;
@ -52,20 +52,29 @@ int ngx_os_init(ngx_log_t *log)
return NGX_ERROR;
}
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
ngx_linux_kern_ostype, ngx_linux_kern_osrelease);
name[0] = CTL_KERN;
name[1] = KERN_RTSIGMAX;
len = sizeof(rtsig_max);
if (sysctl(name, sizeof(name), &rtsig_max, &len, NULL, 0) == -1) {
if (sysctl(name, sizeof(name), &ngx_linux_rtsig_max, &len, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_INFO, log, ngx_errno,
"sysctl(KERN_RTSIGMAX) failed");
} else {
ngx_linux_rtsig_max = 1;
ngx_linux_rtsig_max = 0;
}
return ngx_posix_init(log);
}
void ngx_os_status(ngx_log_t *log)
{
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
ngx_linux_kern_ostype, ngx_linux_kern_osrelease);
ngx_log_error(NGX_LOG_INFO, log, 0, "sysctl(KERN_RTSIGMAX): %d",
ngx_linux_rtsig_max);
ngx_posix_status(log);
}

View File

@ -44,10 +44,12 @@ typedef struct {
void ngx_debug_init();
int ngx_os_init(ngx_log_t *log);
int ngx_daemon(ngx_log_t *log);
int ngx_posix_init(ngx_log_t *log);
int ngx_posix_post_conf_init(ngx_log_t *log);
ngx_int_t ngx_os_init(ngx_log_t *log);
void ngx_os_status(ngx_log_t *log);
ngx_int_t ngx_daemon(ngx_log_t *log);
ngx_int_t ngx_posix_init(ngx_log_t *log);
void ngx_posix_status(ngx_log_t *log);
ngx_int_t ngx_posix_post_conf_init(ngx_log_t *log);
ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size);
@ -58,10 +60,11 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in,
extern ngx_os_io_t ngx_os_io;
extern int ngx_ncpu;
extern int ngx_max_sockets;
extern int ngx_inherited_nonblocking;
extern ngx_int_t ngx_ncpu;
extern ngx_int_t ngx_max_sockets;
extern ngx_int_t ngx_inherited_nonblocking;
#define ngx_stderr_fileno STDERR_FILENO
#ifdef __FreeBSD__
#include <ngx_freebsd.h>

View File

@ -8,9 +8,12 @@
#include <ngx_core.h>
int ngx_ncpu;
int ngx_max_sockets;
int ngx_inherited_nonblocking;
ngx_int_t ngx_ncpu;
ngx_int_t ngx_max_sockets;
ngx_int_t ngx_inherited_nonblocking;
struct rlimit rlmt;
#if (NGX_POSIX_IO)
@ -82,10 +85,9 @@ ngx_signal_t signals[] = {
};
int ngx_posix_init(ngx_log_t *log)
ngx_int_t ngx_posix_init(ngx_log_t *log)
{
ngx_signal_t *sig;
struct rlimit rlmt;
struct sigaction sa;
ngx_pagesize = getpagesize();
@ -111,10 +113,6 @@ int ngx_posix_init(ngx_log_t *log)
return NGX_ERROR;
}
ngx_log_error(NGX_LOG_INFO, log, 0,
"getrlimit(RLIMIT_NOFILE): " RLIM_T_FMT ":" RLIM_T_FMT,
rlmt.rlim_cur, rlmt.rlim_max);
ngx_max_sockets = rlmt.rlim_cur;
#if (HAVE_INHERITED_NONBLOCK)
@ -127,6 +125,14 @@ int ngx_posix_init(ngx_log_t *log)
}
void ngx_posix_status(ngx_log_t *log)
{
ngx_log_error(NGX_LOG_INFO, log, 0,
"getrlimit(RLIMIT_NOFILE): " RLIM_T_FMT ":" RLIM_T_FMT,
rlmt.rlim_cur, rlmt.rlim_max);
}
void ngx_signal_handler(int signo)
{
char *action;

View File

@ -189,7 +189,9 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "start new workers");
ngx_start_worker_processes(cycle, ccf->worker_processes,
NGX_PROCESS_JUST_RESPAWN);
NGX_PROCESS_RESPAWN);
ngx_noaccepting = 0;
continue;
}
@ -313,15 +315,19 @@ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
for (i = 0; i < ngx_last_process; i++) {
if (i == ngx_process_slot || ngx_processes[i].pid == -1) {
if (i == ngx_process_slot
|| ngx_processes[i].pid == -1
|| ngx_processes[i].channel[0] == -1)
{
continue;
}
ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0,
ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"pass channel s:%d pid:" PID_T_FMT
" fd:%d to s:%d pid:" PID_T_FMT,
" fd:%d to s:%d pid:" PID_T_FMT " fd:%d",
ch.slot, ch.pid, ch.fd,
i, ngx_processes[i].pid);
i, ngx_processes[i].pid,
ngx_processes[i].channel[0]);
/* TODO: NGX_AGAIN */
@ -378,6 +384,16 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
for (i = 0; i < ngx_last_process; i++) {
ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"child: %d " PID_T_FMT " e:%d t:%d d:%d r:%d j:%d",
i,
ngx_processes[i].pid,
ngx_processes[i].exiting,
ngx_processes[i].exited,
ngx_processes[i].detached,
ngx_processes[i].respawn,
ngx_processes[i].just_respawn);
if (ngx_processes[i].detached || ngx_processes[i].pid == -1) {
continue;
}
@ -632,6 +648,10 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
continue;
}
if (ngx_processes[n].channel[1] == -1) {
continue;
}
if (close(ngx_processes[n].channel[1]) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"close() failed");

View File

@ -27,7 +27,7 @@ ngx_os_io_t ngx_os_io = {
};
int ngx_os_init(ngx_log_t *log)
ngx_int_t ngx_os_init(ngx_log_t *log)
{
if (sysinfo(SI_SYSNAME, ngx_solaris_sysname, sizeof(ngx_solaris_sysname))
== -1)
@ -53,12 +53,18 @@ int ngx_os_init(ngx_log_t *log)
return NGX_ERROR;
}
return ngx_posix_init(log);
}
void ngx_os_status(ngx_log_t *log)
{
ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
ngx_solaris_sysname, ngx_solaris_release);
ngx_log_error(NGX_LOG_INFO, log, 0, "version: %s",
ngx_solaris_version);
return ngx_posix_init(log);
ngx_posix_status(log);
}

View File

@ -42,7 +42,8 @@ typedef struct {
} ngx_os_io_t;
int ngx_os_init(ngx_log_t *log);
ngx_int_t ngx_os_init(ngx_log_t *log);
void ngx_os_status(ngx_log_t *log);
ssize_t ngx_wsarecv(ngx_connection_t *c, u_char *buf, size_t size);
ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size);
@ -54,10 +55,11 @@ ngx_chain_t *ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
extern ngx_os_io_t ngx_os_io;
extern int ngx_ncpu;
extern int ngx_max_sockets;
extern int ngx_inherited_nonblocking;
extern int ngx_win32_version;
extern ngx_uint_t ngx_ncpu;
extern ngx_int_t ngx_max_sockets;
extern ngx_uint_t ngx_inherited_nonblocking;
extern ngx_uint_t ngx_win32_version;
extern ngx_fd_t ngx_stderr_fileno;

View File

@ -8,10 +8,11 @@
#include <ngx_core.h>
int ngx_win32_version;
int ngx_ncpu;
int ngx_max_sockets;
int ngx_inherited_nonblocking = 1;
ngx_uint_t ngx_win32_version;
ngx_uint_t ngx_ncpu;
ngx_int_t ngx_max_sockets;
ngx_uint_t ngx_inherited_nonblocking = 1;
ngx_fd_t ngx_stderr_fileno;
ngx_os_io_t ngx_os_io = {
@ -40,7 +41,7 @@ static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
static GUID tf_guid = WSAID_TRANSMITFILE;
int ngx_os_init(ngx_log_t *log)
ngx_int_t ngx_os_init(ngx_log_t *log)
{
u_int osviex;
DWORD bytes;
@ -189,3 +190,8 @@ int ngx_os_init(ngx_log_t *log)
return NGX_OK;
}
void ngx_os_status(ngx_log_t *log)
{
}