Mercurial > hg > nginx-quic
annotate src/core/ngx_file.c @ 588:0a2c30f516e6
release-0.3.15 tag
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 07 Dec 2005 14:51:31 +0000 |
parents | 9c2f3ed7a247 |
children | 65bf042c0b4f |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
5 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
495 | 11 static ngx_atomic_uint_t ngx_temp_number; |
12 static ngx_atomic_uint_t ngx_random; | |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
13 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
14 |
493 | 15 ssize_t |
16 ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain) | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
17 { |
467 | 18 ngx_int_t rc; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
19 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
20 if (tf->file.fd == NGX_INVALID_FILE) { |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
21 rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool, |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
22 tf->persistent); |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
23 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
24 if (rc == NGX_ERROR || rc == NGX_AGAIN) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
25 return rc; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
26 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
27 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
28 if (!tf->persistent && tf->warn) { |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
29 ngx_log_error(NGX_LOG_WARN, tf->file.log, 0, tf->warn); |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
30 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
31 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
32 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
33 return ngx_write_chain_to_file(&tf->file, chain, tf->offset, tf->pool); |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
34 } |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
35 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
36 |
493 | 37 ngx_int_t |
38 ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool, | |
561 | 39 ngx_uint_t persistent) |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 { |
509 | 41 ngx_err_t err; |
42 ngx_atomic_uint_t n; | |
563 | 43 ngx_pool_cleanup_t *cln; |
44 ngx_pool_cleanup_file_t *clnf; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 |
493 | 46 file->name.len = path->name.len + 1 + path->len + NGX_ATOMIC_T_LEN; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 |
501 | 48 file->name.data = ngx_palloc(pool, file->name.len + 1); |
49 if (file->name.data == NULL) { | |
467 | 50 return NGX_ERROR; |
51 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 #if 0 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 for (i = 0; i < file->name.len; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 file->name.data[i] = 'X'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 #endif |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 ngx_memcpy(file->name.data, path->name.data, path->name.len); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 |
493 | 61 n = ngx_next_temp_number(0); |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
62 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 for ( ;; ) { |
517 | 64 (void) ngx_sprintf(file->name.data + path->name.len + 1 + path->len, |
65 "%0muA%Z", n); | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 ngx_create_hashed_filename(file, path); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 |
563 | 69 cln = ngx_pool_cleanup_add(pool, sizeof(ngx_pool_cleanup_file_t)); |
70 if (cln == NULL) { | |
71 return NGX_ERROR; | |
72 } | |
73 | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
74 #if 1 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
75 file->fd = ngx_open_tempfile(file->name.data, persistent); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 #else |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
77 file->fd = ngx_open_tempfile(file->name.data, 1); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 #endif |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
80 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
81 "temp fd:%d", file->fd); |
75
869b10be682f
nginx-0.0.1-2003-04-14-21:04:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
74
diff
changeset
|
82 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 if (file->fd != NGX_INVALID_FILE) { |
563 | 84 |
85 cln->handler = ngx_pool_cleanup_file; | |
86 clnf = cln->data; | |
509 | 87 |
563 | 88 clnf->fd = file->fd; |
89 clnf->name = file->name.data; | |
90 clnf->log = pool->log; | |
509 | 91 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 if (err == NGX_EEXIST) { |
493 | 98 n = ngx_next_temp_number(1); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 continue; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
102 if ((path->level[0] == 0) |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
103 || (err != NGX_ENOENT |
461 | 104 #if (NGX_WIN32) |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
105 && err != NGX_ENOTDIR |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 #endif |
467 | 107 )) |
108 { | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 ngx_open_tempfile_n " \"%s\" failed", |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 file->name.data); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 if (ngx_create_path(file, path) == NGX_ERROR) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 return NGX_ERROR; |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
117 } |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 |
493 | 122 void |
123 ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 { |
517 | 125 size_t name, pos, level; |
126 ngx_uint_t i; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 name = file->name.len; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 pos = path->name.len + 1; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 file->name.data[path->name.len + path->len] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 for (i = 0; i < 3; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 level = path->level[i]; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 if (level == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 name -= level; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 file->name.data[pos - 1] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 ngx_memcpy(&file->name.data[pos], &file->name.data[name], level); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 pos += level + 1; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
146 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
147 "hashed path: %s", file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 |
493 | 151 ngx_int_t |
152 ngx_create_path(ngx_file_t *file, ngx_path_t *path) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 { |
517 | 154 size_t pos; |
155 ngx_err_t err; | |
156 ngx_uint_t i; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 pos = path->name.len; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 for (i = 0; i < 3; i++) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 if (path->level[i] == 0) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 break; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 pos += path->level[i] + 1; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 file->name.data[pos] = '\0'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
169 ngx_log_debug1(NGX_LOG_DEBUG_CORE, file->log, 0, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
170 "temp file: \"%s\"", file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
172 if (ngx_create_dir(file->name.data) == NGX_FILE_ERROR) { |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 err = ngx_errno; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 if (err != NGX_EEXIST) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 ngx_log_error(NGX_LOG_CRIT, file->log, err, |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
176 ngx_create_dir_n " \"%s\" failed", |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
175
diff
changeset
|
177 file->name.data); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 file->name.data[pos] = '/'; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 return NGX_OK; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 } |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
187 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
188 |
493 | 189 void |
499 | 190 ngx_init_temp_number(void) |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
191 { |
493 | 192 ngx_temp_number = 0; |
193 ngx_random = 123456; | |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
194 } |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
195 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
196 |
495 | 197 ngx_atomic_uint_t |
493 | 198 ngx_next_temp_number(ngx_uint_t collision) |
83
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
199 { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
200 if (collision) { |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
201 ngx_temp_number += ngx_random; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
202 } |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
203 |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
204 return ngx_temp_number++; |
a7e45c45a95c
nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
205 } |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
206 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
207 |
493 | 208 char * |
209 ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
210 { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
211 char *p = conf; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
212 |
467 | 213 ssize_t level; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
214 ngx_uint_t i, n; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
215 ngx_str_t *value; |
479 | 216 ngx_path_t *path, **slot; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
217 |
467 | 218 slot = (ngx_path_t **) (p + cmd->offset); |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
219 |
467 | 220 if (*slot) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
221 return "is duplicate"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
222 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
223 |
501 | 224 path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
225 if (path == NULL) { | |
467 | 226 return NGX_CONF_ERROR; |
227 } | |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
228 |
467 | 229 value = cf->args->elts; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
230 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
231 path->name = value[1]; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
232 path->len = 0; |
479 | 233 path->cleaner = (ngx_gc_handler_pt) cmd->post; |
467 | 234 path->conf_file = cf->conf_file->file.name.data; |
235 path->line = cf->conf_file->line; | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
236 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
237 for (i = 0, n = 2; n < cf->args->nelts; i++, n++) { |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
238 level = ngx_atoi(value[n].data, value[n].len); |
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
239 if (level == NGX_ERROR || level == 0) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
240 return "invalid value"; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
241 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
242 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
243 path->level[i] = level; |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
244 path->len += level + 1; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
245 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
246 |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
247 while (i < 3) { |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
248 path->level[i++] = 0; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
249 } |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
250 |
479 | 251 *slot = path; |
467 | 252 |
479 | 253 if (ngx_add_path(cf, slot) == NGX_ERROR) { |
254 return NGX_CONF_ERROR; | |
255 } | |
256 | |
257 return NGX_CONF_OK; | |
258 } | |
259 | |
260 | |
493 | 261 ngx_int_t |
262 ngx_add_path(ngx_conf_t *cf, ngx_path_t **slot) | |
479 | 263 { |
264 ngx_uint_t i, n; | |
265 ngx_path_t *path, **p; | |
266 | |
267 path = *slot; | |
268 | |
269 p = cf->cycle->pathes.elts; | |
467 | 270 for (i = 0; i < cf->cycle->pathes.nelts; i++) { |
479 | 271 if (p[i]->name.len == path->name.len |
272 && ngx_strcmp(p[i]->name.data, path->name.data) == 0) | |
467 | 273 { |
274 for (n = 0; n < 3; n++) { | |
479 | 275 if (p[i]->level[n] != path->level[n]) { |
276 if (path->conf_file == NULL) { | |
481 | 277 if (p[i]->conf_file == NULL) { |
278 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
279 "the default path name \"%V\" has " | |
280 "the same name as another default path, " | |
281 "but the different levels, you need to " | |
282 "redefine one of them in http section", | |
283 &p[i]->name); | |
284 return NGX_ERROR; | |
285 } | |
286 | |
479 | 287 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
288 "the path name \"%V\" in %s:%ui has " | |
481 | 289 "the same name as default path, but " |
479 | 290 "the different levels, you need to " |
291 "define default path in http section", | |
292 &p[i]->name, p[i]->conf_file, p[i]->line); | |
293 return NGX_ERROR; | |
294 } | |
295 | |
467 | 296 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
479 | 297 "the same path name \"%V\" in %s:%ui " |
298 "has the different levels than", | |
299 &p[i]->name, p[i]->conf_file, p[i]->line); | |
300 return NGX_ERROR; | |
467 | 301 } |
302 | |
479 | 303 if (p[i]->level[n] == 0) { |
467 | 304 break; |
305 } | |
306 } | |
307 | |
479 | 308 *slot = p[i]; |
467 | 309 |
479 | 310 return NGX_OK; |
467 | 311 } |
312 } | |
313 | |
501 | 314 p = ngx_array_push(&cf->cycle->pathes); |
315 if (p == NULL) { | |
479 | 316 return NGX_ERROR; |
467 | 317 } |
318 | |
479 | 319 *p = path; |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
320 |
479 | 321 return NGX_OK; |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
322 } |
467 | 323 |
324 | |
493 | 325 ngx_int_t |
326 ngx_create_pathes(ngx_cycle_t *cycle, ngx_uid_t user) | |
467 | 327 { |
328 ngx_err_t err; | |
329 ngx_uint_t i; | |
330 ngx_path_t **path; | |
331 #if !(NGX_WIN32) | |
332 ngx_file_info_t fi; | |
333 #endif | |
334 | |
335 path = cycle->pathes.elts; | |
336 for (i = 0; i < cycle->pathes.nelts; i++) { | |
337 | |
338 if (ngx_create_dir(path[i]->name.data) == NGX_FILE_ERROR) { | |
339 err = ngx_errno; | |
340 if (err != NGX_EEXIST) { | |
341 ngx_log_error(NGX_LOG_EMERG, cycle->log, err, | |
342 ngx_create_dir_n " \"%s\" failed", | |
343 path[i]->name.data); | |
344 return NGX_ERROR; | |
345 } | |
346 } | |
347 | |
517 | 348 if (user == (ngx_uid_t) NGX_CONF_UNSET_UINT) { |
467 | 349 continue; |
350 } | |
351 | |
352 #if !(NGX_WIN32) | |
353 | |
354 if (ngx_file_info((const char *) path[i]->name.data, &fi) == -1) { | |
355 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
356 ngx_file_info_n " \"%s\" failed", path[i]->name.data); | |
357 return NGX_ERROR; | |
358 } | |
359 | |
360 if (fi.st_uid != user) { | |
361 if (chown((const char *) path[i]->name.data, user, -1) == -1) { | |
362 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
363 "chown(\"%s\", %d) failed", | |
364 path[i]->name.data, user); | |
365 return NGX_ERROR; | |
366 } | |
367 } | |
368 | |
369 if ((fi.st_mode & (S_IRUSR|S_IWUSR|S_IXUSR)) | |
370 != (S_IRUSR|S_IWUSR|S_IXUSR)) | |
371 { | |
372 fi.st_mode |= (S_IRUSR|S_IWUSR|S_IXUSR); | |
373 | |
374 if (chmod((const char *) path[i]->name.data, fi.st_mode) == -1) { | |
375 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | |
376 "chmod() \"%s\" failed", path[i]->name.data); | |
377 return NGX_ERROR; | |
378 } | |
379 } | |
380 | |
381 #endif | |
382 } | |
383 | |
384 return NGX_OK; | |
385 } |