Mercurial > hg > nginx
annotate src/os/unix/ngx_files.c @ 1937:c46432b9dbb7
fix case when errors are not cached,
and a file was not used often enough to keep open
and it has been removed before it was kept open
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 13 Mar 2008 12:59:25 +0000 |
parents | bb139aba3199 |
children | b5263e401884 |
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:
344
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:
344
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:
344
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:
344
diff
changeset
|
5 |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
33
b2e039840718
nginx-0.0.1-2002-12-19-20:49:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
7 #include <ngx_config.h> |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
8 #include <ngx_core.h> |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
9 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
10 |
561 | 11 ssize_t |
12 ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
13 { |
561 | 14 ssize_t n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
16 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
461 | 17 "read: %d, %p, %uz, %O", file->fd, buf, size, offset); |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
18 |
469 | 19 #if (NGX_HAVE_PREAD) |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
20 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
21 n = pread(file->fd, buf, size, offset); |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
22 |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
23 if (n == -1) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
24 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
25 "pread() failed, file \"%s\"", file->name.data); |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
26 return NGX_ERROR; |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
27 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
28 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
29 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
30 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
31 if (file->sys_offset != offset) { |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
32 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
33 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "lseek() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
34 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
35 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
36 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
37 file->sys_offset = offset; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
38 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
39 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
40 n = read(file->fd, buf, size); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
41 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
42 if (n == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
43 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "read() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
44 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
45 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
46 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
47 file->sys_offset += n; |
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
48 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
49 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
50 |
35
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
51 file->offset += n; |
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
52 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
53 return n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 } |
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
56 |
561 | 57 ssize_t |
58 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
59 { |
561 | 60 ssize_t n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
61 |
461 | 62 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
63 "write: %d, %p, %uz, %O", file->fd, buf, size, offset); | |
64 | |
469 | 65 #if (NGX_HAVE_PWRITE) |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
66 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
67 n = pwrite(file->fd, buf, size, offset); |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
68 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
69 if (n == -1) { |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
70 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "pwrite() failed"); |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
71 return NGX_ERROR; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
72 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
73 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
74 if ((size_t) n != size) { |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
75 ngx_log_error(NGX_LOG_CRIT, file->log, 0, |
461 | 76 "pwrite() has written only %z of %uz", n, size); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
77 return NGX_ERROR; |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
78 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
79 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
80 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
81 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
82 if (file->sys_offset != offset) { |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
83 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
84 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "lseek() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
85 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
86 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
87 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
88 file->sys_offset = offset; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
89 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
90 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
91 n = write(file->fd, buf, size); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
92 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
93 if (n == -1) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
94 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, "write() failed"); |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
95 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
96 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
97 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
98 if ((size_t) n != size) { |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
99 ngx_log_error(NGX_LOG_CRIT, file->log, 0, |
461 | 100 "write() has written only %z of %uz", n, size); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
101 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
102 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
103 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
104 file->sys_offset += n; |
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
105 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
106 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
107 |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
108 file->offset += n; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
109 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
110 return n; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
111 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
112 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
113 |
561 | 114 ngx_fd_t |
1046 | 115 ngx_open_tempfile(u_char *name, ngx_uint_t persistent, ngx_uint_t access) |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
116 { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
117 ngx_fd_t fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
118 |
1046 | 119 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, |
120 access ? access : 0600); | |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
121 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
122 if (fd != -1 && !persistent) { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
123 unlink((const char *) name); |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
124 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
125 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
126 return fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
127 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
128 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
129 |
461 | 130 #define NGX_IOVS 8 |
131 | |
561 | 132 ssize_t |
133 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
134 ngx_pool_t *pool) | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
135 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
136 u_char *prev; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
137 size_t size; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
138 ssize_t n; |
461 | 139 ngx_array_t vec; |
140 struct iovec *iov, iovs[NGX_IOVS]; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
141 |
461 | 142 /* use pwrite() if there is the only buf in a chain */ |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
143 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
144 if (cl->next == NULL) { |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
145 return ngx_write_file(file, cl->buf->pos, |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
146 (size_t) (cl->buf->last - cl->buf->pos), |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
191
diff
changeset
|
147 offset); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
148 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
149 |
461 | 150 vec.elts = iovs; |
151 vec.size = sizeof(struct iovec); | |
577 | 152 vec.nalloc = NGX_IOVS; |
461 | 153 vec.pool = pool; |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
154 |
461 | 155 do { |
156 prev = NULL; | |
157 iov = NULL; | |
158 size = 0; | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
159 |
461 | 160 vec.nelts = 0; |
161 | |
162 /* create the iovec and coalesce the neighbouring bufs */ | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
163 |
461 | 164 while (cl && vec.nelts < IOV_MAX) { |
165 if (prev == cl->buf->pos) { | |
166 iov->iov_len += cl->buf->last - cl->buf->pos; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
167 |
461 | 168 } else { |
501 | 169 iov = ngx_array_push(&vec); |
170 if (iov == NULL) { | |
461 | 171 return NGX_ERROR; |
172 } | |
173 | |
174 iov->iov_base = (void *) cl->buf->pos; | |
175 iov->iov_len = cl->buf->last - cl->buf->pos; | |
176 } | |
177 | |
178 size += cl->buf->last - cl->buf->pos; | |
179 prev = cl->buf->last; | |
180 cl = cl->next; | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
181 } |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
182 |
461 | 183 /* use pwrite() if there is the only iovec buffer */ |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
184 |
461 | 185 if (vec.nelts == 1) { |
186 iov = vec.elts; | |
187 return ngx_write_file(file, (u_char *) iov[0].iov_base, | |
188 iov[0].iov_len, offset); | |
189 } | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
190 |
461 | 191 if (file->sys_offset != offset) { |
192 if (lseek(file->fd, offset, SEEK_SET) == -1) { | |
193 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
194 "lseek() failed"); | |
195 return NGX_ERROR; | |
196 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
197 |
461 | 198 file->sys_offset = offset; |
199 } | |
200 | |
201 n = writev(file->fd, vec.elts, vec.nelts); | |
202 | |
203 if (n == -1) { | |
204 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
205 "writev() failed"); | |
154
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
206 return NGX_ERROR; |
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
207 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
208 |
461 | 209 if ((size_t) n != size) { |
210 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
211 "writev() has written only %z of %uz", n, size); | |
212 return NGX_ERROR; | |
213 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
214 |
461 | 215 file->sys_offset += n; |
216 file->offset += n; | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
217 |
461 | 218 } while (cl); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
219 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
220 return n; |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
221 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
222 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
223 |
561 | 224 ngx_int_t |
681 | 225 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
226 { | |
227 struct timeval tv[2]; | |
228 | |
229 tv[0].tv_sec = s; | |
230 tv[0].tv_usec = 0; | |
231 tv[1].tv_sec = s; | |
232 tv[1].tv_usec = 0; | |
233 | |
234 if (utimes((char *) name, tv) != -1) { | |
235 return NGX_OK; | |
236 } | |
237 | |
238 return NGX_ERROR; | |
239 } | |
240 | |
241 | |
242 ngx_int_t | |
561 | 243 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
244 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
245 dir->dir = opendir((const char *) name->data); |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
246 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
247 if (dir->dir == NULL) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
248 return NGX_ERROR; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
249 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
250 |
457 | 251 dir->valid_info = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
252 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
253 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
254 } |
561 | 255 |
256 | |
727 | 257 ngx_int_t |
258 ngx_open_glob(ngx_glob_t *gl) | |
259 { | |
735
72621ebef255
fix building on Linux and Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
727
diff
changeset
|
260 if (glob((char *) gl->pattern, GLOB_NOSORT, NULL, &gl->pglob) == 0) { |
727 | 261 return NGX_OK; |
262 } | |
263 | |
264 return NGX_ERROR; | |
265 } | |
266 | |
267 | |
268 ngx_int_t | |
269 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
270 { | |
735
72621ebef255
fix building on Linux and Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
727
diff
changeset
|
271 if (gl->n < (size_t) gl->pglob.gl_pathc) { |
727 | 272 |
273 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]); | |
274 name->data = (u_char *) gl->pglob.gl_pathv[gl->n]; | |
275 gl->n++; | |
276 | |
277 return NGX_OK; | |
278 } | |
279 | |
280 return NGX_DONE; | |
281 } | |
282 | |
283 | |
284 void | |
285 ngx_close_glob(ngx_glob_t *gl) | |
286 { | |
287 globfree(&gl->pglob); | |
288 } | |
289 | |
290 | |
611 | 291 ngx_err_t |
292 ngx_trylock_fd(ngx_fd_t fd) | |
561 | 293 { |
294 struct flock fl; | |
295 | |
611 | 296 fl.l_start = 0; |
297 fl.l_len = 0; | |
298 fl.l_pid = 0; | |
299 fl.l_type = F_WRLCK; | |
561 | 300 fl.l_whence = SEEK_SET; |
611 | 301 |
302 if (fcntl(fd, F_SETLK, &fl) == -1) { | |
303 return ngx_errno; | |
304 } | |
305 | |
306 return 0; | |
307 } | |
308 | |
309 | |
310 ngx_err_t | |
311 ngx_lock_fd(ngx_fd_t fd) | |
312 { | |
313 struct flock fl; | |
314 | |
315 fl.l_start = 0; | |
561 | 316 fl.l_len = 0; |
317 fl.l_pid = 0; | |
318 fl.l_type = F_WRLCK; | |
611 | 319 fl.l_whence = SEEK_SET; |
561 | 320 |
611 | 321 if (fcntl(fd, F_SETLKW, &fl) == -1) { |
322 return ngx_errno; | |
561 | 323 } |
324 | |
611 | 325 return 0; |
561 | 326 } |
327 | |
328 | |
611 | 329 ngx_err_t |
330 ngx_unlock_fd(ngx_fd_t fd) | |
561 | 331 { |
332 struct flock fl; | |
333 | |
611 | 334 fl.l_start = 0; |
561 | 335 fl.l_len = 0; |
336 fl.l_pid = 0; | |
337 fl.l_type = F_UNLCK; | |
611 | 338 fl.l_whence = SEEK_SET; |
561 | 339 |
611 | 340 if (fcntl(fd, F_SETLK, &fl) == -1) { |
341 return ngx_errno; | |
561 | 342 } |
343 | |
611 | 344 return 0; |
561 | 345 } |