# HG changeset patch # User Igor Sysoev # Date 1087575736 0 # Node ID 239e37d44a341dbac2adf3ef6dbc0916c7ade3bb # Parent a3e622ab7ee70b166eb76535387e3aa634365090 nginx-0.0.7-2004-06-18-20:22:16 import diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -187,16 +187,6 @@ static ngx_int_t ngx_event_module_init(n size = 128 /* ngx_accept_mutex */ + 128; /* ngx_connection_counter */ -#if 0 - shared = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); - - if (shared == MAP_FAILED) { - ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, - "mmap(MAP_ANON|MAP_SHARED) failed"); - return NGX_ERROR; - } -#endif - if (!(shared = ngx_create_shared_memory(size, cycle->log))) { return NGX_ERROR; } @@ -635,6 +625,9 @@ static void *ngx_event_create_conf(ngx_c static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) { ngx_event_conf_t *ecf = conf; +#if (HAVE_RTSIG) + ngx_core_conf_t *ccf; +#endif #if (HAVE_KQUEUE) @@ -656,8 +649,6 @@ static char *ngx_event_init_conf(ngx_cyc #elif (HAVE_RTSIG) - ngx_core_conf_t *ccf; - ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS); ngx_conf_init_unsigned_value(ecf->use, ngx_rtsig_module.ctx_index); ngx_conf_init_ptr_value(ecf->name, ngx_rtsig_module_ctx.name->data); diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -6,9 +6,9 @@ static void ngx_execute_proc(ngx_cycle_t *cycle, void *data); -ngx_int_t ngx_current_slot; +ngx_int_t ngx_process_slot; +ngx_socket_t ngx_channel; ngx_int_t ngx_last_process; -ngx_socket_t ngx_channel; ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; @@ -31,6 +31,18 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t return NGX_ERROR; } + if (ngx_nonblocking(ngx_processes[s].channel[0]) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_nonblocking_n " failed while spawning \"%s\"", name); + return NGX_ERROR; + } + + if (ngx_nonblocking(ngx_processes[s].channel[1]) == -1) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_nonblocking_n " failed while spawning \"%s\"", name); + return NGX_ERROR; + } + on = 1; if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, @@ -45,7 +57,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t } ngx_channel = ngx_processes[s].channel[1]; - ngx_current_slot = s; + ngx_process_slot = s; pid = fork(); diff --git a/src/os/unix/ngx_process.h b/src/os/unix/ngx_process.h --- a/src/os/unix/ngx_process.h +++ b/src/os/unix/ngx_process.h @@ -49,9 +49,9 @@ ngx_pid_t ngx_execute(ngx_cycle_t *cycle void ngx_process_get_status(void); extern ngx_pid_t ngx_pid; -extern ngx_int_t ngx_current_slot; +extern ngx_socket_t ngx_channel; +extern ngx_int_t ngx_process_slot; extern ngx_int_t ngx_last_process; -extern ngx_socket_t ngx_channel; extern ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -334,13 +334,33 @@ void ngx_single_process_cycle(ngx_cycle_ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type) { + ngx_int_t i; + ngx_channel_t ch; struct itimerval itv; ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "start worker processes"); + ch.command = NGX_CMD_OPEN_CHANNEL; + while (n--) { ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, "worker process", type); + + ch.pid = ngx_processes[ngx_process_slot].pid; + ch.slot = ngx_process_slot; + ch.fd = ngx_processes[ngx_process_slot].channel[0]; + + for (i = 0; i < ngx_last_process - 1; i++) { + + ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0, + "pass channel s: %d pid:" PID_T_FMT " fd:%d", + ch.slot, ch.pid, ch.fd); + + /* TODO: NGX_AGAIN */ + + ngx_write_channel(ngx_processes[i].channel[0], + &ch, sizeof(ngx_channel_t), cycle->log); + } } /* @@ -360,6 +380,7 @@ static void ngx_start_worker_processes(n } } + static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo) { ngx_int_t i; @@ -529,7 +550,7 @@ static void ngx_worker_process_cycle(ngx for (n = 0; n <= ngx_last_process; n++) { - if (n == ngx_current_slot) { + if (n == ngx_process_slot) { if (close(ngx_processes[n].channel[0]) == -1) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "close() failed"); @@ -681,6 +702,16 @@ static void ngx_channel_handler(ngx_even case NGX_CMD_REOPEN: ngx_reopen = 1; break; + + case NGX_CMD_OPEN_CHANNEL: + + ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0, + "get channel s:%d pid:" PID_T_FMT " fd:%d", + ch.slot, ch.pid, ch.fd); + + ngx_processes[ch.slot].pid = ch.pid; + ngx_processes[ch.slot].channel[0] = ch.fd; + break; } } @@ -775,7 +806,7 @@ ngx_int_t ngx_write_channel(ngx_socket_t msg.msg_iov = iov; msg.msg_iovlen = 1; - n = sendmsg(s, &msg, MSG_DONTWAIT); + n = sendmsg(s, &msg, 0); if (n == -1) { err = ngx_errno; @@ -799,7 +830,7 @@ ngx_int_t ngx_read_channel(ngx_socket_t ngx_err_t err; struct iovec iov[1]; struct msghdr msg; - struct cmsghdr *cm; + struct cmsghdr cm; iov[0].iov_base = (char *) ch; iov[0].iov_len = size; @@ -817,7 +848,7 @@ ngx_int_t ngx_read_channel(ngx_socket_t msg.msg_accrightslen = sizeof(int); #endif - n = recvmsg(s, &msg, MSG_DONTWAIT); + n = recvmsg(s, &msg, 0); if (n == -1) { err = ngx_errno; @@ -838,28 +869,21 @@ ngx_int_t ngx_read_channel(ngx_socket_t #if (HAVE_MSGHDR_MSG_CONTROL) if (ch->command == NGX_CMD_OPEN_CHANNEL) { - cm = (struct cmsghdr *) msg.msg_control; - if (cm == NULL) { - ngx_log_error(NGX_LOG_ALERT, log, 0, - "recvmsg() returned no ancillary data"); - return NGX_ERROR; - } - - if (cm->cmsg_len < sizeof(struct cmsghdr) + sizeof(int)) { + if (cm.cmsg_len < sizeof(struct cmsghdr) + sizeof(int)) { ngx_log_error(NGX_LOG_ALERT, log, 0, "recvmsg() returned too small ancillary data"); return NGX_ERROR; } - if (cm->cmsg_level != SOL_SOCKET || cm->cmsg_type != SCM_RIGHTS) { + if (cm.cmsg_level != SOL_SOCKET || cm.cmsg_type != SCM_RIGHTS) { ngx_log_error(NGX_LOG_ALERT, log, 0, "recvmsg() returned invalid ancillary data " - "level %d or type %d", cm->cmsg_level, cm->cmsg_type); + "level %d or type %d", cm.cmsg_level, cm.cmsg_type); return NGX_ERROR; } - ch->fd = *((int *) ((char *) cm + sizeof(struct cmsghdr))); + ch->fd = *((int *) ((char *) &cm + sizeof(struct cmsghdr))); } if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) { diff --git a/src/os/unix/ngx_process_cycle.h b/src/os/unix/ngx_process_cycle.h --- a/src/os/unix/ngx_process_cycle.h +++ b/src/os/unix/ngx_process_cycle.h @@ -16,6 +16,7 @@ typedef struct { ngx_uint_t command; ngx_pid_t pid; + ngx_int_t slot; ngx_fd_t fd; } ngx_channel_t;