diff options
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/unix/ngx_linux_config.h | 5 | ||||
-rw-r--r-- | src/os/unix/ngx_shared.c | 91 | ||||
-rw-r--r-- | src/os/unix/ngx_shared.h | 12 | ||||
-rw-r--r-- | src/os/unix/ngx_time.h | 21 | ||||
-rw-r--r-- | src/os/win32/ngx_shared.h | 12 | ||||
-rw-r--r-- | src/os/win32/ngx_time.c | 2 | ||||
-rw-r--r-- | src/os/win32/ngx_time.h | 7 |
7 files changed, 126 insertions, 24 deletions
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h index 2b6eb9cb3..8a75e229f 100644 --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -41,11 +41,6 @@ #include <netinet/tcp.h> /* TCP_CORK */ -/* Linux has no <sys/filio.h> so autoconfigure does not find FIONBIO */ -#ifndef HAVE_FIONBIO -#define HAVE_FIONBIO 1 -#endif - #include <ngx_auto_config.h> diff --git a/src/os/unix/ngx_shared.c b/src/os/unix/ngx_shared.c new file mode 100644 index 000000000..a19ca5315 --- /dev/null +++ b/src/os/unix/ngx_shared.c @@ -0,0 +1,91 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +#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 <sys/ipc.h> +#include <sys/shm.h> + + +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 index 000000000..ca077df42 --- /dev/null +++ b/src/os/unix/ngx_shared.h @@ -0,0 +1,12 @@ +#ifndef _NGX_SHARED_H_INCLUDED_ +#define _NGX_SHARED_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +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 index dbb7a0a54..7cf3d01af 100644 --- 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) - -#elif defined __linux__ -#define HAVE_TIMEZONE 1 +#if (HAVE_GMTOFF) +#define ngx_tm_gmtoff tm_gmtoff +#define ngx_tm_zone tm_zone +#endif -#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 index 000000000..ca077df42 --- /dev/null +++ b/src/os/win32/ngx_shared.h @@ -0,0 +1,12 @@ +#ifndef _NGX_SHARED_H_INCLUDED_ +#define _NGX_SHARED_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +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 index cef335707..85d1a3b6d 100644 --- 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 index 9ed94baeb..f86011618 100644 --- 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); |