diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-04-12 10:10:53 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-04-12 10:10:53 +0400 |
commit | 076498e356546713a4b40edea95bcc1a30c45a98 (patch) | |
tree | a0746df46e5c2bc25873d59de6b388a77ee08a8e /src/os/unix/ngx_process_cycle.c | |
parent | 407b0deeaf8455b220f0fdc5754d599dd3830a46 (diff) |
nginx-0.0.3-2004-04-12-10:10:53 import
Diffstat (limited to 'src/os/unix/ngx_process_cycle.c')
-rw-r--r-- | src/os/unix/ngx_process_cycle.c | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 2797670df..1b10cfc72 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -12,6 +12,8 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); static int ngx_worker_thread_cycle(void *data); #endif +static void ngx_delete_pidfile(ngx_cycle_t *cycle); + ngx_int_t ngx_process; ngx_pid_t ngx_pid; @@ -336,21 +338,10 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) { - u_char *name; - - if (ngx_inherited && getppid() > 1) { - name = ctx->pid.name.data; - - } else { - name = ctx->name; - } - - if (ngx_delete_file(name) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, - ngx_delete_file_n " \"%s\" failed", name); - } + ngx_delete_pidfile(cycle); ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); + exit(0); } @@ -535,31 +526,44 @@ int ngx_worker_thread_cycle(void *data) #endif -static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) +static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) { size_t len; u_char pid[NGX_INT64_LEN + 1]; + ngx_str_t name; ngx_core_conf_t *ccf; ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + if (ctx->pid.len) { + if (ccf->pid.len == 0) { + return NGX_OK; + } + + if (ctx->pid.len == ccf->pid.len + && ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0) + { + return NGX_OK; + } + } + if (ccf->pid.len == 0) { ccf->pid.len = sizeof(NGINX_PID) - 1; ccf->pid.data = NGINX_PID; - ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1; - ccf->newpid.data = NGINX_NEW_PID; + ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; + ccf->newpid.data = NGINX_NEWPID; } else { - ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT); + ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { return NGX_ERROR; } ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), - NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT)); + NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); } - len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); + len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; ctx->name = ccf->pid.data; @@ -584,3 +588,24 @@ static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) return NGX_OK; } + + +static void ngx_delete_pidfile(ngx_cycle_t *cycle) +{ + u_char *name; + ngx_core_conf_t *ccf; + + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + + if (ngx_inherited && getppid() > 1) { + name = ccf->newpid.data; + + } else { + name = ccf->pid.data; + } + + if (ngx_delete_file(name) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_delete_file_n " \"%s\" failed", name); + } +} |