comparison src/core/ngx_file.c @ 42:41ccba1aba45 NGINX_0_1_21

nginx 0.1.21 *) Bugfix: the ngx_http_stub_status_module showed incorrect statistics if "rtsig" method was used or if several worker process ran on SMP. *) Bugfix: nginx could not be built by the icc compiler on Linux or if the zlib-1.2.x library was building from sources. *) Bugfix: nginx could not be built on NetBSD 2.0.
author Igor Sysoev <http://sysoev.ru>
date Tue, 22 Feb 2005 00:00:00 +0300
parents e1ada20fc595
children 4989c3d25945
comparison
equal deleted inserted replaced
41:4d8e7a81b3a0 42:41ccba1aba45
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_uint_t ngx_temp_number; 11 static ngx_atomic_int_t ngx_temp_number;
12 static ngx_uint_t ngx_random; 12 static ngx_atomic_int_t ngx_random;
13 13
14 14
15 ssize_t ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) 15 ssize_t
16 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain)
16 { 17 {
17 ngx_int_t rc; 18 ngx_int_t rc;
18 19
19 if (tf->file.fd == NGX_INVALID_FILE) { 20 if (tf->file.fd == NGX_INVALID_FILE) {
20 rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, 21 rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool,
31 32
32 return ngx_write_chain_to_file(&tf->file, chain, tf->offset, tf->pool); 33 return ngx_write_chain_to_file(&tf->file, chain, tf->offset, tf->pool);
33 } 34 }
34 35
35 36
36 ngx_int_t ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, 37 ngx_int_t
37 ngx_pool_t *pool, int persistent) 38 ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool,
38 { 39 int persistent)
39 ngx_err_t err; 40 {
40 uint32_t num; 41 ngx_err_t err;
41 42 ngx_atomic_int_t n;
42 file->name.len = path->name.len + 1 + path->len + 10; 43
44 file->name.len = path->name.len + 1 + path->len + NGX_ATOMIC_T_LEN;
43 45
44 if (!(file->name.data = ngx_palloc(pool, file->name.len + 1))) { 46 if (!(file->name.data = ngx_palloc(pool, file->name.len + 1))) {
45 return NGX_ERROR; 47 return NGX_ERROR;
46 } 48 }
47 49
51 } 53 }
52 #endif 54 #endif
53 55
54 ngx_memcpy(file->name.data, path->name.data, path->name.len); 56 ngx_memcpy(file->name.data, path->name.data, path->name.len);
55 57
56 num = (uint32_t) ngx_next_temp_number(0); 58 n = ngx_next_temp_number(0);
57 59
58 for ( ;; ) { 60 for ( ;; ) {
59 ngx_sprintf(file->name.data + path->name.len + 1 + path->len, 61 ngx_sprintf(file->name.data + path->name.len + 1 + path->len,
60 "%010ui%Z", num); 62 "%0muA%Z", n);
61 63
62 ngx_create_hashed_filename(file, path); 64 ngx_create_hashed_filename(file, path);
63 65
64 #if 1 66 #if 1
65 file->fd = ngx_open_tempfile(file->name.data, persistent); 67 file->fd = ngx_open_tempfile(file->name.data, persistent);
75 } 77 }
76 78
77 err = ngx_errno; 79 err = ngx_errno;
78 80
79 if (err == NGX_EEXIST) { 81 if (err == NGX_EEXIST) {
80 num = ngx_next_temp_number(1); 82 n = ngx_next_temp_number(1);
81 continue; 83 continue;
82 } 84 }
83 85
84 if ((path->level[0] == 0) 86 if ((path->level[0] == 0)
85 || (err != NGX_ENOENT 87 || (err != NGX_ENOENT
99 } 101 }
100 } 102 }
101 } 103 }
102 104
103 105
104 void ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path) 106 void
107 ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path)
105 { 108 {
106 ngx_uint_t i, name, pos, level; 109 ngx_uint_t i, name, pos, level;
107 110
108 name = file->name.len; 111 name = file->name.len;
109 pos = path->name.len + 1; 112 pos = path->name.len + 1;
126 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, 129 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0,
127 "hashed path: %s", file->name.data); 130 "hashed path: %s", file->name.data);
128 } 131 }
129 132
130 133
131 ngx_int_t ngx_create_path(ngx_file_t *file, ngx_path_t *path) 134 ngx_int_t
135 ngx_create_path(ngx_file_t *file, ngx_path_t *path)
132 { 136 {
133 int i, pos; 137 int i, pos;
134 ngx_err_t err; 138 ngx_err_t err;
135 139
136 pos = path->name.len; 140 pos = path->name.len;
162 166
163 return NGX_OK; 167 return NGX_OK;
164 } 168 }
165 169
166 170
167 void ngx_init_temp_number() 171 void
168 { 172 ngx_init_temp_number()
169 ngx_random = 0; 173 {
170 174 ngx_temp_number = 0;
171 ngx_temp_number = ngx_random; 175 ngx_random = 123456;
172 176 }
173 while (ngx_random < 10000) { 177
174 ngx_random = 123456; 178
175 } 179 ngx_atomic_int_t
176 } 180 ngx_next_temp_number(ngx_uint_t collision)
177
178
179 ngx_uint_t ngx_next_temp_number(ngx_uint_t collision)
180 { 181 {
181 if (collision) { 182 if (collision) {
182 ngx_temp_number += ngx_random; 183 ngx_temp_number += ngx_random;
183 } 184 }
184 185
185 return ngx_temp_number++; 186 return ngx_temp_number++;
186 } 187 }
187 188
188 189
189 char *ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 190 char *
191 ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
190 { 192 {
191 char *p = conf; 193 char *p = conf;
192 194
193 ssize_t level; 195 ssize_t level;
194 ngx_uint_t i, n; 196 ngx_uint_t i, n;
235 237
236 return NGX_CONF_OK; 238 return NGX_CONF_OK;
237 } 239 }
238 240
239 241
240 ngx_int_t ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot) 242 ngx_int_t
243 ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot)
241 { 244 {
242 ngx_uint_t i, n; 245 ngx_uint_t i, n;
243 ngx_path_t *path, **p; 246 ngx_path_t *path, **p;
244 247
245 path = *slot; 248 path = *slot;
297 300
298 return NGX_OK; 301 return NGX_OK;
299 } 302 }
300 303
301 304
302 ngx_int_t ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user) 305 ngx_int_t
306 ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user)
303 { 307 {
304 ngx_err_t err; 308 ngx_err_t err;
305 ngx_uint_t i; 309 ngx_uint_t i;
306 ngx_path_t **path; 310 ngx_path_t **path;
307 #if !(NGX_WIN32) 311 #if !(NGX_WIN32)