Mercurial > hg > nginx-vendor-current
comparison src/core/ngx_file.c @ 516:7efcdb937752 NGINX_0_8_10
nginx 0.8.10
*) Bugfix: memory leaks if GeoIP City database was used.
*) Bugfix: in copying temporary files to permanent storage area; the
bug had appeared in 0.8.9.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 24 Aug 2009 00:00:00 +0400 |
parents | 43cc6f0b77ce |
children | 0dc162a5f3e8 |
comparison
equal
deleted
inserted
replaced
515:607556aed0a1 | 516:7efcdb937752 |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 | 9 |
10 | 10 |
11 static ngx_atomic_uint_t ngx_temp_number; | 11 static ngx_atomic_t temp_number = 0; |
12 static ngx_atomic_uint_t ngx_random_number; | 12 ngx_atomic_t *ngx_temp_number = &temp_number; |
13 ngx_atomic_int_t ngx_random_number = 123456; | |
13 | 14 |
14 | 15 |
15 ssize_t | 16 ssize_t |
16 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) | 17 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) |
17 { | 18 { |
203 | 204 |
204 return 0; | 205 return 0; |
205 } | 206 } |
206 | 207 |
207 | 208 |
208 void | |
209 ngx_init_temp_number(void) | |
210 { | |
211 ngx_temp_number = 0; | |
212 ngx_random_number = 123456; | |
213 } | |
214 | |
215 | |
216 ngx_atomic_uint_t | 209 ngx_atomic_uint_t |
217 ngx_next_temp_number(ngx_uint_t collision) | 210 ngx_next_temp_number(ngx_uint_t collision) |
218 { | 211 { |
219 if (collision) { | 212 ngx_atomic_uint_t n, add; |
220 ngx_temp_number += ngx_random_number; | 213 |
221 } | 214 add = collision ? ngx_random_number : 1; |
222 | 215 |
223 return ngx_temp_number++; | 216 n = ngx_atomic_fetch_add(ngx_temp_number, add); |
217 | |
218 return n + add; | |
224 } | 219 } |
225 | 220 |
226 | 221 |
227 char * | 222 char * |
228 ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 223 ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
574 if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) { | 569 if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) { |
575 return NGX_OK; | 570 return NGX_OK; |
576 } | 571 } |
577 | 572 |
578 err = ngx_errno; | 573 err = ngx_errno; |
579 goto failed; | |
580 } | 574 } |
581 | 575 |
582 #if (NGX_WIN32) | 576 #if (NGX_WIN32) |
583 | 577 |
584 if (err == NGX_EEXIST) { | 578 if (err == NGX_EEXIST) { |
603 cf.buf_size = 0; | 597 cf.buf_size = 0; |
604 cf.access = ext->access; | 598 cf.access = ext->access; |
605 cf.time = ext->time; | 599 cf.time = ext->time; |
606 cf.log = ext->log; | 600 cf.log = ext->log; |
607 | 601 |
608 name = ngx_alloc(to->len + 1 + 10, ext->log); | 602 name = ngx_alloc(to->len + 1 + 10 + 1, ext->log); |
609 if (name == NULL) { | 603 if (name == NULL) { |
610 return NGX_ERROR; | 604 return NGX_ERROR; |
611 } | 605 } |
612 | 606 |
613 (void) ngx_sprintf(name, "%*s.%010uD%Z", to->len - 1, to->data, | 607 (void) ngx_sprintf(name, "%*s.%010uD%Z", to->len, to->data, |
614 (uint32_t) ngx_next_temp_number(0)); | 608 (uint32_t) ngx_next_temp_number(0)); |
615 | 609 |
616 if (ngx_copy_file(src->data, name, &cf) == NGX_OK) { | 610 if (ngx_copy_file(src->data, name, &cf) == NGX_OK) { |
617 | 611 |
618 if (ngx_rename_file(name, to->data) == NGX_FILE_ERROR) { | 612 if (ngx_rename_file(name, to->data) != NGX_FILE_ERROR) { |
619 ngx_free(name); | 613 ngx_free(name); |
620 goto failed; | 614 |
621 } | 615 if (ngx_delete_file(src->data) == NGX_FILE_ERROR) { |
622 | 616 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
623 ngx_free(name); | 617 ngx_delete_file_n " \"%s\" failed", |
624 | 618 src->data); |
625 if (ngx_delete_file(src->data) == NGX_FILE_ERROR) { | 619 return NGX_ERROR; |
620 } | |
621 | |
622 return NGX_OK; | |
623 } | |
624 | |
625 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, | |
626 ngx_rename_file_n " \"%s\" to \"%s\" failed", | |
627 name, to->data); | |
628 | |
629 if (ngx_delete_file(name) == NGX_FILE_ERROR) { | |
626 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, | 630 ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno, |
627 ngx_delete_file_n " \"%s\" failed", src->data); | 631 ngx_delete_file_n " \"%s\" failed", name); |
628 | 632 |
629 return NGX_ERROR; | 633 } |
630 } | |
631 | |
632 return NGX_OK; | |
633 } | 634 } |
634 | 635 |
635 ngx_free(name); | 636 ngx_free(name); |
637 | |
638 err = 0; | |
636 } | 639 } |
637 | 640 |
638 failed: | 641 failed: |
639 | 642 |
640 if (ext->delete_file) { | 643 if (ext->delete_file) { |