Mercurial > hg > nginx
diff src/core/nginx.c @ 210:00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 14 Dec 2003 20:10:27 +0000 |
parents | e1c815be05ae |
children | 679f60139863 |
line wrap: on
line diff
--- a/src/core/nginx.c Tue Dec 09 15:08:11 2003 +0000 +++ b/src/core/nginx.c Sun Dec 14 20:10:27 2003 +0000 @@ -16,7 +16,8 @@ typedef struct { - int daemon; + int daemon; + ngx_str_t pid; } ngx_core_conf_t; @@ -61,6 +62,7 @@ u_int ngx_connection_counter; +int done; int restart; int rotate; @@ -73,6 +75,9 @@ ngx_cycle_t *cycle; ngx_open_file_t *file; #if !(WIN32) + size_t len; + char pid[/* STUB */ 10]; + ngx_file_t pidfile; ngx_core_conf_t *ccf; #endif @@ -119,6 +124,33 @@ return 1; } + if (ccf->pid.len == 0) { + ccf->pid.len = sizeof(NGINX_PID) - 1; + ccf->pid.data = NGINX_PID; + } + + len = ngx_snprintf(pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); + ngx_memzero(&pidfile, sizeof(ngx_file_t)); + pidfile.name = ccf->pid; + + pidfile.fd = ngx_open_file(pidfile.name.data, NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN); + + if (pidfile.fd == NGX_INVALID_FILE) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + ngx_open_file_n " \"%s\" failed", pidfile.name.data); + return 1; + } + + if (ngx_write_file(&pidfile, pid, len, 0) == NGX_ERROR) { + return 1; + } + + if (ngx_close_file(pidfile.fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_close_file_n " \"%s\" failed", pidfile.name.data); + } + #endif /* life cycle */ @@ -162,8 +194,20 @@ ngx_process_events(cycle->log); + if (done) { + if (ngx_delete_file(pidfile.name.data) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_delete_file_n " \"%s\" failed", + pidfile.name.data); + } + + ngx_log_error(NGX_LOG_INFO, + cycle->log, 0, "exiting"); + exit(0); + } + if (rotate) { - ngx_log_debug(cycle->log, "rotate"); + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "rotating logs"); file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { @@ -313,6 +357,10 @@ ngx_destroy_pool(pool); return NULL; } + /* set by pcalloc() + * + * ccf->pid = NULL; + */ ccf->daemon = -1; ((void **)(cycle->conf_ctx))[ngx_core_module.index] = ccf;