diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nginx.c | 100 | ||||
-rw-r--r-- | src/core/ngx_connection.c | 32 | ||||
-rw-r--r-- | src/core/ngx_cycle.c | 12 | ||||
-rw-r--r-- | src/core/ngx_log.c | 6 |
4 files changed, 85 insertions, 65 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index a542eca74..cfc2337f1 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -180,10 +180,14 @@ ngx_module_t ngx_core_module = { }; -ngx_uint_t ngx_max_module; +ngx_uint_t ngx_max_module; + +static ngx_uint_t ngx_show_version; +static ngx_uint_t ngx_show_configure; +#if (NGX_WIN32) +static char *ngx_signal; +#endif -static ngx_uint_t ngx_show_version; -static ngx_uint_t ngx_show_configure; static char **ngx_os_environ; @@ -303,22 +307,15 @@ main(int argc, char *const *argv) ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); - ngx_process = ccf->master ? NGX_PROCESS_MASTER : NGX_PROCESS_SINGLE; + if (ccf->master && ngx_process == NGX_PROCESS_SINGLE) { + ngx_process = NGX_PROCESS_MASTER; + } #if (NGX_WIN32) -#if 0 - - TODO: - - if (ccf->run_as_service) { - if (ngx_service(cycle->log) != NGX_OK) { - return 1; - } - - return 0; + if (ngx_signal) { + return ngx_signal_process(cycle, ngx_signal); } -#endif #else @@ -334,17 +331,17 @@ main(int argc, char *const *argv) ngx_daemonized = 1; } +#endif + if (ngx_create_pidfile(&ccf->pid, cycle->log) != NGX_OK) { return 1; } -#endif - - if (ngx_process == NGX_PROCESS_MASTER) { - ngx_master_process_cycle(cycle); + if (ngx_process == NGX_PROCESS_SINGLE) { + ngx_single_process_cycle(cycle); } else { - ngx_single_process_cycle(cycle); + ngx_master_process_cycle(cycle); } return 0; @@ -645,6 +642,29 @@ ngx_getopt(ngx_cycle_t *cycle, int argc, char *const *argv) cycle->conf_param.len = ngx_strlen(cycle->conf_param.data); break; +#if (NGX_WIN32) + case 's': + if (argv[++i] == NULL) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, + "the option \"-s\" requires parameter"); + return NGX_ERROR; + } + + if (ngx_strcmp(argv[i], "stop") == 0 + || ngx_strcmp(argv[i], "quit") == 0 + || ngx_strcmp(argv[i], "reopen") == 0 + || ngx_strcmp(argv[i], "reload") == 0) + { + ngx_process = NGX_PROCESS_SIGNALLER; + ngx_signal = argv[i]; + break; + } + + ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, + "invalid option: \"-s %s\"", argv[i]); + return NGX_ERROR; +#endif + default: ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "invalid option: \"%s\"", argv[i]); @@ -786,6 +806,27 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) #endif + + if (ccf->pid.len == 0) { + ccf->pid.len = sizeof(NGX_PID_PATH) - 1; + ccf->pid.data = (u_char *) NGX_PID_PATH; + } + + if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) { + return NGX_CONF_ERROR; + } + + ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT); + + ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len); + if (ccf->oldpid.data == NULL) { + return NGX_CONF_ERROR; + } + + ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len), + NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT)); + + #if !(NGX_WIN32) if (ccf->user == (uid_t) NGX_CONF_UNSET_UINT && geteuid() == 0) { @@ -814,25 +855,6 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf) ccf->group = grp->gr_gid; } - if (ccf->pid.len == 0) { - ccf->pid.len = sizeof(NGX_PID_PATH) - 1; - ccf->pid.data = (u_char *) NGX_PID_PATH; - } - - if (ngx_conf_full_name(cycle, &ccf->pid, 0) != NGX_OK) { - return NGX_CONF_ERROR; - } - - ccf->oldpid.len = ccf->pid.len + sizeof(NGX_OLDPID_EXT); - - ccf->oldpid.data = ngx_pnalloc(cycle->pool, ccf->oldpid.len); - if (ccf->oldpid.data == NULL) { - return NGX_CONF_ERROR; - } - - ngx_memcpy(ngx_cpymem(ccf->oldpid.data, ccf->pid.data, ccf->pid.len), - NGX_OLDPID_EXT, sizeof(NGX_OLDPID_EXT)); - if (ccf->lock_file.len == 0) { ccf->lock_file.len = sizeof(NGX_LOCK_PATH) - 1; diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index f413ffbe8..ed9efe754 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -557,28 +557,30 @@ ngx_close_listening_sockets(ngx_cycle_t *cycle) c = ls[i].connection; - if (c->read->active) { - if (ngx_event_flags & NGX_USE_RTSIG_EVENT) { - ngx_del_conn(c, NGX_CLOSE_EVENT); + if (c) { + if (c->read->active) { + if (ngx_event_flags & NGX_USE_RTSIG_EVENT) { + ngx_del_conn(c, NGX_CLOSE_EVENT); - } else if (ngx_event_flags & NGX_USE_EPOLL_EVENT) { + } else if (ngx_event_flags & NGX_USE_EPOLL_EVENT) { - /* - * it seems that Linux-2.6.x OpenVZ sends events - * for closed shared listening sockets unless - * the events was explicity deleted - */ + /* + * it seems that Linux-2.6.x OpenVZ sends events + * for closed shared listening sockets unless + * the events was explicity deleted + */ - ngx_del_event(c->read, NGX_READ_EVENT, 0); + ngx_del_event(c->read, NGX_READ_EVENT, 0); - } else { - ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT); + } else { + ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT); + } } - } - ngx_free_connection(c); + ngx_free_connection(c); - c->fd = (ngx_socket_t) -1; + c->fd = (ngx_socket_t) -1; + } ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, "close listening %V #%d ", &ls[i].addr_text, ls[i].fd); diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index d4186d358..2d829dd04 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -295,8 +295,6 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); -#if !(NGX_WIN32) - if (ngx_test_config) { if (ngx_create_pidfile(&ccf->pid, log) != NGX_OK) { @@ -325,8 +323,6 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) } } -#endif - if (ngx_test_lockfile(cycle->lock_file.data, log) != NGX_OK) { goto failed; @@ -928,8 +924,6 @@ ngx_init_zone_pool(ngx_cycle_t *cycle, ngx_shm_zone_t *zn) } -#if !(NGX_WIN32) - ngx_int_t ngx_create_pidfile(ngx_str_t *name, ngx_log_t *log) { @@ -938,6 +932,10 @@ ngx_create_pidfile(ngx_str_t *name, ngx_log_t *log) ngx_file_t file; u_char pid[NGX_INT64_LEN + 2]; + if (ngx_process > NGX_PROCESS_MASTER) { + return NGX_OK; + } + ngx_memzero(&file, sizeof(ngx_file_t)); file.name = *name; @@ -987,8 +985,6 @@ ngx_delete_pidfile(ngx_cycle_t *cycle) } } -#endif - static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log) diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index 35a24172e..8769bcdc6 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -227,9 +227,9 @@ ngx_log_init(void) NGX_FILE_DEFAULT_ACCESS); if (ngx_stderr.fd == NGX_INVALID_FILE) { - ngx_message_box("nginx", MB_OK, ngx_errno, - "Could not open error log file: " - ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed"); + ngx_event_log(ngx_errno, + "Could not open error log file: " + ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed"); return NULL; } |