diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-06-17 17:18:53 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-06-17 17:18:53 +0000 |
commit | 415b1ce1b93a3b74efe8a3ee5a35ee55e0a11caa (patch) | |
tree | 077bf24b4f310a87ab8bff140c730cb679069988 /src/os/unix | |
parent | f924e6b694db7fd1d99473b3d7db7eb2b49c9e62 (diff) | |
download | nginx-415b1ce1b93a3b74efe8a3ee5a35ee55e0a11caa.tar.gz nginx-415b1ce1b93a3b74efe8a3ee5a35ee55e0a11caa.zip |
nginx-0.0.7-2004-06-17-21:18:53 import
Diffstat (limited to 'src/os/unix')
-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 |
4 files changed, 110 insertions, 19 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 |