Mercurial > hg > nginx-quic
comparison src/os/unix/ngx_process_cycle.c @ 311:11ff50a35d6d
nginx-0.0.3-2004-04-12-20:38:09 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 12 Apr 2004 16:38:09 +0000 |
parents | a9a9af2c7370 |
children | 39b6f2df45c0 |
comparison
equal
deleted
inserted
replaced
310:a9a9af2c7370 | 311:11ff50a35d6d |
---|---|
9 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); | 9 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); |
10 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 10 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
11 #if (NGX_THREADS) | 11 #if (NGX_THREADS) |
12 static int ngx_worker_thread_cycle(void *data); | 12 static int ngx_worker_thread_cycle(void *data); |
13 #endif | 13 #endif |
14 | |
15 static void ngx_delete_pidfile(ngx_cycle_t *cycle); | |
16 | 14 |
17 | 15 |
18 ngx_int_t ngx_process; | 16 ngx_int_t ngx_process; |
19 ngx_pid_t ngx_pid; | 17 ngx_pid_t ngx_pid; |
20 ngx_pid_t ngx_new_binary; | 18 ngx_pid_t ngx_new_binary; |
73 for ( ;; ) { | 71 for ( ;; ) { |
74 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); | 72 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "new cycle"); |
75 | 73 |
76 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, | 74 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, |
77 ngx_core_module); | 75 ngx_core_module); |
78 | |
79 if (ccf->worker_processes == NGX_CONF_UNSET) { | |
80 ccf->worker_processes = 1; | |
81 } | |
82 | 76 |
83 if (ngx_process == NGX_PROCESS_MASTER) { | 77 if (ngx_process == NGX_PROCESS_MASTER) { |
84 for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) { | 78 for (i = 0; i < (ngx_uint_t) ccf->worker_processes; i++) { |
85 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, | 79 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, |
86 "worker process", NGX_PROCESS_RESPAWN); | 80 "worker process", NGX_PROCESS_RESPAWN); |
522 | 516 |
523 return 1; | 517 return 1; |
524 } | 518 } |
525 | 519 |
526 #endif | 520 #endif |
527 | |
528 | |
529 static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | |
530 { | |
531 size_t len; | |
532 u_char pid[NGX_INT64_LEN + 1]; | |
533 ngx_str_t name; | |
534 ngx_core_conf_t *ccf; | |
535 | |
536 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
537 | |
538 if (ctx->pid.len) { | |
539 if (ccf->pid.len == 0) { | |
540 return NGX_OK; | |
541 } | |
542 | |
543 if (ctx->pid.len == ccf->pid.len | |
544 && ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0) | |
545 { | |
546 return NGX_OK; | |
547 } | |
548 } | |
549 | |
550 if (ccf->pid.len == 0) { | |
551 ccf->pid.len = sizeof(NGINX_PID) - 1; | |
552 ccf->pid.data = NGINX_PID; | |
553 ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; | |
554 ccf->newpid.data = NGINX_NEWPID; | |
555 | |
556 } else { | |
557 ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); | |
558 if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { | |
559 return NGX_ERROR; | |
560 } | |
561 | |
562 ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), | |
563 NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); | |
564 } | |
565 | |
566 len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); | |
567 ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); | |
568 ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; | |
569 ctx->name = ccf->pid.data; | |
570 | |
571 ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, | |
572 NGX_FILE_CREATE_OR_OPEN); | |
573 | |
574 if (ctx->pid.fd == NGX_INVALID_FILE) { | |
575 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
576 ngx_open_file_n " \"%s\" failed", ctx->pid.name.data); | |
577 return NGX_ERROR; | |
578 } | |
579 | |
580 if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) { | |
581 return NGX_ERROR; | |
582 } | |
583 | |
584 if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) { | |
585 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
586 ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); | |
587 } | |
588 | |
589 return NGX_OK; | |
590 } | |
591 | |
592 | |
593 static void ngx_delete_pidfile(ngx_cycle_t *cycle) | |
594 { | |
595 u_char *name; | |
596 ngx_core_conf_t *ccf; | |
597 | |
598 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
599 | |
600 if (ngx_inherited && getppid() > 1) { | |
601 name = ccf->newpid.data; | |
602 | |
603 } else { | |
604 name = ccf->pid.data; | |
605 } | |
606 | |
607 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | |
608 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
609 ngx_delete_file_n " \"%s\" failed", name); | |
610 } | |
611 } |