summaryrefslogtreecommitdiffhomepage
path: root/src/os/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/win32')
-rw-r--r--src/os/win32/ngx_os.h1
-rw-r--r--src/os/win32/ngx_shmem.c41
-rw-r--r--src/os/win32/ngx_shmem.h11
-rw-r--r--src/os/win32/ngx_win32_init.c19
4 files changed, 56 insertions, 16 deletions
diff --git a/src/os/win32/ngx_os.h b/src/os/win32/ngx_os.h
index 93ec3ffaa..2124ab8d7 100644
--- a/src/os/win32/ngx_os.h
+++ b/src/os/win32/ngx_os.h
@@ -54,6 +54,7 @@ extern ngx_uint_t ngx_inherited_nonblocking;
extern ngx_uint_t ngx_tcp_nodelay_and_tcp_nopush;
extern ngx_uint_t ngx_win32_version;
extern ngx_fd_t ngx_stderr_fileno;
+extern char ngx_unique[];
diff --git a/src/os/win32/ngx_shmem.c b/src/os/win32/ngx_shmem.c
index 62e8585d0..12837f74c 100644
--- a/src/os/win32/ngx_shmem.c
+++ b/src/os/win32/ngx_shmem.c
@@ -11,31 +11,50 @@
ngx_int_t
ngx_shm_alloc(ngx_shm_t *shm)
{
+ u_char *name;
+
+ name = ngx_alloc(shm->name.len + 2 + sizeof(NGX_INT32_LEN), shm->log);
+ if (name == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_sprintf(name, "%V_%s%Z", &shm->name, ngx_unique);
+
+ ngx_set_errno(0);
+
shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
- 0, shm->size, (char *) shm->name.data);
+ 0, shm->size, (char *) name);
if (shm->handle == NULL) {
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
"CreateFileMapping(%uz, %s) failed",
shm->size, shm->name.data);
- return NGX_ERROR;
+ goto failed;
+ }
+
+ if (ngx_errno == ERROR_ALREADY_EXISTS) {
+ shm->exists = 1;
}
shm->addr = MapViewOfFile(shm->handle, FILE_MAP_WRITE, 0, 0, 0);
- if (shm->addr == NULL) {
- ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
- "MapViewOfFile(%uz) failed", shm->size);
+ if (shm->addr != NULL) {
+ return NGX_OK;
+ }
- if (CloseHandle(shm->handle) == 0) {
- ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
- "CloseHandle() failed");
- }
+ ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
+ "MapViewOfFile(%uz) failed", shm->size);
- return NGX_ERROR;
+ if (CloseHandle(shm->handle) == 0) {
+ ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
+ "CloseHandle() failed");
}
- return NGX_OK;
+failed:
+
+ ngx_free(name);
+
+ return NGX_ERROR;
}
diff --git a/src/os/win32/ngx_shmem.h b/src/os/win32/ngx_shmem.h
index 7bd6d6265..57271a443 100644
--- a/src/os/win32/ngx_shmem.h
+++ b/src/os/win32/ngx_shmem.h
@@ -13,11 +13,12 @@
typedef struct {
- u_char *addr;
- size_t size;
- ngx_str_t name;
- HANDLE handle;
- ngx_log_t *log;
+ u_char *addr;
+ size_t size;
+ ngx_str_t name;
+ HANDLE handle;
+ ngx_log_t *log;
+ ngx_uint_t exists; /* unsigned exists:1; */
} ngx_shm_t;
diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c
index 5ceb7a84b..f451311ce 100644
--- a/src/os/win32/ngx_win32_init.c
+++ b/src/os/win32/ngx_win32_init.c
@@ -17,6 +17,7 @@ ngx_uint_t ngx_inherited_nonblocking = 1;
ngx_uint_t ngx_tcp_nodelay_and_tcp_nopush;
ngx_fd_t ngx_stderr_fileno;
+char ngx_unique[NGX_INT32_LEN + 1];
ngx_os_io_t ngx_os_io = {
@@ -60,6 +61,7 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
DWORD bytes;
SOCKET s;
WSADATA wsd;
+ ngx_err_t err;
ngx_uint_t n;
SYSTEM_INFO si;
@@ -205,6 +207,23 @@ ngx_int_t ngx_os_init(ngx_log_t *log)
ngx_close_socket_n " failed");
}
+ if (GetEnvironmentVariable("nginx_unique", ngx_unique, NGX_INT32_LEN + 1)
+ != 0)
+ {
+ ngx_process = NGX_PROCESS_WORKER;
+
+ } else {
+ err = ngx_errno;
+
+ if (err != ERROR_ENVVAR_NOT_FOUND) {
+ ngx_log_error(NGX_LOG_EMERG, log, err,
+ "GetEnvironmentVariable(\"nginx_unique\") failed");
+ return NGX_ERROR;
+ }
+
+ ngx_sprintf((u_char *) ngx_unique, "%P%Z", ngx_pid);
+ }
+
return NGX_OK;
}