summaryrefslogtreecommitdiffhomepage
path: root/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/os')
-rw-r--r--src/os/win32/ngx_files.c12
-rw-r--r--src/os/win32/ngx_process.c22
-rw-r--r--src/os/win32/ngx_process_cycle.c25
-rw-r--r--src/os/win32/ngx_shmem.c35
4 files changed, 65 insertions, 29 deletions
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index 4397b28a0..b6f9bb645 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -269,7 +269,7 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
for ( ;; ) {
num = ngx_next_temp_number(collision);
- ngx_sprintf(name + to->len, ".%0muA.DELETE", num);
+ ngx_sprintf(name + to->len, ".%0muA.DELETE%Z", num);
if (MoveFile((const char *) to->data, (const char *) name) != 0) {
break;
@@ -277,7 +277,8 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
collision = 1;
- ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, "MoveFile() failed");
+ ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
+ "MoveFile() \"%s\" to \"%s\" failed", to->data, name);
}
if (MoveFile((const char *) from->data, (const char *) to->data) == 0) {
@@ -288,11 +289,14 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
}
if (DeleteFile((const char *) name) == 0) {
- ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, "DeleteFile() failed");
+ ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
+ "DeleteFile() \"%s\" failed", name);
}
if (rc == NGX_ERROR) {
- ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, "MoveFile() failed");
+ ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
+ "MoveFile() \"%s\" to \"%s\" failed",
+ from->data, to->data);
}
/* mutex_unlock() */
diff --git a/src/os/win32/ngx_process.c b/src/os/win32/ngx_process.c
index bbc7afa9e..e7c283612 100644
--- a/src/os/win32/ngx_process.c
+++ b/src/os/win32/ngx_process.c
@@ -19,10 +19,11 @@ ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
ngx_pid_t
ngx_spawn_process(ngx_cycle_t *cycle, char *name, ngx_int_t respawn)
{
- u_long rc, n;
+ u_long rc, n, code;
ngx_int_t s;
ngx_pid_t pid;
ngx_exec_ctx_t ctx;
+ HANDLE events[2];
char file[MAX_PATH + 1];
if (respawn >= 0) {
@@ -79,12 +80,15 @@ ngx_spawn_process(ngx_cycle_t *cycle, char *name, ngx_int_t respawn)
ngx_sprintf(ngx_processes[s].reopen_event, "ngx_%s_reopen_%ul%Z",
name, pid);
- rc = WaitForSingleObject(ngx_master_process_event, 5000);
+ events[0] = ngx_master_process_event;
+ events[1] = ctx.child;
+
+ rc = WaitForMultipleObjects(2, events, 0, 5000);
ngx_time_update(0, 0);
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "WaitForSingleObject: %ul", rc);
+ "WaitForMultipleObjects: %ul", rc);
switch (rc) {
@@ -126,6 +130,18 @@ ngx_spawn_process(ngx_cycle_t *cycle, char *name, ngx_int_t respawn)
break;
+ case WAIT_OBJECT_0 + 1:
+ if (GetExitCodeProcess(ctx.child, &code) == 0) {
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "GetExitCodeProcess(%P) failed", pid);
+ }
+
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
+ "%s process %P exited with code %Xul",
+ name, pid, code);
+
+ goto failed;
+
case WAIT_TIMEOUT:
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"the event \"%s\" was not signaled for 5s",
diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c
index d4fba8b3c..12b13d17e 100644
--- a/src/os/win32/ngx_process_cycle.c
+++ b/src/os/win32/ngx_process_cycle.c
@@ -14,7 +14,7 @@ static void ngx_process_init(ngx_cycle_t *cycle);
static void ngx_console_init(ngx_cycle_t *cycle);
static int __stdcall ngx_console_handler(u_long type);
static ngx_int_t ngx_create_events(ngx_cycle_t *cycle);
-static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t type);
+static ngx_int_t ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t type);
static void ngx_reopen_worker_processes(ngx_cycle_t *cycle);
static void ngx_quit_worker_processes(ngx_cycle_t *cycle, ngx_uint_t old);
static void ngx_terminate_worker_processes(ngx_cycle_t *cycle);
@@ -116,7 +116,9 @@ ngx_master_process_cycle(ngx_cycle_t *cycle)
ngx_close_listening_sockets(cycle);
- ngx_start_worker_processes(cycle, NGX_PROCESS_RESPAWN);
+ if (ngx_start_worker_processes(cycle, NGX_PROCESS_RESPAWN) == 0) {
+ exit(2);
+ }
timer = 0;
timeout = INFINITE;
@@ -206,8 +208,11 @@ ngx_master_process_cycle(ngx_cycle_t *cycle)
ngx_cycle = cycle;
- ngx_start_worker_processes(cycle, NGX_PROCESS_JUST_RESPAWN);
- ngx_quit_worker_processes(cycle, 1);
+ ngx_close_listening_sockets(cycle);
+
+ if (ngx_start_worker_processes(cycle, NGX_PROCESS_JUST_RESPAWN)) {
+ ngx_quit_worker_processes(cycle, 1);
+ }
continue;
}
@@ -382,7 +387,7 @@ ngx_create_events(ngx_cycle_t *cycle)
}
-static void
+static ngx_int_t
ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t type)
{
ngx_int_t n;
@@ -394,9 +399,11 @@ ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t type)
for (n = 0; n < ccf->worker_processes; n++) {
if (ngx_spawn_process(cycle, "worker", type) == NGX_INVALID_PID) {
- return;
+ break;
}
}
+
+ return n;
}
@@ -428,7 +435,7 @@ ngx_quit_worker_processes(ngx_cycle_t *cycle, ngx_uint_t old)
for (n = 0; n < ngx_last_process; n++) {
ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "process: %d %P %p e:%d t:%d r:%d j:%d",
+ "process: %d %P %p e:%d j:%d",
n,
ngx_processes[n].pid,
ngx_processes[n].handle,
@@ -495,7 +502,7 @@ ngx_reap_worker(ngx_cycle_t *cycle, HANDLE h)
}
if (GetExitCodeProcess(h, &code) == 0) {
- ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"GetExitCodeProcess(%P) failed",
ngx_processes[n].pid);
}
@@ -538,7 +545,7 @@ found:
for (n = 0; n < ngx_last_process; n++) {
ngx_log_debug5(NGX_LOG_DEBUG_CORE, cycle->log, 0,
- "process: %d %P %p e:%d t:%d r:%d j:%d",
+ "process: %d %P %p e:%d j:%d",
n,
ngx_processes[n].pid,
ngx_processes[n].handle,
diff --git a/src/os/win32/ngx_shmem.c b/src/os/win32/ngx_shmem.c
index 667e37eaf..e4b357a97 100644
--- a/src/os/win32/ngx_shmem.c
+++ b/src/os/win32/ngx_shmem.c
@@ -11,27 +11,36 @@
ngx_int_t
ngx_shm_alloc(ngx_shm_t *shm)
{
- u_char *name;
+ u_char *name;
+ uint64_t size;
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);
+ (void) ngx_sprintf(name, "%V_%s%Z", &shm->name, ngx_unique);
ngx_set_errno(0);
+ size = shm->size;
+
shm->handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
- 0, shm->size, (char *) name);
+ (u_long) (size >> 32),
+ (u_long) (size & 0xffffffff),
+ (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);
- goto failed;
+ shm->size, name);
+ ngx_free(name);
+
+ return NGX_ERROR;
}
+ ngx_free(name);
+
if (ngx_errno == ERROR_ALREADY_EXISTS) {
shm->exists = 1;
}
@@ -43,17 +52,15 @@ ngx_shm_alloc(ngx_shm_t *shm)
}
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
- "MapViewOfFile(%uz) failed", shm->size);
+ "MapViewOfFile(%uz) of file mapping \"%V\" failed",
+ shm->size, &shm->name);
if (CloseHandle(shm->handle) == 0) {
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
- "CloseHandle() failed");
+ "CloseHandle() of file mapping \"%V\" failed",
+ &shm->name);
}
-failed:
-
- ngx_free(name);
-
return NGX_ERROR;
}
@@ -63,11 +70,13 @@ ngx_shm_free(ngx_shm_t *shm)
{
if (UnmapViewOfFile(shm->addr) == 0) {
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
- "UnmapViewOfFile(%p) failed", shm->addr);
+ "UnmapViewOfFile(%p) of file mapping \"%V\" failed",
+ shm->addr, &shm->name);
}
if (CloseHandle(shm->handle) == 0) {
ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno,
- "CloseHandle() failed");
+ "CloseHandle() of file mapping \"%V\" failed",
+ &shm->name);
}
}