ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr, u_char *name) { if (mtx->name) { if (ngx_strcmp(name, mtx->name) == 0) { mtx->name = name; return NGX_OK; } ngx_shmtx_destroy(mtx); } mtx->fd = ngx_open_file(name, NGX_FILE_RDWR, NGX_FILE_CREATE_OR_OPEN, NGX_FILE_DEFAULT_ACCESS); if (mtx->fd == NGX_INVALID_FILE) { ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, ngx_errno, ngx_open_file_n " \"%s\" failed", name); return NGX_ERROR; } if (ngx_delete_file(name) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, ngx_delete_file_n " \"%s\" failed", name); } mtx->name = name; return NGX_OK; }
static ngx_int_t __ngx_http_session_delete(ngx_http_session_t *session) { ngx_int_t ret; ngx_http_session_list_t *session_list; session_list = ngx_http_session_shm_zone->data; if (!session->ref) { if (!session->next && !session->prev) { /* the only node in the chain */ *(session->slot) = NULL; } else if (!session->prev && session->next) { /* first node in the chain */ *(session->slot) = session->next; ((ngx_http_session_t *)(session->next))->prev = NULL; ((ngx_http_session_t *)(session->next))->slot = session->slot; } else if (session->next && session->prev) { /* node in the middle */ ((ngx_http_session_t *)(session->prev))->next = session->next; ((ngx_http_session_t *)(session->next))->prev = session->prev; } else if (session->prev && !session->next) { /* last node in the chain */ ((ngx_http_session_t *)(session->prev))->next = NULL; } session->next = session->prev = NULL; if (session->ev.timer_set) { ngx_del_timer(&session->ev); } if (!ngx_queue_empty(&session->redirect_queue_node)) { ngx_queue_remove(&session->redirect_queue_node); session_list->redirect_num--; } __ngx_http_session_ctx_delete(session); ngx_shmtx_destroy(&session->mutex); ngx_slab_free_locked(session_list->shpool, session); ret = NGX_OK; } else { ret = NGX_ERROR; } return ret; }