Mercurial > hg > nginx-quic
comparison src/os/unix/ngx_process_cycle.c @ 309:2e899477243a
nginx-0.0.3-2004-04-09-20:03:04 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 09 Apr 2004 16:03:04 +0000 |
parents | 4b1a3a4acc60 |
children | a9a9af2c7370 |
comparison
equal
deleted
inserted
replaced
308:7a0dbd779c6d | 309:2e899477243a |
---|---|
1 | 1 |
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 | |
6 #include <nginx.h> | |
5 | 7 |
6 | 8 |
7 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); |
8 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); |
9 #if (NGX_THREADS) | 11 #if (NGX_THREADS) |
529 | 531 |
530 return 1; | 532 return 1; |
531 } | 533 } |
532 | 534 |
533 #endif | 535 #endif |
536 | |
537 | |
538 static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) | |
539 { | |
540 size_t len; | |
541 u_char pid[NGX_INT64_LEN + 1]; | |
542 ngx_core_conf_t *ccf; | |
543 | |
544 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
545 | |
546 if (ccf->pid.len == 0) { | |
547 ccf->pid.len = sizeof(NGINX_PID) - 1; | |
548 ccf->pid.data = NGINX_PID; | |
549 ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1; | |
550 ccf->newpid.data = NGINX_NEW_PID; | |
551 | |
552 } else { | |
553 ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT); | |
554 if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { | |
555 return NGX_ERROR; | |
556 } | |
557 | |
558 ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), | |
559 NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT)); | |
560 } | |
561 | |
562 len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); | |
563 ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); | |
564 ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; | |
565 ctx->name = ccf->pid.data; | |
566 | |
567 ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, | |
568 NGX_FILE_CREATE_OR_OPEN); | |
569 | |
570 if (ctx->pid.fd == NGX_INVALID_FILE) { | |
571 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
572 ngx_open_file_n " \"%s\" failed", ctx->pid.name.data); | |
573 return NGX_ERROR; | |
574 } | |
575 | |
576 if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) { | |
577 return NGX_ERROR; | |
578 } | |
579 | |
580 if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) { | |
581 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
582 ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); | |
583 } | |
584 | |
585 return NGX_OK; | |
586 } |