# HG changeset patch # User Igor Sysoev # Date 1087492733 0 # Node ID 0a03c921c81d5c75b554a72f1d7f217206e5532f # Parent e260514b9ad4fae087cb402f3f40d4bb0632995b nginx-0.0.7-2004-06-17-21:18:53 import diff --git a/auto/feature b/auto/feature new file mode 100644 --- /dev/null +++ b/auto/feature @@ -0,0 +1,53 @@ + +echo $ngx_n "checking for $ngx_feature ..." $ngx_c +echo >> $NGX_ERR +echo "checking for $ngx_feature" >> $NGX_ERR + +ngx_found=no + +feature=`echo $ngx_feature_name | tr '[a-z]' '[A-Z]'` + +cat << END > $NGX_AUTOTEST.c + +#include +$NGX_UNISTD_H +$ngx_feature_inc + +int main() { + $ngx_feature_test; + return 0; +} + +END + +test="$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c \ + $ngx_feature_libs" +eval "$test >> $NGX_ERR 2>&1" + +if [ -x $NGX_AUTOTEST ]; then + + if [ $ngx_feature_run = yes ]; then + if $NGX_AUTOTEST 2>&1 > /dev/null; then + echo " found" + have=HAVE_$feature . auto/have + ngx_found=yes + else + echo " found but is not working" + fi + + else + echo " found" + have=HAVE_$feature . auto/have + ngx_found=yes + fi + +else + echo " not found" + echo "---------" >> $NGX_ERR + cat $NGX_AUTOTEST.c >> $NGX_ERR + echo "---------" >> $NGX_ERR + echo $test >> $NGX_ERR + echo "---------" >> $NGX_ERR +fi + +rm $NGX_AUTOTEST* diff --git a/auto/func b/auto/func --- a/auto/func +++ b/auto/func @@ -5,7 +5,7 @@ echo "checking for $ngx_func" >> $NGX_ER ngx_found=no -func=`echo $ngx_func | sed -e 's/()$//' | tr '[a-z.]' '[A-Z_]'` +func=`echo $ngx_func | sed -e 's/()$//' | tr '[a-z]' '[A-Z]'` cat << END > $NGX_AUTOTEST.c @@ -20,8 +20,8 @@ int main() { END -eval "$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c $ngx_func_libs \ - >> $NGX_ERR 2>&1" +test="$CC_WARN $CC_TEST_FLAGS -o $NGX_AUTOTEST $NGX_AUTOTEST.c $ngx_func_libs" +eval "$test >> $NGX_ERR 2>&1" if [ -x $NGX_AUTOTEST ]; then echo " found" @@ -30,6 +30,11 @@ if [ -x $NGX_AUTOTEST ]; then else echo " not found" + echo "---------" >> $NGX_ERR + cat $NGX_AUTOTEST.c >> $NGX_ERR + echo "---------" >> $NGX_ERR + echo $test >> $NGX_ERR + echo "---------" >> $NGX_ERR fi rm $NGX_AUTOTEST* diff --git a/auto/sources b/auto/sources --- a/auto/sources +++ b/auto/sources @@ -105,6 +105,7 @@ UNIX_DEPS="$CORE_DEPS $EVENT_DEPS \ src/os/unix/ngx_errno.h \ src/os/unix/ngx_alloc.h \ src/os/unix/ngx_files.h \ + src/os/unix/ngx_shared.h \ src/os/unix/ngx_process.h \ src/os/unix/ngx_thread.h \ src/os/unix/ngx_socket.h \ @@ -120,8 +121,9 @@ UNIX_SRCS="$CORE_SRCS $EVENT_SRCS \ src/os/unix/ngx_recv.c \ src/os/unix/ngx_readv_chain.c \ src/os/unix/ngx_writev_chain.c \ + src/os/unix/ngx_shared.c \ + src/os/unix/ngx_process.c \ src/os/unix/ngx_daemon.c \ - src/os/unix/ngx_process.c \ src/os/unix/ngx_posix_init.c \ src/os/unix/ngx_process_cycle.c" @@ -152,6 +154,7 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \ src/os/win32/ngx_errno.h \ src/os/win32/ngx_alloc.h \ src/os/win32/ngx_files.h \ + src/os/win32/ngx_shared.h \ src/os/win32/ngx_process.h \ src/os/win32/ngx_socket.h \ src/os/win32/ngx_os.h \ diff --git a/auto/unix b/auto/unix --- a/auto/unix +++ b/auto/unix @@ -40,14 +40,6 @@ ngx_types="int"; . auto/types/typedef . auto/types/uintptr_t -ngx_func="sin_len" -ngx_func_inc="#include -#include " - -ngx_func_test="struct sockaddr_in sa; sa.sin_len = 5" -. auto/func - - # printf() formats CC_WARN=$CC_STRONG @@ -71,19 +63,21 @@ ngx_fmt_name=RLIM_T_FMT; ngx_type="rlim_ eval ngx_formats=\${ngx_${ngx_bytes}_fmt}; . auto/fmt/fmt -# syscalls and libc calls +# syscalls, libc calls and some features + +ngx_feature_libs= +ngx_func_libs= + ngx_func="pread()" ngx_func_inc= -ngx_func_test="char buf[1]; ssize_t n; - n = pread(0, buf, 1, 0)" +ngx_func_test="char buf[1]; ssize_t n; n = pread(0, buf, 1, 0)" . auto/func ngx_func="pwrite()" ngx_func_inc= -ngx_func_test="char buf[1]; ssize_t n; - n = pwrite(1, buf, 1, 0)" +ngx_func_test="char buf[1]; ssize_t n; n = pwrite(1, buf, 1, 0)" . auto/func @@ -113,7 +107,7 @@ ngx_func_test="struct tm t; time_t c=0; ngx_func="posix_memalign()" ngx_func_inc="#include " -ngx_func_test="void *p, int n; n = posix_memalign(&p, 4096, 4096)" +ngx_func_test="void *p; int n; n = posix_memalign(&p, 4096, 4096)" . auto/func @@ -123,13 +117,76 @@ ngx_func_test="void *p; p = memalign(409 . auto/func -ngx_func="msghdr.msg_control" -ngx_func_inc="#include " -ngx_func_test="struct msghdr msg; msg.msg_control = NULL" -. auto/func + +ngx_feature="mmap(MAP_ANON|MAP_SHARED)" +ngx_feature_name="MAP_ANON" +ngx_feature_inc="#include " +ngx_feature_test="void *p; + p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, + MAP_ANON|MAP_SHARED, -1, 0); + if (p == MAP_FAILED) return 1;" +ngx_feature_run=yes +. auto/feature + + +ngx_feature='mmap("/dev/zero", MAP_SHARED)' +ngx_feature_name="MAP_DEVZERO" +ngx_feature_inc="#include +#include +#include " +ngx_feature_test='void *p; int fd; + fd = open("/dev/zero", O_RDWR); + p = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (p == MAP_FAILED) return 1;' +. auto/feature + + +ngx_feature="System V shared memory" +ngx_feature_name="SYSVSHM" +ngx_feature_inc="#include +#include " +ngx_feature_test="int id; + id = shmget(IPC_PRIVATE, 4096, (SHM_R|SHM_W|IPC_CREAT)); + if (id == -1) return 1; + shmctl(id, IPC_RMID, NULL);" +. auto/feature + -ngx_func="FIONBIO" -ngx_func_inc="#include " -ngx_func_test="int i; i = FIONBIO" -. auto/func +ngx_feature="struct sockaddr_in.sin_len" +ngx_feature_name="sin_len" +ngx_feature_inc="#include +#include " +ngx_feature_test="struct sockaddr_in sa; sa.sin_len = 5" +ngx_feature_run=no +. auto/feature + + +ngx_feature="struct msghdr.msg_control" +ngx_feature_name="msghdr_msg_control" +ngx_feature_inc="#include " +ngx_feature_test="struct msghdr msg; msg.msg_control = NULL" +. auto/feature + + +case $PLATFORM in + Linux:*) + ngx_feature_inc="#include " + ;; + + *) + ngx_feature_inc="#include " + ;; +esac + +ngx_feature="ioctl(FIONBIO)" +ngx_feature_name="FIONBIO" +ngx_feature_test="int i; i = FIONBIO" +. auto/feature + + +ngx_feature="struct tm.tm_gmtoff" +ngx_feature_name="gmtoff" +ngx_feature_inc="#include " +ngx_feature_test="struct tm tm; tm.tm_gmtoff = 0" +. auto/feature diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -19,6 +19,7 @@ typedef struct ngx_connection_s ngx_con #include #include #include +#include #include #include #include diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -123,15 +123,20 @@ void ngx_time_update(time_t s) ngx_cached_http_time.data = p; -#if (HAVE_TIMEZONE) +#if (HAVE_GETTIMEZONE) + + ngx_gmtoff = ngx_gettimezone(); + ngx_gmtime(ngx_cached_time + ngx_gmtoff * 60, &tm); - ngx_gmtoff = ngx_timezone(); - ngx_gmtime(ngx_cached_time + ngx_gmtoff * 60, &tm); +#elif (HAVE_GMTOFF) + + ngx_localtime(&tm); + ngx_gmtoff = tm.ngx_tm_gmtoff / 60; #else ngx_localtime(&tm); - ngx_gmtoff = tm.ngx_tm_gmtoff / 60; + ngx_gmtoff = ngx_timezone(tm.ngx_tm_isdst); #endif diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -187,6 +187,7 @@ static ngx_int_t ngx_event_module_init(n size = 128 /* ngx_accept_mutex */ + 128; /* ngx_connection_counter */ +#if 0 shared = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); if (shared == MAP_FAILED) { @@ -194,6 +195,11 @@ static ngx_int_t ngx_event_module_init(n "mmap(MAP_ANON|MAP_SHARED) failed"); return NGX_ERROR; } +#endif + + if (!(shared = ngx_create_shared_memory(size, cycle->log))) { + return NGX_ERROR; + } ngx_accept_mutex_ptr = (ngx_atomic_t *) shared; ngx_connection_counter = (ngx_atomic_t *) (shared + 128); @@ -611,7 +617,7 @@ static void *ngx_event_create_conf(ngx_c NGX_CONF_ERROR); ecf->connections = NGX_CONF_UNSET_UINT; - ecf->use = NGX_CONF_UNSET; + ecf->use = NGX_CONF_UNSET_UINT; ecf->multi_accept = NGX_CONF_UNSET; ecf->accept_mutex = NGX_CONF_UNSET; ecf->accept_mutex_delay = NGX_CONF_UNSET_MSEC; @@ -694,9 +700,9 @@ static char *ngx_event_init_conf(ngx_cyc return NGX_CONF_ERROR; } - ngx_conf_unsigned_init_value(ecf->connections, DEFAULT_CONNECTIONS); + ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS); - ngx_conf_unsigned_init_value(ecf->use, m); + ngx_conf_init_unsigned_value(ecf->use, m); ngx_conf_init_ptr_value(ecf->name, module->name->data); #endif diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -943,7 +943,8 @@ static ngx_int_t ngx_http_process_reques * in CPU cache */ - ua = ngx_strstr(r->headers_in.user_agent->value.data, "MSIE"); + ua = (u_char *) ngx_strstr(r->headers_in.user_agent->value.data, + "MSIE"); if (ua && ua + 8 < r->headers_in.user_agent->value.data + r->headers_in.user_agent->value.len) diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -41,11 +41,6 @@ #include /* TCP_CORK */ -/* Linux has no so autoconfigure does not find FIONBIO */ -#ifndef HAVE_FIONBIO -#define HAVE_FIONBIO 1 -#endif - #include diff --git a/src/os/unix/ngx_shared.c b/src/os/unix/ngx_shared.c new file mode 100644 --- /dev/null +++ b/src/os/unix/ngx_shared.c @@ -0,0 +1,91 @@ + +#include +#include + + +#if (HAVE_MAP_ANON) + +void *ngx_create_shared_memory(size_t size, ngx_log_t *log) +{ + void *p; + + p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); + + if (p == MAP_FAILED) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + "mmap(MAP_ANON|MAP_SHARED, " SIZE_T_FMT ") failed", + size); + return NULL; + } + + return p; +} + +#elif (HAVE_MAP_DEVZERO) + +void *ngx_create_shared_memory(size_t size, ngx_log_t *log) +{ + void *p; + ngx_fd_t fd; + + fd = open("/dev/zero", O_RDWR); + + if (fd == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + "open(/dev/zero) failed"); + return NULL; + } + + p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + + if (p == MAP_FAILED) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + "mmap(/dev/zero, MAP_SHARED, " SIZE_T_FMT ") failed", + size); + p = NULL; + } + + if (close(fd) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() failed"); + } + + return p; +} + +#elif (HAVE_SYSVSHM) + +#include +#include + + +void *ngx_create_shared_memory(size_t size, ngx_log_t *log) +{ + int id; + void *p; + + id = shmget(IPC_PRIVATE, size, (SHM_R|SHM_W|IPC_CREAT)); + + if (id == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + "shmget(" SIZE_T_FMT ") failed", size); + return NULL; + } + + ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "shmget id: %d", id); + + p = shmat(id, NULL, 0); + + if (p == (void *) -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmat() failed"); + p = NULL; + } + + if (shmctl(id, IPC_RMID, NULL) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "shmctl(IPC_RMID) failed"); + p = NULL; + } + + return p; +} + +#endif diff --git a/src/os/unix/ngx_shared.h b/src/os/unix/ngx_shared.h new file mode 100644 --- /dev/null +++ b/src/os/unix/ngx_shared.h @@ -0,0 +1,12 @@ +#ifndef _NGX_SHARED_H_INCLUDED_ +#define _NGX_SHARED_H_INCLUDED_ + + +#include +#include + + +void *ngx_create_shared_memory(size_t size, ngx_log_t *log); + + +#endif /* _NGX_SHARED_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h --- a/src/os/unix/ngx_time.h +++ b/src/os/unix/ngx_time.h @@ -9,7 +9,6 @@ typedef uint64_t ngx_epoch_msec_t; typedef ngx_int_t ngx_msec_t; -#define NGX_MAX_MSEC (ngx_msec_t) -1 typedef struct tm ngx_tm_t; @@ -20,11 +19,7 @@ typedef struct tm ngx_tm_t; #define ngx_tm_mon tm_mon #define ngx_tm_year tm_year #define ngx_tm_wday tm_wday -#define ngx_tm_gmtoff tm_gmtoff - -#ifndef SOLARIS -#define ngx_tm_zone tm_zone -#endif +#define ngx_tm_isdst tm_isdst #define ngx_tm_sec_t int #define ngx_tm_min_t int @@ -35,16 +30,14 @@ typedef struct tm ngx_tm_t; #define ngx_tm_wday_t int -#if (SOLARIS) -#define HAVE_TIMEZONE 1 - -#define ngx_timezone() (- (daylight ? altzone : timezone) / 60) +#if (HAVE_GMTOFF) +#define ngx_tm_gmtoff tm_gmtoff +#define ngx_tm_zone tm_zone +#endif -#elif defined __linux__ -#define HAVE_TIMEZONE 1 -#define ngx_timezone() (- timezone / 60 + daylight * 60) - +#if (SOLARIS) +#define ngx_timezone(isdst) (- (isdst ? altzone : timezone) / 60) #endif diff --git a/src/os/win32/ngx_shared.h b/src/os/win32/ngx_shared.h new file mode 100644 --- /dev/null +++ b/src/os/win32/ngx_shared.h @@ -0,0 +1,12 @@ +#ifndef _NGX_SHARED_H_INCLUDED_ +#define _NGX_SHARED_H_INCLUDED_ + + +#include +#include + + +void *ngx_create_shared_memory(size_t size, ngx_log_t *log); + + +#endif /* _NGX_SHARED_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_time.c b/src/os/win32/ngx_time.c --- a/src/os/win32/ngx_time.c +++ b/src/os/win32/ngx_time.c @@ -31,7 +31,7 @@ void ngx_gettimeofday(struct timeval *tp } -ngx_int_t ngx_timezone(void) +ngx_int_t ngx_gettimezone(void) { TIME_ZONE_INFORMATION tz; diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h --- a/src/os/win32/ngx_time.h +++ b/src/os/win32/ngx_time.h @@ -9,7 +9,6 @@ typedef uint64_t ngx_epoch_msec_t; typedef ngx_int_t ngx_msec_t; -#define NGX_MAX_MSEC (ngx_msec_t) -1 typedef SYSTEMTIME ngx_tm_t; @@ -32,11 +31,11 @@ typedef FILETIME ngx_mtime_t; #define ngx_tm_wday_t u_short -#define ngx_msleep Sleep +#define ngx_msleep Sleep -#define HAVE_TIMEZONE 1 +#define HAVE_GETIMEZONE 1 -ngx_int_t ngx_timezone(void); +ngx_int_t ngx_gettimezone(void); void ngx_gettimeofday(struct timeval *tp);