comparison src/os/unix/ngx_process.c @ 279:b79f021a644a

nginx-0.0.2-2004-03-04-19:34:23 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 04 Mar 2004 16:34:23 +0000
parents d4e65d74db9f
children 6b91bfbc4123
comparison
equal deleted inserted replaced
278:0ba4821f4460 279:b79f021a644a
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 4
5 5
6 static void ngx_exec_proc(ngx_cycle_t *cycle, void *data); 6 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data);
7 7
8 ngx_uint_t ngx_last_process; 8 ngx_uint_t ngx_last_process;
9 ngx_process_t ngx_processes[NGX_MAX_PROCESSES]; 9 ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
10 10
11 11
12 ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle, 12 ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
13 ngx_spawn_proc_pt proc, void *data, 13 ngx_spawn_proc_pt proc, void *data,
14 char *name, ngx_int_t respawn) 14 char *name, ngx_int_t respawn)
15 { 15 {
16 #if 0
17 sigset_t set, oset;
18 #endif
19 ngx_pid_t pid; 16 ngx_pid_t pid;
20
21 #if 0
22 if (respawn < 0) {
23 sigemptyset(&set);
24 sigaddset(&set, SIGCHLD);
25 if (sigprocmask(SIG_BLOCK, &set, &oset) == -1) {
26 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
27 "sigprocmask() failed while spawning %s", name);
28 return NGX_ERROR;
29 }
30 }
31 #endif
32 17
33 pid = fork(); 18 pid = fork();
34 19
35 if (pid == -1) { 20 if (pid == -1) {
36 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 21 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
37 "fork() failed while spawning \"%s\"", name); 22 "fork() failed while spawning \"%s\"", name);
38 }
39
40 if (pid == -1 || pid == 0) {
41 #if 0
42 if (sigprocmask(SIG_SETMASK, &oset, &set) == -1) {
43 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
44 "sigprocmask() failed while spawning %s", name);
45 return NGX_ERROR;
46 }
47 #endif
48 } 23 }
49 24
50 switch (pid) { 25 switch (pid) {
51 case -1: 26 case -1:
52 return NGX_ERROR; 27 return NGX_ERROR;
79 (respawn == NGX_PROCESS_DETACHED) ? 1 : 0; 54 (respawn == NGX_PROCESS_DETACHED) ? 1 : 0;
80 ngx_processes[ngx_last_process].exited = 0; 55 ngx_processes[ngx_last_process].exited = 0;
81 ngx_processes[ngx_last_process].exiting = 0; 56 ngx_processes[ngx_last_process].exiting = 0;
82 ngx_last_process++; 57 ngx_last_process++;
83 58
84 #if 0
85 if (sigprocmask(SIG_SETMASK, &oset, &set) == -1) {
86 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
87 "sigprocmask() failed while spawning %s", name);
88 return NGX_ERROR;
89 }
90 #endif
91
92 return pid; 59 return pid;
93 } 60 }
94 61
95 62
96 ngx_pid_t ngx_exec(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx) 63 ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx)
97 { 64 {
98 return ngx_spawn_process(cycle, ngx_exec_proc, ctx, ctx->name, 65 return ngx_spawn_process(cycle, ngx_execute_proc, ctx, ctx->name,
99 NGX_PROCESS_DETACHED); 66 NGX_PROCESS_DETACHED);
100 } 67 }
101 68
102 69
103 static void ngx_exec_proc(ngx_cycle_t *cycle, void *data) 70 static void ngx_execute_proc(ngx_cycle_t *cycle, void *data)
104 { 71 {
105 ngx_exec_ctx_t *ctx = data; 72 ngx_exec_ctx_t *ctx = data;
106 73
107 if (execve(ctx->path, ctx->argv, ctx->envp) == -1) { 74 if (execve(ctx->path, ctx->argv, ctx->envp) == -1) {
108 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 75 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
110 ctx->name, ctx->path); 77 ctx->name, ctx->path);
111 } 78 }
112 79
113 exit(1); 80 exit(1);
114 } 81 }
115
116
117 #if 0
118
119 void ngx_signal_processes(ngx_cycle_t *cycle)
120 {
121 ngx_uint_t i;
122
123 for (i = 0; i < ngx_last_process; i++) {
124
125 if (ngx_processes[i].signal0 == 0) {
126 continue;
127 }
128
129 #if 0
130 if (ngx_processes[i].exited) {
131 if (i != --ngx_last_process) {
132 ngx_processes[i--] = ngx_processes[ngx_last_process];
133 }
134 continue;
135 }
136 #endif
137
138 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
139 "kill (" PID_T_FMT ", %d)" ,
140 ngx_processes[i].pid, ngx_processes[i].signal0);
141
142 if (kill(ngx_processes[i].pid, ngx_processes[i].signal0) == -1) {
143 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
144 "kill(%d, %d) failed",
145 ngx_processes[i].pid, ngx_processes[i].signal0);
146 continue;
147 }
148
149 if (ngx_processes[i].signal0 != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
150 ngx_processes[i].exiting = 1;
151 }
152 }
153 }
154
155 #endif
156 82
157 83
158 void ngx_respawn_processes(ngx_cycle_t *cycle) 84 void ngx_respawn_processes(ngx_cycle_t *cycle)
159 { 85 {
160 ngx_uint_t i; 86 ngx_uint_t i;