aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix/ngx_process.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2011-11-23 14:09:19 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2011-11-23 14:09:19 +0000
commit13717da19e52fb0b43b25ebfdb9bab1bc0a71ce4 (patch)
tree2a1753008729ab59ac1bd957ed0c5d4c2e3d0e18 /src/os/unix/ngx_process.c
parentddb7cd1c410a7166d8e28092d714f782ed1d69b3 (diff)
downloadnginx-13717da19e52fb0b43b25ebfdb9bab1bc0a71ce4.tar.gz
nginx-13717da19e52fb0b43b25ebfdb9bab1bc0a71ce4.zip
Unlock of shared memory zones on process crash.
If process exited abnormally while holding lock on some shared memory zone - unlock it. It may be not safe thing to do (as crash with lock held may result in corrupted shared memory structure, and other processes will subsequently crash while trying to access shared data), therefore complain loudly if unlock succeeds.
Diffstat (limited to 'src/os/unix/ngx_process.c')
-rw-r--r--src/os/unix/ngx_process.c61
1 files changed, 50 insertions, 11 deletions
diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c
index cbdae8be1..9f1936bd1 100644
--- a/src/os/unix/ngx_process.c
+++ b/src/os/unix/ngx_process.c
@@ -22,6 +22,7 @@ typedef struct {
static void ngx_execute_proc(ngx_cycle_t *cycle, void *data);
static void ngx_signal_handler(int signo);
static void ngx_process_get_status(void);
+static void ngx_unlock_mutexes(ngx_pid_t pid);
int ngx_argc;
@@ -497,17 +498,6 @@ ngx_process_get_status(void)
}
- if (ngx_accept_mutex_ptr) {
-
- /*
- * unlock the accept mutex if the abnormally exited process
- * held it
- */
-
- ngx_shmtx_force_unlock(&ngx_accept_mutex, pid);
- }
-
-
one = 1;
process = "unknown process";
@@ -545,6 +535,55 @@ ngx_process_get_status(void)
process, pid, WEXITSTATUS(status));
ngx_processes[i].respawn = 0;
}
+
+ ngx_unlock_mutexes(pid);
+ }
+}
+
+
+static void
+ngx_unlock_mutexes(ngx_pid_t pid)
+{
+ ngx_uint_t i;
+ ngx_shm_zone_t *shm_zone;
+ ngx_list_part_t *part;
+ ngx_slab_pool_t *sp;
+
+ /*
+ * unlock the accept mutex if the abnormally exited process
+ * held it
+ */
+
+ if (ngx_accept_mutex_ptr) {
+ ngx_shmtx_force_unlock(&ngx_accept_mutex, pid);
+ }
+
+ /*
+ * unlock shared memory mutexes if held by the abnormally exited
+ * process
+ */
+
+ part = (ngx_list_part_t *) &ngx_cycle->shared_memory.part;
+ shm_zone = part->elts;
+
+ for (i = 0; /* void */ ; i++) {
+
+ if (i >= part->nelts) {
+ if (part->next == NULL) {
+ break;
+ }
+ part = part->next;
+ shm_zone = part->elts;
+ i = 0;
+ }
+
+ sp = (ngx_slab_pool_t *) shm_zone[i].shm.addr;
+
+ if (ngx_shmtx_force_unlock(&sp->mutex, pid)) {
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
+ "shared memory zone \"%V\" was locked by %P",
+ &shm_zone[i].shm.name, pid);
+ }
}
}