Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_files.c @ 4016:b044d6553d52
Move SO_ACCEPTFILTER and TCP_DEFER_ACCEPT checks into configure.
NetBSD 5.0+ has SO_ACCEPTFILTER support merged from FreeBSD, and having
accept filter check in FreeBSD-specific ngx_freebsd_config.h prevents it
from being used on NetBSD. Therefore move the check into configure (and
do the same for Linux-specific TCP_DEFER_ACCEPT, just to be in line).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 21 Aug 2011 11:37:37 +0000 |
parents | cf80c0b0109a |
children | 4be8dd8dd547 d1d34de1a419 |
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 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
11 #if (NGX_HAVE_FILE_AIO) |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
12 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
13 ngx_uint_t ngx_file_aio = 1; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
14 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
15 #endif |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
16 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
17 |
561 | 18 ssize_t |
19 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
|
20 { |
561 | 21 ssize_t n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
196
diff
changeset
|
23 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
461 | 24 "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
|
25 |
469 | 26 #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
|
27 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
28 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
|
29 |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
30 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
|
31 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
32 "pread() \"%s\" failed", 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
|
33 return NGX_ERROR; |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
34 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
35 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
36 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
37 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
38 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
|
39 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
40 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
41 "lseek() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
42 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
43 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
44 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
45 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
|
46 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
47 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
48 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
|
49 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
50 if (n == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
51 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
52 "read() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
53 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
54 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
55 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
56 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
|
57 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
58 #endif |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
59 |
35
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
60 file->offset += n; |
79c1fce18e71
nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
61 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
6
diff
changeset
|
62 return n; |
5
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 } |
62b1a364857c
nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
65 |
561 | 66 ssize_t |
67 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
|
68 { |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
69 ssize_t n, written; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
70 |
461 | 71 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, |
72 "write: %d, %p, %uz, %O", file->fd, buf, size, offset); | |
73 | |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
74 written = 0; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
75 |
469 | 76 #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
|
77 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
78 for ( ;; ) { |
3657 | 79 n = pwrite(file->fd, buf + written, size, offset); |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
80 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
81 if (n == -1) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
82 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
83 "pwrite() \"%s\" failed", file->name.data); |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
84 return NGX_ERROR; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
85 } |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
86 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
87 file->offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
88 written += n; |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
89 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
90 if ((size_t) n == size) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
91 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
92 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
93 |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
94 offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
95 size -= n; |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
96 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
97 |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
98 #else |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
99 |
190
02a715e85df1
nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
100 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
|
101 if (lseek(file->fd, offset, SEEK_SET) == -1) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
102 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
103 "lseek() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
104 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
105 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
106 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
107 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
|
108 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
109 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
110 for ( ;; ) { |
3657 | 111 n = write(file->fd, buf + written, size); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
112 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
113 if (n == -1) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
114 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
115 "write() \"%s\" failed", file->name.data); |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
116 return NGX_ERROR; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
117 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
118 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
119 file->offset += n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
120 written += n; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
121 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
122 if ((size_t) n == size) { |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
123 return written; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
124 } |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
170
diff
changeset
|
125 |
3163
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
126 size -= n; |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
127 } |
34cbd6e86218
handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents:
3157
diff
changeset
|
128 #endif |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
129 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
130 |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
131 |
561 | 132 ngx_fd_t |
1046 | 133 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
|
134 { |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
135 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
|
136 |
1046 | 137 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, |
138 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
|
139 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
140 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
|
141 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
|
142 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
143 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
144 return fd; |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
145 } |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
146 |
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
147 |
461 | 148 #define NGX_IOVS 8 |
149 | |
561 | 150 ssize_t |
151 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
152 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
|
153 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
154 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
|
155 size_t size; |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
156 ssize_t n; |
461 | 157 ngx_array_t vec; |
158 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
|
159 |
461 | 160 /* 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
|
161 |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
162 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
|
163 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
|
164 (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
|
165 offset); |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
166 } |
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
167 |
461 | 168 vec.elts = iovs; |
169 vec.size = sizeof(struct iovec); | |
577 | 170 vec.nalloc = NGX_IOVS; |
461 | 171 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
|
172 |
461 | 173 do { |
174 prev = NULL; | |
175 iov = NULL; | |
176 size = 0; | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
177 |
461 | 178 vec.nelts = 0; |
179 | |
180 /* 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
|
181 |
461 | 182 while (cl && vec.nelts < IOV_MAX) { |
183 if (prev == cl->buf->pos) { | |
184 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
|
185 |
461 | 186 } else { |
501 | 187 iov = ngx_array_push(&vec); |
188 if (iov == NULL) { | |
461 | 189 return NGX_ERROR; |
190 } | |
191 | |
192 iov->iov_base = (void *) cl->buf->pos; | |
193 iov->iov_len = cl->buf->last - cl->buf->pos; | |
194 } | |
195 | |
196 size += cl->buf->last - cl->buf->pos; | |
197 prev = cl->buf->last; | |
198 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
|
199 } |
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
200 |
461 | 201 /* 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
|
202 |
461 | 203 if (vec.nelts == 1) { |
204 iov = vec.elts; | |
205 return ngx_write_file(file, (u_char *) iov[0].iov_base, | |
206 iov[0].iov_len, offset); | |
207 } | |
170
c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
208 |
461 | 209 if (file->sys_offset != offset) { |
210 if (lseek(file->fd, offset, SEEK_SET) == -1) { | |
211 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
212 "lseek() \"%s\" failed", file->name.data); |
461 | 213 return NGX_ERROR; |
214 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
215 |
461 | 216 file->sys_offset = offset; |
217 } | |
218 | |
219 n = writev(file->fd, vec.elts, vec.nelts); | |
220 | |
221 if (n == -1) { | |
222 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, | |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
223 "writev() \"%s\" failed", file->name.data); |
154
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
224 return NGX_ERROR; |
eac26585476e
nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
225 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
190
diff
changeset
|
226 |
461 | 227 if ((size_t) n != size) { |
228 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
229 "writev() \"%s\" has written only %z of %uz", |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
230 file->name.data, n, size); |
461 | 231 return NGX_ERROR; |
232 } | |
74
17ab1af8c3dd
nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
73
diff
changeset
|
233 |
461 | 234 file->sys_offset += n; |
235 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
|
236 |
461 | 237 } while (cl); |
73
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
238 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
239 return n; |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
240 } |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
241 |
4534060fde92
nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
242 |
561 | 243 ngx_int_t |
681 | 244 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
245 { | |
246 struct timeval tv[2]; | |
247 | |
3861
cf80c0b0109a
set current atime while setting mtime
Igor Sysoev <igor@sysoev.ru>
parents:
3657
diff
changeset
|
248 tv[0].tv_sec = ngx_time(); |
681 | 249 tv[0].tv_usec = 0; |
250 tv[1].tv_sec = s; | |
251 tv[1].tv_usec = 0; | |
252 | |
253 if (utimes((char *) name, tv) != -1) { | |
254 return NGX_OK; | |
255 } | |
256 | |
257 return NGX_ERROR; | |
258 } | |
259 | |
260 | |
261 ngx_int_t | |
3651 | 262 ngx_create_file_mapping(ngx_file_mapping_t *fm) |
263 { | |
264 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
265 NGX_FILE_DEFAULT_ACCESS); | |
266 if (fm->fd == NGX_INVALID_FILE) { | |
267 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
268 ngx_open_file_n " \"%s\" failed", fm->name); | |
269 return NGX_ERROR; | |
270 } | |
271 | |
272 if (ftruncate(fm->fd, fm->size) == -1) { | |
273 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
274 "ftruncate() \"%s\" failed", fm->name); | |
275 goto failed; | |
276 } | |
277 | |
278 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED, | |
279 fm->fd, 0); | |
280 if (fm->addr != MAP_FAILED) { | |
281 return NGX_OK; | |
282 } | |
283 | |
284 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
285 "mmap(%uz) \"%s\" failed", fm->size, fm->name); | |
286 | |
287 failed: | |
288 | |
289 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
290 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
291 ngx_close_file_n " \"%s\" failed", fm->name); | |
292 } | |
293 | |
294 return NGX_ERROR; | |
295 } | |
296 | |
297 | |
298 void | |
299 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
300 { | |
301 if (munmap(fm->addr, fm->size) == -1) { | |
302 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
303 "munmap(%uz) \"%s\" failed", fm->size, fm->name); | |
304 } | |
305 | |
306 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
307 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
308 ngx_close_file_n " \"%s\" failed", fm->name); | |
309 } | |
310 } | |
311 | |
312 | |
313 ngx_int_t | |
561 | 314 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
|
315 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
278
diff
changeset
|
316 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
|
317 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
318 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
|
319 return NGX_ERROR; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
320 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
321 |
457 | 322 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
|
323 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
324 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
325 } |
561 | 326 |
327 | |
727 | 328 ngx_int_t |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
329 ngx_read_dir(ngx_dir_t *dir) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
330 { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
331 dir->de = readdir(dir->dir); |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
332 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
333 if (dir->de) { |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
334 #if (NGX_HAVE_D_TYPE) |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
335 dir->type = dir->de->d_type; |
2550
5e87ddb4764f
XFS on Linux does not set dirent.d_type,
Igor Sysoev <igor@sysoev.ru>
parents:
2248
diff
changeset
|
336 #else |
3200
26784c34e8be
*) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents:
3164
diff
changeset
|
337 dir->type = 0; |
2234
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
338 #endif |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
339 return NGX_OK; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
340 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
341 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
342 return NGX_ERROR; |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
343 } |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
344 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
345 |
c7c319896bb4
*) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents:
2210
diff
changeset
|
346 ngx_int_t |
727 | 347 ngx_open_glob(ngx_glob_t *gl) |
348 { | |
1980 | 349 int n; |
350 | |
351 n = glob((char *) gl->pattern, GLOB_NOSORT, NULL, &gl->pglob); | |
352 | |
353 if (n == 0) { | |
354 return NGX_OK; | |
355 } | |
356 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
357 #ifdef GLOB_NOMATCH |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
358 |
1980 | 359 if (n == GLOB_NOMATCH && gl->test) { |
727 | 360 return NGX_OK; |
361 } | |
362 | |
2199
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
363 #endif |
ffb512f0eabd
fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
364 |
727 | 365 return NGX_ERROR; |
366 } | |
367 | |
368 | |
369 ngx_int_t | |
370 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
371 { | |
2210
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
372 size_t count; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
373 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
374 #ifdef GLOB_NOMATCH |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
375 count = (size_t) gl->pglob.gl_pathc; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
376 #else |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
377 count = (size_t) gl->pglob.gl_matchc; |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
378 #endif |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
379 |
2cae41e51622
fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents:
2199
diff
changeset
|
380 if (gl->n < count) { |
727 | 381 |
382 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]); | |
383 name->data = (u_char *) gl->pglob.gl_pathv[gl->n]; | |
384 gl->n++; | |
385 | |
386 return NGX_OK; | |
387 } | |
388 | |
389 return NGX_DONE; | |
390 } | |
391 | |
392 | |
393 void | |
394 ngx_close_glob(ngx_glob_t *gl) | |
395 { | |
396 globfree(&gl->pglob); | |
397 } | |
398 | |
399 | |
611 | 400 ngx_err_t |
401 ngx_trylock_fd(ngx_fd_t fd) | |
561 | 402 { |
403 struct flock fl; | |
404 | |
611 | 405 fl.l_start = 0; |
406 fl.l_len = 0; | |
407 fl.l_pid = 0; | |
408 fl.l_type = F_WRLCK; | |
561 | 409 fl.l_whence = SEEK_SET; |
611 | 410 |
411 if (fcntl(fd, F_SETLK, &fl) == -1) { | |
412 return ngx_errno; | |
413 } | |
414 | |
415 return 0; | |
416 } | |
417 | |
418 | |
419 ngx_err_t | |
420 ngx_lock_fd(ngx_fd_t fd) | |
421 { | |
422 struct flock fl; | |
423 | |
424 fl.l_start = 0; | |
561 | 425 fl.l_len = 0; |
426 fl.l_pid = 0; | |
427 fl.l_type = F_WRLCK; | |
611 | 428 fl.l_whence = SEEK_SET; |
561 | 429 |
611 | 430 if (fcntl(fd, F_SETLKW, &fl) == -1) { |
431 return ngx_errno; | |
561 | 432 } |
433 | |
611 | 434 return 0; |
561 | 435 } |
436 | |
437 | |
611 | 438 ngx_err_t |
439 ngx_unlock_fd(ngx_fd_t fd) | |
561 | 440 { |
441 struct flock fl; | |
442 | |
611 | 443 fl.l_start = 0; |
561 | 444 fl.l_len = 0; |
445 fl.l_pid = 0; | |
446 fl.l_type = F_UNLCK; | |
611 | 447 fl.l_whence = SEEK_SET; |
561 | 448 |
611 | 449 if (fcntl(fd, F_SETLK, &fl) == -1) { |
450 return ngx_errno; | |
561 | 451 } |
452 | |
611 | 453 return 0; |
561 | 454 } |
2129 | 455 |
456 | |
3322
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
457 #if (NGX_HAVE_POSIX_FADVISE) |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
458 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
459 ngx_int_t |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
460 ngx_read_ahead(ngx_fd_t fd, size_t n) |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
461 { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
462 int err; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
463 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
464 err = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
465 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
466 if (err == 0) { |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
467 return 0; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
468 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
469 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
470 ngx_set_errno(err); |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
471 return NGX_FILE_ERROR; |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
472 } |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
473 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
474 #endif |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
475 |
e19df6e65352
fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
476 |
2129 | 477 #if (NGX_HAVE_O_DIRECT) |
478 | |
479 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
480 ngx_directio_on(ngx_fd_t fd) |
2129 | 481 { |
482 int flags; | |
483 | |
484 flags = fcntl(fd, F_GETFL); | |
485 | |
486 if (flags == -1) { | |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
487 return NGX_FILE_ERROR; |
2129 | 488 } |
489 | |
490 return fcntl(fd, F_SETFL, flags | O_DIRECT); | |
491 } | |
492 | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
493 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
494 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
495 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
496 { |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
497 int flags; |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
498 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
499 flags = fcntl(fd, F_GETFL); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
500 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
501 if (flags == -1) { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3163
diff
changeset
|
502 return NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
503 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
504 |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
505 return fcntl(fd, F_SETFL, flags & ~O_DIRECT); |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
506 } |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
507 |
2129 | 508 #endif |
2615 | 509 |
510 | |
511 #if (NGX_HAVE_STATFS) | |
512 | |
513 size_t | |
514 ngx_fs_bsize(u_char *name) | |
515 { | |
516 struct statfs fs; | |
517 | |
518 if (statfs((char *) name, &fs) == -1) { | |
519 return 512; | |
520 } | |
521 | |
522 if ((fs.f_bsize % 512) != 0) { | |
523 return 512; | |
524 } | |
525 | |
526 return (size_t) fs.f_bsize; | |
527 } | |
528 | |
529 #elif (NGX_HAVE_STATVFS) | |
530 | |
531 size_t | |
532 ngx_fs_bsize(u_char *name) | |
533 { | |
534 struct statvfs fs; | |
535 | |
536 if (statvfs((char *) name, &fs) == -1) { | |
537 return 512; | |
538 } | |
539 | |
540 if ((fs.f_frsize % 512) != 0) { | |
541 return 512; | |
542 } | |
543 | |
544 return (size_t) fs.f_frsize; | |
545 } | |
546 | |
547 #else | |
548 | |
549 size_t | |
550 ngx_fs_bsize(u_char *name) | |
551 { | |
552 return 512; | |
553 } | |
554 | |
555 #endif |