Mercurial > hg > nginx
comparison src/os/unix/ngx_process_cycle.c @ 310:a9a9af2c7370
nginx-0.0.3-2004-04-12-10:10:53 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 12 Apr 2004 06:10:53 +0000 |
parents | 2e899477243a |
children | 11ff50a35d6d |
comparison
equal
deleted
inserted
replaced
309:2e899477243a | 310:a9a9af2c7370 |
---|---|
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); | |
14 | 16 |
15 | 17 |
16 ngx_int_t ngx_process; | 18 ngx_int_t ngx_process; |
17 ngx_pid_t ngx_pid; | 19 ngx_pid_t ngx_pid; |
18 ngx_pid_t ngx_new_binary; | 20 ngx_pid_t ngx_new_binary; |
334 } | 336 } |
335 | 337 |
336 | 338 |
337 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | 339 static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) |
338 { | 340 { |
339 u_char *name; | 341 ngx_delete_pidfile(cycle); |
340 | |
341 if (ngx_inherited && getppid() > 1) { | |
342 name = ctx->pid.name.data; | |
343 | |
344 } else { | |
345 name = ctx->name; | |
346 } | |
347 | |
348 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | |
349 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
350 ngx_delete_file_n " \"%s\" failed", name); | |
351 } | |
352 | 342 |
353 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); | 343 ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "exit"); |
344 | |
354 exit(0); | 345 exit(0); |
355 } | 346 } |
356 | 347 |
357 | 348 |
358 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) | 349 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) |
533 } | 524 } |
534 | 525 |
535 #endif | 526 #endif |
536 | 527 |
537 | 528 |
538 static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | 529 static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) |
539 { | 530 { |
540 size_t len; | 531 size_t len; |
541 u_char pid[NGX_INT64_LEN + 1]; | 532 u_char pid[NGX_INT64_LEN + 1]; |
533 ngx_str_t name; | |
542 ngx_core_conf_t *ccf; | 534 ngx_core_conf_t *ccf; |
543 | 535 |
544 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 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 } | |
545 | 549 |
546 if (ccf->pid.len == 0) { | 550 if (ccf->pid.len == 0) { |
547 ccf->pid.len = sizeof(NGINX_PID) - 1; | 551 ccf->pid.len = sizeof(NGINX_PID) - 1; |
548 ccf->pid.data = NGINX_PID; | 552 ccf->pid.data = NGINX_PID; |
549 ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1; | 553 ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; |
550 ccf->newpid.data = NGINX_NEW_PID; | 554 ccf->newpid.data = NGINX_NEWPID; |
551 | 555 |
552 } else { | 556 } else { |
553 ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT); | 557 ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); |
554 if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { | 558 if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { |
555 return NGX_ERROR; | 559 return NGX_ERROR; |
556 } | 560 } |
557 | 561 |
558 ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), | 562 ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), |
559 NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT)); | 563 NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); |
560 } | 564 } |
561 | 565 |
562 len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); | 566 len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); |
563 ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); | 567 ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); |
564 ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; | 568 ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; |
565 ctx->name = ccf->pid.data; | 569 ctx->name = ccf->pid.data; |
566 | 570 |
567 ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, | 571 ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, |
582 ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); | 586 ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); |
583 } | 587 } |
584 | 588 |
585 return NGX_OK; | 589 return NGX_OK; |
586 } | 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 } |