comparison src/core/nginx.c @ 290:87e73f067470

nginx-0.0.2-2004-03-16-10:10:12 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 16 Mar 2004 07:10:12 +0000
parents 0750faf8d7e3
children 502b03d9d2a3
comparison
equal deleted inserted replaced
289:0750faf8d7e3 290:87e73f067470
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_core.h> 3 #include <ngx_core.h>
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 #include <nginx.h> 5 #include <nginx.h>
6 6
7
8 #if 0
9
10 typedef struct {
11 ngx_flag_t daemon;
12 ngx_flag_t master;
13 ngx_flag_t worker_reopen;
14 uid_t user;
15 gid_t group;
16 ngx_str_t pid;
17 ngx_str_t newpid;
18 } ngx_core_conf_t;
19
20
21 typedef struct {
22 ngx_file_t pid;
23 char *name;
24 int argc;
25 char *const *argv;
26 } ngx_master_ctx_t;
27
28
29 static void ngx_master_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
30 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
31 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
32 #if (NGX_THREADS)
33 static int ngx_worker_thread_cycle(void *data);
34 #endif
35
36 #endif
37 7
38 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); 8 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle);
39 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle); 9 static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle);
40 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle); 10 static ngx_int_t ngx_core_module_init(ngx_cycle_t *cycle);
41 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 11 static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
110 ngx_cycle_t *cycle, init_cycle; 80 ngx_cycle_t *cycle, init_cycle;
111 ngx_core_conf_t *ccf; 81 ngx_core_conf_t *ccf;
112 ngx_master_ctx_t ctx; 82 ngx_master_ctx_t ctx;
113 #if !(WIN32) 83 #if !(WIN32)
114 size_t len; 84 size_t len;
115 char pid[/* STUB */ 10]; 85 u_char pid[/* STUB */ 10];
116 #endif 86 #endif
117 87
118 #if __FreeBSD__ 88 #if __FreeBSD__
119 ngx_debug_init(); 89 ngx_debug_init();
120 #endif 90 #endif
218 188
219 ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), 189 ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
220 NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT)); 190 NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT));
221 } 191 }
222 192
223 len = ngx_snprintf(pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); 193 len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
224 ngx_memzero(&ctx.pid, sizeof(ngx_file_t)); 194 ngx_memzero(&ctx.pid, sizeof(ngx_file_t));
225 ctx.pid.name = ngx_inherited ? ccf->newpid : ccf->pid; 195 ctx.pid.name = ngx_inherited ? ccf->newpid : ccf->pid;
226 ctx.name = ccf->pid.data; 196 ctx.name = ccf->pid.data;
227 197
228 ctx.pid.fd = ngx_open_file(ctx.pid.name.data, NGX_FILE_RDWR, 198 ctx.pid.fd = ngx_open_file(ctx.pid.name.data, NGX_FILE_RDWR,
251 } 221 }
252 222
253 223
254 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle) 224 static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle)
255 { 225 {
256 char *p, *v, *inherited; 226 u_char *p, *v, *inherited;
257 ngx_socket_t s; 227 ngx_socket_t s;
258 ngx_listening_t *ls; 228 ngx_listening_t *ls;
259 229
260 inherited = getenv(NGINX_VAR); 230 inherited = (u_char *) getenv(NGINX_VAR);
261 231
262 if (inherited == NULL) { 232 if (inherited == NULL) {
263 return NGX_OK; 233 return NGX_OK;
264 } 234 }
265 235
278 NGINX_VAR " enviroment variable, " 248 NGINX_VAR " enviroment variable, "
279 "ignoring the rest of the variable", v); 249 "ignoring the rest of the variable", v);
280 break; 250 break;
281 } 251 }
282 252
283 v = p + 1; 253 v = p + 1;
284 254
285 if (!(ls = ngx_push_array(&cycle->listening))) { 255 if (!(ls = ngx_push_array(&cycle->listening))) {
286 return NGX_ERROR; 256 return NGX_ERROR;
287 } 257 }
288 258
289 ls->fd = s; 259 ls->fd = s;
290 } 260 }
291 } 261 }
292 262
297 267
298 268
299 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv) 269 ngx_pid_t ngx_exec_new_binary(ngx_cycle_t *cycle, char *const *argv)
300 { 270 {
301 char *env[2], *var, *p; 271 char *env[2], *var, *p;
302 ngx_int_t i; 272 ngx_uint_t i;
303 ngx_pid_t pid; 273 ngx_pid_t pid;
304 ngx_exec_ctx_t ctx; 274 ngx_exec_ctx_t ctx;
305 ngx_listening_t *ls; 275 ngx_listening_t *ls;
306 276
307 ctx.path = argv[0]; 277 ctx.path = argv[0];
310 280
311 var = ngx_alloc(sizeof(NGINX_VAR) 281 var = ngx_alloc(sizeof(NGINX_VAR)
312 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2, 282 + cycle->listening.nelts * (NGX_INT32_LEN + 1) + 2,
313 cycle->log); 283 cycle->log);
314 284
315 p = ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR)); 285 p = (char *) ngx_cpymem(var, NGINX_VAR "=", sizeof(NGINX_VAR));
316 286
317 ls = cycle->listening.elts; 287 ls = cycle->listening.elts;
318 for (i = 0; i < cycle->listening.nelts; i++) { 288 for (i = 0; i < cycle->listening.nelts; i++) {
319 p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd); 289 p += ngx_snprintf(p, NGX_INT32_LEN + 2, "%u;", ls[i].fd);
320 } 290 }
345 } 315 }
346 316
347 switch (ctx->argv[i][1]) { 317 switch (ctx->argv[i][1]) {
348 318
349 case 'c': 319 case 'c':
350 cycle->conf_file.data = ctx->argv[++i]; 320 cycle->conf_file.data = (u_char *) ctx->argv[++i];
351 cycle->conf_file.len = ngx_strlen(cycle->conf_file.data); 321 cycle->conf_file.len = ngx_strlen(cycle->conf_file.data);
352 break; 322 break;
353 323
354 default: 324 default:
355 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, 325 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
423 return "is duplicate"; 393 return "is duplicate";
424 } 394 }
425 395
426 value = (ngx_str_t *) cf->args->elts; 396 value = (ngx_str_t *) cf->args->elts;
427 397
428 pwd = getpwnam(value[1].data); 398 pwd = getpwnam((const char *) value[1].data);
429 if (pwd == NULL) { 399 if (pwd == NULL) {
430 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, 400 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
431 "getpwnam(%s) failed", value[1].data); 401 "getpwnam(%s) failed", value[1].data);
432 return NGX_CONF_ERROR; 402 return NGX_CONF_ERROR;
433 } 403 }
436 406
437 if (cf->args->nelts == 2) { 407 if (cf->args->nelts == 2) {
438 return NGX_CONF_OK; 408 return NGX_CONF_OK;
439 } 409 }
440 410
441 grp = getgrnam(value[2].data); 411 grp = getgrnam((const char *) value[2].data);
442 if (grp == NULL) { 412 if (grp == NULL) {
443 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, 413 ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
444 "getgrnam(%s) failed", value[1].data); 414 "getgrnam(%s) failed", value[1].data);
445 return NGX_CONF_ERROR; 415 return NGX_CONF_ERROR;
446 } 416 }