Mercurial > hg > nginx
comparison src/core/ngx_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 | 87e73f067470 |
children | 11ff50a35d6d |
comparison
equal
deleted
inserted
replaced
309:2e899477243a | 310:a9a9af2c7370 |
---|---|
28 ngx_conf_t conf; | 28 ngx_conf_t conf; |
29 ngx_pool_t *pool; | 29 ngx_pool_t *pool; |
30 ngx_cycle_t *cycle, **old; | 30 ngx_cycle_t *cycle, **old; |
31 ngx_socket_t fd; | 31 ngx_socket_t fd; |
32 ngx_open_file_t *file; | 32 ngx_open_file_t *file; |
33 ngx_core_conf_t *ccf; | |
33 ngx_listening_t *ls, *nls; | 34 ngx_listening_t *ls, *nls; |
34 | 35 |
35 log = old_cycle->log; | 36 log = old_cycle->log; |
36 | 37 |
37 if (!(pool = ngx_create_pool(16 * 1024, log))) { | 38 if (!(pool = ngx_create_pool(16 * 1024, log))) { |
123 return NULL; | 124 return NULL; |
124 } | 125 } |
125 | 126 |
126 | 127 |
127 failed = 0; | 128 failed = 0; |
129 | |
130 | |
128 | 131 |
129 file = cycle->open_files.elts; | 132 file = cycle->open_files.elts; |
130 for (i = 0; i < cycle->open_files.nelts; i++) { | 133 for (i = 0; i < cycle->open_files.nelts; i++) { |
131 if (file[i].name.data == NULL) { | 134 if (file[i].name.data == NULL) { |
132 continue; | 135 continue; |
369 | 372 |
370 return cycle; | 373 return cycle; |
371 } | 374 } |
372 | 375 |
373 | 376 |
377 static ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle) | |
378 { | |
379 size_t len; | |
380 u_char pid[NGX_INT64_LEN + 1]; | |
381 ngx_str_t name; | |
382 ngx_core_conf_t *ccf; | |
383 | |
384 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
385 | |
386 if (ctx->pid.len) { | |
387 if (ccf->pid.len == 0) { | |
388 return NGX_OK; | |
389 } | |
390 | |
391 if (ctx->pid.len == ccf->pid.len | |
392 && ngx_strcmp(ctx->pid.data, ccf->pid.data) == 0) | |
393 { | |
394 return NGX_OK; | |
395 } | |
396 } | |
397 | |
398 if (ccf->pid.len == 0) { | |
399 ccf->pid.len = sizeof(NGINX_PID) - 1; | |
400 ccf->pid.data = NGINX_PID; | |
401 ccf->newpid.len = sizeof(NGINX_NEWPID) - 1; | |
402 ccf->newpid.data = NGINX_NEWPID; | |
403 | |
404 } else { | |
405 ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEWPID_EXT); | |
406 if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { | |
407 return NGX_ERROR; | |
408 } | |
409 | |
410 ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), | |
411 NGINX_NEWPID_EXT, sizeof(NGINX_NEWPID_EXT)); | |
412 } | |
413 | |
414 len = ngx_snprintf((char *) pid, NGX_INT64_LEN + 1, PID_T_FMT, ngx_pid); | |
415 ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); | |
416 ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; | |
417 ctx->name = ccf->pid.data; | |
418 | |
419 ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, | |
420 NGX_FILE_CREATE_OR_OPEN); | |
421 | |
422 if (ctx->pid.fd == NGX_INVALID_FILE) { | |
423 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
424 ngx_open_file_n " \"%s\" failed", ctx->pid.name.data); | |
425 return NGX_ERROR; | |
426 } | |
427 | |
428 if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) { | |
429 return NGX_ERROR; | |
430 } | |
431 | |
432 if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) { | |
433 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
434 ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); | |
435 } | |
436 | |
437 return NGX_OK; | |
438 } | |
439 | |
440 | |
441 static void ngx_delete_pidfile(ngx_cycle_t *cycle) | |
442 { | |
443 u_char *name; | |
444 ngx_core_conf_t *ccf; | |
445 | |
446 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | |
447 | |
448 if (ngx_inherited && getppid() > 1) { | |
449 name = ccf->newpid.data; | |
450 | |
451 } else { | |
452 name = ccf->pid.data; | |
453 } | |
454 | |
455 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | |
456 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | |
457 ngx_delete_file_n " \"%s\" failed", name); | |
458 } | |
459 } | |
460 | |
461 | |
374 void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) | 462 void ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user) |
375 { | 463 { |
376 ngx_fd_t fd; | 464 ngx_fd_t fd; |
377 ngx_uint_t i; | 465 ngx_uint_t i; |
378 ngx_open_file_t *file; | 466 ngx_open_file_t *file; |