implement "-s signal" option for Unix
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index eae4c83..476ba83 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -569,12 +569,14 @@
}
}
- 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_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)
{