diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-10-03 20:02:06 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-10-03 20:02:06 +0000 |
commit | aad1b89b68b0651b5729b15203081f6b4620847a (patch) | |
tree | 8a5906c3607c082e27d4d8ebc1e9a9e5b42822b5 /src/os/unix | |
parent | 8035fd27919d1f598b0d655a3bf30200220462d3 (diff) | |
download | nginx-aad1b89b68b0651b5729b15203081f6b4620847a.tar.gz nginx-aad1b89b68b0651b5729b15203081f6b4620847a.zip |
nginx-0.1.0-2004-10-04-00:02:06 import
Diffstat (limited to 'src/os/unix')
-rw-r--r-- | src/os/unix/ngx_freebsd.h | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_freebsd_init.c | 132 | ||||
-rw-r--r-- | src/os/unix/ngx_linux_init.c | 25 | ||||
-rw-r--r-- | src/os/unix/ngx_os.h | 17 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 24 | ||||
-rw-r--r-- | src/os/unix/ngx_process_cycle.c | 30 | ||||
-rw-r--r-- | src/os/unix/ngx_solaris_init.c | 12 |
7 files changed, 155 insertions, 90 deletions
diff --git a/src/os/unix/ngx_freebsd.h b/src/os/unix/ngx_freebsd.h index 7b1532c1f..9c8910586 100644 --- a/src/os/unix/ngx_freebsd.h +++ b/src/os/unix/ngx_freebsd.h @@ -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_ */ diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c index d07670a07..dcf432b65 100644 --- a/src/os/unix/ngx_freebsd_init.c +++ b/src/os/unix/ngx_freebsd_init.c @@ -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); +} diff --git a/src/os/unix/ngx_linux_init.c b/src/os/unix/ngx_linux_init.c index a6daf3a2f..db72c6e22 100644 --- a/src/os/unix/ngx_linux_init.c +++ b/src/os/unix/ngx_linux_init.c @@ -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); +} diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index 0ddb93bac..b28a73ffb 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -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> diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index f750495bf..134c27691 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -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; diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 5a9f79dc2..4d4db54c6 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -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"); diff --git a/src/os/unix/ngx_solaris_init.c b/src/os/unix/ngx_solaris_init.c index f2ff462f3..a743ab525 100644 --- a/src/os/unix/ngx_solaris_init.c +++ b/src/os/unix/ngx_solaris_init.c @@ -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); } |