diff options
Diffstat (limited to 'src/os')
| -rw-r--r-- | src/os/unix/ngx_os.h | 1 | ||||
| -rw-r--r-- | src/os/unix/ngx_process.c | 39 | ||||
| -rw-r--r-- | src/os/unix/ngx_process_cycle.h | 7 | ||||
| -rw-r--r-- | src/os/win32/ngx_os.h | 2 | ||||
| -rw-r--r-- | src/os/win32/ngx_process_cycle.c | 58 | ||||
| -rw-r--r-- | src/os/win32/ngx_process_cycle.h | 1 |
6 files changed, 47 insertions, 61 deletions
diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index 0dbdd0b3b..a83c6ed8f 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -37,6 +37,7 @@ void ngx_os_status(ngx_log_t *log); ngx_int_t ngx_os_specific_init(ngx_log_t *log); void ngx_os_specific_status(ngx_log_t *log); ngx_int_t ngx_daemon(ngx_log_t *log); +ngx_int_t ngx_os_signal_process(ngx_cycle_t *cycle, char *sig, ngx_int_t pid); ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size); diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index 18b2601af..7446c138b 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -13,6 +13,7 @@ typedef struct { int signo; char *signame; + char *name; void (*handler)(int signo); } ngx_signal_t; @@ -36,39 +37,45 @@ ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; ngx_signal_t signals[] = { { ngx_signal_value(NGX_RECONFIGURE_SIGNAL), "SIG" ngx_value(NGX_RECONFIGURE_SIGNAL), + "reload", ngx_signal_handler }, { ngx_signal_value(NGX_REOPEN_SIGNAL), "SIG" ngx_value(NGX_REOPEN_SIGNAL), + "reopen", ngx_signal_handler }, { ngx_signal_value(NGX_NOACCEPT_SIGNAL), "SIG" ngx_value(NGX_NOACCEPT_SIGNAL), + "", ngx_signal_handler }, { ngx_signal_value(NGX_TERMINATE_SIGNAL), "SIG" ngx_value(NGX_TERMINATE_SIGNAL), + "stop", ngx_signal_handler }, { ngx_signal_value(NGX_SHUTDOWN_SIGNAL), "SIG" ngx_value(NGX_SHUTDOWN_SIGNAL), + "quit", ngx_signal_handler }, { ngx_signal_value(NGX_CHANGEBIN_SIGNAL), "SIG" ngx_value(NGX_CHANGEBIN_SIGNAL), + "", ngx_signal_handler }, - { SIGALRM, "SIGALRM", ngx_signal_handler }, + { SIGALRM, "SIGALRM", "", ngx_signal_handler }, - { SIGINT, "SIGINT", ngx_signal_handler }, + { SIGINT, "SIGINT", "", ngx_signal_handler }, - { SIGIO, "SIGIO", ngx_signal_handler }, + { SIGIO, "SIGIO", "", ngx_signal_handler }, - { SIGCHLD, "SIGCHLD", ngx_signal_handler }, + { SIGCHLD, "SIGCHLD", "", ngx_signal_handler }, - { SIGPIPE, "SIGPIPE, SIG_IGN", SIG_IGN }, + { SIGPIPE, "SIGPIPE, SIG_IGN", "", SIG_IGN }, - { 0, NULL, NULL } + { 0, NULL, "", NULL } }; @@ -540,3 +547,23 @@ ngx_debug_point(void) ngx_abort(); } } + + +ngx_int_t +ngx_os_signal_process(ngx_cycle_t *cycle, char *name, ngx_int_t pid) +{ + ngx_signal_t *sig; + + for (sig = signals; sig->signo != 0; sig++) { + if (ngx_strcmp(name, sig->name) == 0) { + if (kill(pid, sig->signo) != -1) { + return 0; + } + + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + "kill(%P, %d) failed", pid, sig->signo); + } + } + + return 1; +} diff --git a/src/os/unix/ngx_process_cycle.h b/src/os/unix/ngx_process_cycle.h index 349a90202..c52b6f0e1 100644 --- a/src/os/unix/ngx_process_cycle.h +++ b/src/os/unix/ngx_process_cycle.h @@ -19,9 +19,10 @@ #define NGX_CMD_REOPEN 5 -#define NGX_PROCESS_SINGLE 0 -#define NGX_PROCESS_MASTER 1 -#define NGX_PROCESS_WORKER 2 +#define NGX_PROCESS_SINGLE 0 +#define NGX_PROCESS_MASTER 1 +#define NGX_PROCESS_WORKER 2 +#define NGX_PROCESS_SIGNALLER 3 void ngx_master_process_cycle(ngx_cycle_t *cycle); diff --git a/src/os/win32/ngx_os.h b/src/os/win32/ngx_os.h index cbd1fc22b..ba10c809a 100644 --- a/src/os/win32/ngx_os.h +++ b/src/os/win32/ngx_os.h @@ -11,6 +11,7 @@ #include <ngx_config.h> #include <ngx_core.h> + #define NGX_IO_SENDFILE 1 @@ -32,6 +33,7 @@ typedef struct { ngx_int_t ngx_os_init(ngx_log_t *log); void ngx_os_status(ngx_log_t *log); +ngx_int_t ngx_os_signal_process(ngx_cycle_t *cycle, char *sig, ngx_int_t pid); ssize_t ngx_wsarecv(ngx_connection_t *c, u_char *buf, size_t size); ssize_t ngx_overlapped_wsarecv(ngx_connection_t *c, u_char *buf, size_t size); diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c index 22d70c6fe..0481fe690 100644 --- a/src/os/win32/ngx_process_cycle.c +++ b/src/os/win32/ngx_process_cycle.c @@ -1006,50 +1006,11 @@ ngx_single_process_cycle(ngx_cycle_t *cycle) ngx_int_t -ngx_signal_process(ngx_cycle_t *cycle, char *sig) +ngx_os_signal_process(ngx_cycle_t *cycle, char *sig, ngx_int_t pid) { - size_t n; - HANDLE ev; - ngx_int_t rc, pid; - ngx_file_t file; - ngx_core_conf_t *ccf; - u_char buf[NGX_INT64_LEN + 2]; - char evn[NGX_PROCESS_SYNC_NAME]; - - 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; - } - - rc = 1; - - n = ngx_read_file(&file, buf, NGX_INT64_LEN + 2, 0); - - if (n == NGX_ERROR) { - goto failed; - } - - 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); - goto failed; - } + HANDLE ev; + ngx_int_t rc; + char evn[NGX_PROCESS_SYNC_NAME]; ngx_sprintf((u_char *) evn, "ngx_%s_%ul%Z", sig, pid); @@ -1057,25 +1018,20 @@ ngx_signal_process(ngx_cycle_t *cycle, char *sig) if (ev == NULL) { ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, "OpenEvent(\"%s\") failed", evn); - goto failed; + return 1; } if (SetEvent(ev) == 0) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "SetEvent(\"%s\") failed", evn); + rc = 1; + } else { rc = 0; } ngx_close_handle(ev); -failed: - - 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); - } - return rc; } diff --git a/src/os/win32/ngx_process_cycle.h b/src/os/win32/ngx_process_cycle.h index d9ed30b1a..cd5f01199 100644 --- a/src/os/win32/ngx_process_cycle.h +++ b/src/os/win32/ngx_process_cycle.h @@ -20,7 +20,6 @@ void ngx_master_process_cycle(ngx_cycle_t *cycle); void ngx_single_process_cycle(ngx_cycle_t *cycle); -ngx_int_t ngx_signal_process(ngx_cycle_t *cycle, char *sig); void ngx_close_handle(HANDLE h); |
