diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/nginx.c | 20 | ||||
| -rw-r--r-- | src/core/ngx_cycle.c | 64 | ||||
| -rw-r--r-- | src/core/ngx_cycle.h | 1 |
3 files changed, 65 insertions, 20 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 566f8f977..28fffa040 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -188,9 +188,7 @@ static ngx_uint_t ngx_show_version; static ngx_uint_t ngx_show_configure; static u_char *ngx_conf_file; static u_char *ngx_conf_params; -#if (NGX_WIN32) static char *ngx_signal; -#endif static char **ngx_os_environ; @@ -213,20 +211,16 @@ main(int argc, char *const *argv) if (ngx_show_help) { ngx_log_stderr( - "Usage: nginx [-?hvVt]" -#if (NGX_WIN32) - " [-s signal]" -#endif - " [-c filename] [-g directives]" CRLF CRLF + "Usage: nginx [-?hvVt] [-s signal] [-c filename] " + "[-g directives]" CRLF CRLF "Options:" CRLF " -?,-h : this help" CRLF " -v : show version and exit" CRLF " -V : show version and configure options then exit" CRLF " -t : test configuration and exit" CRLF -#if (NGX_WIN32) - " -s signal : send signal to a master process" CRLF -#endif + " -s signal : send signal to a master process: " + "stop, quit, reopen, reload" CRLF " -c filename : set configuration file (default: " NGX_CONF_PATH ")" CRLF " -g directives : set global directives out of configuration " @@ -337,13 +331,11 @@ main(int argc, char *const *argv) ngx_process = NGX_PROCESS_MASTER; } -#if (NGX_WIN32) - if (ngx_signal) { return ngx_signal_process(cycle, ngx_signal); } -#else +#if !(NGX_WIN32) if (ngx_init_signals(cycle->log) != NGX_OK) { return 1; @@ -685,7 +677,6 @@ ngx_get_options(int argc, char *const *argv) ngx_log_stderr("the option \"-g\" requires parameter"); return NGX_ERROR; -#if (NGX_WIN32) case 's': if (*p) { ngx_signal = (char *) p; @@ -709,7 +700,6 @@ ngx_get_options(int argc, char *const *argv) ngx_log_stderr("invalid option: \"-s %s\"", ngx_signal); return NGX_ERROR; -#endif default: ngx_log_stderr("invalid option: \"%c\"", *(p - 1)); diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c index eae4c8369..476ba8328 100644 --- a/src/core/ngx_cycle.c +++ b/src/core/ngx_cycle.c @@ -569,12 +569,14 @@ ngx_init_cycle(ngx_cycle_t *old_cycle) } } - if (ngx_open_listening_sockets(cycle) != NGX_OK) { - goto failed; - } + if (ngx_process != NGX_PROCESS_SIGNALLER) { + if (ngx_open_listening_sockets(cycle) != NGX_OK) { + goto failed; + } - if (!ngx_test_config) { - ngx_configure_listening_socket(cycle); + if (!ngx_test_config) { + ngx_configure_listening_socket(cycle); + } } @@ -986,6 +988,58 @@ ngx_delete_pidfile(ngx_cycle_t *cycle) } +ngx_int_t +ngx_signal_process(ngx_cycle_t *cycle, char *sig) +{ + ssize_t n; + ngx_int_t pid; + ngx_file_t file; + ngx_core_conf_t *ccf; + u_char buf[NGX_INT64_LEN + 2]; + + ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "signal process started"); + + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + + file.name = ccf->pid; + file.log = cycle->log; + + file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY, + NGX_FILE_OPEN, NGX_FILE_DEFAULT_ACCESS); + + if (file.fd == NGX_INVALID_FILE) { + ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, + ngx_open_file_n " \"%s\" failed", file.name.data); + return 1; + } + + n = ngx_read_file(&file, buf, NGX_INT64_LEN + 2, 0); + + if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_close_file_n " \"%s\" failed", file.name.data); + } + + if (n == NGX_ERROR) { + return 1; + } + + while (n-- && (buf[n] == CR || buf[n] == LF)) { /* void */ } + + pid = ngx_atoi(buf, ++n); + + if (pid == NGX_ERROR) { + ngx_log_error(NGX_LOG_ERR, cycle->log, 0, + "invalid PID number \"%*s\" in \"%s\"", + n, buf, file.name.data); + return 1; + } + + return ngx_os_signal_process(cycle, sig, pid); + +} + + static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log) { diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h index e7d611695..6ce297410 100644 --- a/src/core/ngx_cycle.h +++ b/src/core/ngx_cycle.h @@ -116,6 +116,7 @@ typedef struct { ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle); ngx_int_t ngx_create_pidfile(ngx_str_t *name, ngx_log_t *log); void ngx_delete_pidfile(ngx_cycle_t *cycle); +ngx_int_t ngx_signal_process(ngx_cycle_t *cycle, char *sig); void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user); char **ngx_set_environment(ngx_cycle_t *cycle, ngx_uint_t *last); ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv); |
