Mercurial > hg > nginx
comparison src/core/nginx.c @ 227:2ba3477070ac
nginx-0.0.1-2004-01-14-21:19:42 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 14 Jan 2004 18:19:42 +0000 |
parents | b0c1e21e68db |
children | 92db0aa1e83f |
comparison
equal
deleted
inserted
replaced
226:b0c1e21e68db | 227:2ba3477070ac |
---|---|
239 { | 239 { |
240 int signo; | 240 int signo; |
241 char *name; | 241 char *name; |
242 sigset_t set, wset; | 242 sigset_t set, wset; |
243 struct timeval tv; | 243 struct timeval tv; |
244 ngx_uint_t i, live, mark; | 244 ngx_uint_t i, live, sent; |
245 ngx_msec_t delay; | 245 ngx_msec_t delay; |
246 | 246 |
247 delay = 125; | 247 delay = 125; |
248 | 248 |
249 sigemptyset(&set); | 249 sigemptyset(&set); |
263 } | 263 } |
264 | 264 |
265 ngx_signal = 0; | 265 ngx_signal = 0; |
266 ngx_new_binary = 0; | 266 ngx_new_binary = 0; |
267 signo = 0; | 267 signo = 0; |
268 mark = 1; | 268 sent = 0; |
269 | 269 |
270 for ( ;; ) { | 270 for ( ;; ) { |
271 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); | 271 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); |
272 | 272 |
273 if (ngx_process == NGX_PROCESS_MASTER) { | 273 if (ngx_process == NGX_PROCESS_MASTER) { |
274 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, | 274 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, |
275 "worker process", NGX_PROCESS_RESPAWN); | 275 "worker process", NGX_PROCESS_RESPAWN); |
276 mark = 1; | |
277 | 276 |
278 } else { | 277 } else { |
279 ngx_init_temp_number(); | 278 ngx_init_temp_number(); |
280 | 279 |
281 for (i = 0; ngx_modules[i]; i++) { | 280 for (i = 0; ngx_modules[i]; i++) { |
295 /* an event loop */ | 294 /* an event loop */ |
296 | 295 |
297 for ( ;; ) { | 296 for ( ;; ) { |
298 | 297 |
299 if (ngx_process == NGX_PROCESS_MASTER) { | 298 if (ngx_process == NGX_PROCESS_MASTER) { |
300 if (signo) { | 299 if (sent) { |
301 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | 300 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
302 "signal cycle: %d, %d", signo, mark); | 301 "sent signal cycle"); |
303 | 302 |
304 if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) { | 303 if (sigprocmask(SIG_UNBLOCK, &set, NULL) == -1) { |
305 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 304 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
306 "sigprocmask() failed"); | 305 "sigprocmask() failed"); |
307 continue; | 306 continue; |
362 "reap childs"); | 361 "reap childs"); |
363 | 362 |
364 live = 0; | 363 live = 0; |
365 for (i = 0; i < ngx_last_process; i++) { | 364 for (i = 0; i < ngx_last_process; i++) { |
366 | 365 |
367 if (ngx_processes[i].exiting | 366 ngx_log_debug6(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
368 && !ngx_processes[i].exited) | 367 "child: " PID_T_FMT |
369 { | 368 " s:%d e:%d t:%d d:%d r:%d", |
370 live = 1; | 369 ngx_processes[i].pid, |
371 continue; | 370 ngx_processes[i].signal, |
372 } | 371 ngx_processes[i].exiting, |
372 ngx_processes[i].exited, | |
373 ngx_processes[i].detached, | |
374 ngx_processes[i].respawn); | |
373 | 375 |
374 if (ngx_processes[i].exited) { | 376 if (ngx_processes[i].exited) { |
377 | |
378 if (ngx_processes[i].respawn | |
379 && !ngx_processes[i].exiting | |
380 && !ngx_terminate | |
381 && !ngx_quit) | |
382 { | |
383 if (ngx_spawn_process(cycle, | |
384 ngx_processes[i].proc, | |
385 ngx_processes[i].data, | |
386 ngx_processes[i].name, i) | |
387 == NGX_ERROR) | |
388 { | |
389 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
390 "can not respawn %s", | |
391 ngx_processes[i].name); | |
392 } | |
393 | |
394 continue; | |
395 } | |
396 | |
375 if (ngx_processes[i].pid == ngx_new_binary) { | 397 if (ngx_processes[i].pid == ngx_new_binary) { |
376 ngx_new_binary = 0; | 398 ngx_new_binary = 0; |
377 } | 399 } |
378 | 400 |
379 if (i != --ngx_last_process) { | 401 if (i != --ngx_last_process) { |
380 ngx_processes[i--] = | 402 ngx_processes[i--] = |
381 ngx_processes[ngx_last_process]; | 403 ngx_processes[ngx_last_process]; |
382 } | 404 } |
405 | |
406 } else if (!ngx_processes[i].detached | |
407 && (ngx_terminate || ngx_quit)) | |
408 { | |
409 live = 1; | |
410 | |
411 } else if (ngx_processes[i].exiting) { | |
412 live = 1; | |
383 } | 413 } |
384 } | 414 } |
385 | 415 |
386 if (!live) { | 416 if (!live) { |
387 if (ngx_terminate || ngx_quit) { | 417 if (ngx_terminate || ngx_quit) { |
402 | 432 |
403 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); | 433 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); |
404 exit(0); | 434 exit(0); |
405 | 435 |
406 } else { | 436 } else { |
407 signo = 0; | 437 sent = 0; |
408 mark = 0; | |
409 } | 438 } |
410 } | 439 } |
411 } | 440 } |
412 | 441 |
413 if (ngx_terminate) { | 442 if (ngx_terminate) { |
414 if (delay > 10000) { | 443 if (delay > 10000) { |
415 signo = SIGKILL; | 444 signo = SIGKILL; |
416 } else { | 445 } else { |
417 signo = ngx_signal_value(NGX_TERMINATE_SIGNAL); | 446 signo = ngx_signal_value(NGX_TERMINATE_SIGNAL); |
418 if (mark == 0) { | 447 } |
419 mark = 1; | |
420 } | |
421 } | |
422 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
423 "mark: %d", mark); | |
424 | 448 |
425 } else if (ngx_quit) { | 449 } else if (ngx_quit) { |
426 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | 450 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
427 if (mark == 0) { | |
428 mark = 1; | |
429 } | |
430 | 451 |
431 } else { | 452 } else { |
432 | 453 |
433 if (ngx_reap) { | |
434 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | |
435 "respawn processes"); | |
436 ngx_respawn_processes(cycle); | |
437 } | |
438 | |
439 if (ngx_noaccept) { | 454 if (ngx_noaccept) { |
440 if (mark == 0) { | |
441 mark = 1; | |
442 } | |
443 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | 455 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
444 } | 456 } |
445 | 457 |
446 if (ngx_change_binary) { | 458 if (ngx_change_binary) { |
447 ngx_change_binary = 0; | 459 ngx_change_binary = 0; |
449 "changing binary"); | 461 "changing binary"); |
450 ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv); | 462 ngx_new_binary = ngx_exec_new_binary(cycle, ctx->argv); |
451 } | 463 } |
452 | 464 |
453 if (ngx_reconfigure) { | 465 if (ngx_reconfigure) { |
454 mark = 1; | |
455 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | 466 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
456 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | 467 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, |
457 "reconfiguring"); | 468 "reconfiguring"); |
458 } | 469 } |
459 | 470 |
460 if (ngx_reopen) { | 471 if (ngx_reopen) { |
461 ngx_reopen = 0; | |
462 | |
463 /* STUB */ | 472 /* STUB */ |
464 mark = 1; | |
465 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); | 473 signo = ngx_signal_value(NGX_SHUTDOWN_SIGNAL); |
466 | 474 |
467 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, | 475 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, |
468 "reopening logs"); | 476 "reopening logs"); |
469 ngx_reopen_files(cycle); | 477 ngx_reopen_files(cycle); |
470 } | 478 } |
471 } | 479 } |
472 | 480 |
473 if (signo) { | 481 if (signo) { |
474 if (mark == 1) { | 482 for (i = 0; i < ngx_last_process; i++) { |
475 for (i = 0; i < ngx_last_process; i++) { | 483 |
476 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, | 484 if (!ngx_processes[i].detached) { |
485 ngx_processes[i].signal = signo; | |
486 | |
487 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, | |
477 cycle->log, 0, | 488 cycle->log, 0, |
478 "proc " PID_T_FMT, | 489 "signal " PID_T_FMT " %d", |
479 ngx_processes[i].pid); | 490 ngx_processes[i].pid, signo); |
480 | |
481 if (!ngx_processes[i].detached) { | |
482 ngx_processes[i].signal = 1; | |
483 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, | |
484 cycle->log, 0, | |
485 "mark " PID_T_FMT, | |
486 ngx_processes[i].pid); | |
487 } | |
488 } | 491 } |
489 mark = -1; | 492 } |
490 delay = 125; | 493 delay = 125; |
491 } | 494 signo = 0; |
492 | 495 } |
493 ngx_signal_processes(cycle, signo); | 496 |
497 for (i = 0; i < ngx_last_process; i++) { | |
498 | |
499 if (ngx_processes[i].signal == 0) { | |
500 continue; | |
501 } | |
502 | |
503 sent = 1; | |
504 | |
505 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, | |
506 "kill (" PID_T_FMT ", %d)" , | |
507 ngx_processes[i].pid, | |
508 ngx_processes[i].signal); | |
509 | |
510 if (kill(ngx_processes[i].pid, ngx_processes[i].signal) | |
511 == -1) | |
512 { | |
513 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
514 "kill(%d, %d) failed", | |
515 ngx_processes[i].pid, | |
516 ngx_processes[i].signal); | |
517 continue; | |
518 } | |
519 | |
520 if (ngx_processes[i].signal | |
521 != ngx_signal_value(NGX_REOPEN_SIGNAL)) | |
522 { | |
523 ngx_processes[i].exiting = 1; | |
524 } | |
494 } | 525 } |
495 | 526 |
496 if (ngx_reap) { | 527 if (ngx_reap) { |
497 ngx_reap = 0; | 528 ngx_reap = 0; |
498 } | 529 } |
499 | 530 |
500 /* STUB */ | 531 /* STUB */ |
501 if (ngx_reopen) { | 532 if (ngx_reopen) { |
533 ngx_reopen = 0; | |
502 break; | 534 break; |
503 } | 535 } |
504 | 536 |
505 if (ngx_reconfigure) { | 537 if (ngx_reconfigure) { |
506 break; | 538 break; |