annotate src/os/unix/ngx_files.c @ 6299:5170c3040ce1

Handled EINTR from write() and pwrite() syscalls. This is in addition to 6fce16b1fc10.
author Valentin Bartenev <vbart@nginx.com>
date Tue, 17 Nov 2015 19:01:41 +0300
parents 8f6d753c1953
children be6af0906a4d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4299
diff changeset
4 * Copyright (C) Nginx, Inc.
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
5 */
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
6
5
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
33
b2e039840718 nginx-0.0.1-2002-12-19-20:49:51 import
Igor Sysoev <igor@sysoev.ru>
parents: 9
diff changeset
8 #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
9 #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
10
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
11
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
12 #if (NGX_THREADS)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
13 #include <ngx_thread_pool.h>
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
14 static void ngx_thread_read_handler(void *data, ngx_log_t *log);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
15 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
16
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
17
3294
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
18 #if (NGX_HAVE_FILE_AIO)
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
19
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
20 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
21
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
22 #endif
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
23
04cfc09b8b8d export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents: 3200
diff changeset
24
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
25 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
26 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
27 {
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
28 ssize_t n;
5
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 196
diff changeset
30 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
31 "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
32
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
33 #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
34
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
35 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
36
9
6f58641241bb nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
37 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
38 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
39 "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
40 return NGX_ERROR;
6f58641241bb nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
41 }
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
42
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
43 #else
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
44
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
45 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
46 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
47 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
48 "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
49 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
50 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
51
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
52 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
53 }
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 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
56
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
57 if (n == -1) {
3157
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
58 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
59 "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
60 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
61 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
62
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
63 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
64
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
65 #endif
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
66
35
79c1fce18e71 nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 33
diff changeset
67 file->offset += n;
79c1fce18e71 nginx-0.0.1-2002-12-21-20:14:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 33
diff changeset
68
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
69 return n;
5
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 }
62b1a364857c nginx-0.0.1-2002-08-23-20:14:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
72
6022
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
73 #if (NGX_THREADS)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
74
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
75 typedef struct {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
76 ngx_fd_t fd;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
77 u_char *buf;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
78 size_t size;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
79 off_t offset;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
80
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
81 size_t read;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
82 ngx_err_t err;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
83 } ngx_thread_read_ctx_t;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
84
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
85
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
86 ssize_t
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
87 ngx_thread_read(ngx_thread_task_t **taskp, ngx_file_t *file, u_char *buf,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
88 size_t size, off_t offset, ngx_pool_t *pool)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
89 {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
90 ngx_thread_task_t *task;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
91 ngx_thread_read_ctx_t *ctx;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
92
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
93 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
94 "thread read: %d, %p, %uz, %O",
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
95 file->fd, buf, size, offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
96
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
97 task = *taskp;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
98
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
99 if (task == NULL) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
100 task = ngx_thread_task_alloc(pool, sizeof(ngx_thread_read_ctx_t));
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
101 if (task == NULL) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
102 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
103 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
104
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
105 task->handler = ngx_thread_read_handler;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
106
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
107 *taskp = task;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
108 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
109
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
110 ctx = task->ctx;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
111
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
112 if (task->event.complete) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
113 task->event.complete = 0;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
114
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
115 if (ctx->err) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
116 ngx_log_error(NGX_LOG_CRIT, file->log, ctx->err,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
117 "pread() \"%s\" failed", file->name.data);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
118 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
119 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
120
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
121 return ctx->read;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
122 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
123
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
124 ctx->fd = file->fd;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
125 ctx->buf = buf;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
126 ctx->size = size;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
127 ctx->offset = offset;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
128
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
129 if (file->thread_handler(task, file) != NGX_OK) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
130 return NGX_ERROR;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
131 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
132
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
133 return NGX_AGAIN;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
134 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
135
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
136
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
137 #if (NGX_HAVE_PREAD)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
138
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
139 static void
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
140 ngx_thread_read_handler(void *data, ngx_log_t *log)
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
141 {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
142 ngx_thread_read_ctx_t *ctx = data;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
143
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
144 ssize_t n;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
145
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
146 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "thread read handler");
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
147
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
148 n = pread(ctx->fd, ctx->buf, ctx->size, ctx->offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
149
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
150 if (n == -1) {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
151 ctx->err = ngx_errno;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
152
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
153 } else {
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
154 ctx->read = n;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
155 ctx->err = 0;
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
156 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
157
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
158 #if 0
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
159 ngx_time_update();
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
160 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
161
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
162 ngx_log_debug4(NGX_LOG_DEBUG_CORE, log, 0,
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
163 "pread: %z (err: %i) of %uz @%O",
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
164 n, ctx->err, ctx->size, ctx->offset);
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
165 }
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
166
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
167 #else
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
168
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
169 #error pread() is required!
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
170
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
171 #endif
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
172
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
173 #endif /* NGX_THREADS */
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
174
1fdba317ee6d Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents: 4943
diff changeset
175
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
176 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
177 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
178 {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
179 ssize_t n, written;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
180 ngx_err_t err;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
181
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
182 ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0,
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
183 "write: %d, %p, %uz, %O", file->fd, buf, size, offset);
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
184
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
185 written = 0;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
186
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
187 #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
188
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
189 for ( ;; ) {
3657
fbd7dad43a4e fix ngx_write_file() buf
Igor Sysoev <igor@sysoev.ru>
parents: 3651
diff changeset
190 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
191
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
192 if (n == -1) {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
193 err = ngx_errno;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
194
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
195 if (err == NGX_EINTR) {
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
196 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
197 "pwrite() was interrupted");
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
198 continue;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
199 }
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
200
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
201 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
202 "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
203 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
204 }
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
205
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
206 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
207 written += n;
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
208
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
209 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
210 return written;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
211 }
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
212
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
213 offset += n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
214 size -= n;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
215 }
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
216
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
217 #else
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
218
190
02a715e85df1 nginx-0.0.1-2003-11-19-00:34:08 import
Igor Sysoev <igor@sysoev.ru>
parents: 186
diff changeset
219 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
220 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
221 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
222 "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
223 return NGX_ERROR;
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
224 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
225
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
226 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
227 }
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
228
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
229 for ( ;; ) {
3657
fbd7dad43a4e fix ngx_write_file() buf
Igor Sysoev <igor@sysoev.ru>
parents: 3651
diff changeset
230 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
231
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
232 if (n == -1) {
6299
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
233 err = ngx_errno;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
234
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
235 if (err == NGX_EINTR) {
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
236 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
237 "write() was interrupted");
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
238 continue;
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
239 }
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
240
5170c3040ce1 Handled EINTR from write() and pwrite() syscalls.
Valentin Bartenev <vbart@nginx.com>
parents: 6298
diff changeset
241 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
242 "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
243 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
244 }
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
245
6298
8f6d753c1953 Adjusted file->sys_offset after the write() syscall.
Valentin Bartenev <vbart@nginx.com>
parents: 6241
diff changeset
246 file->sys_offset += n;
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
247 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
248 written += n;
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
249
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
250 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
251 return written;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
252 }
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 170
diff changeset
253
3163
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
254 size -= n;
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
255 }
34cbd6e86218 handle short pwrite() to log an error cause: ENOSPC, EDQUOT, or EFBIG
Igor Sysoev <igor@sysoev.ru>
parents: 3157
diff changeset
256 #endif
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
257 }
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
258
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
259
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
260 ngx_fd_t
1046
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
261 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
262 {
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
263 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
264
1046
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
265 fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR,
bb139aba3199 rename mode to access
Igor Sysoev <igor@sysoev.ru>
parents: 735
diff changeset
266 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
267
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
268 if (fd != -1 && !persistent) {
4794
4163fb9dcfcb Explicitly ignore returned value from unlink() in ngx_open_tempfile().
Andrey Belov <defan@nginx.com>
parents: 4737
diff changeset
269 (void) unlink((const char *) name);
303
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
270 }
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
271
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
272 return fd;
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
273 }
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
274
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
275
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
276 #define NGX_IOVS 8
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
277
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
278 ssize_t
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
279 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
280 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
281 {
290
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 278
diff changeset
282 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
283 size_t size;
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
284 ssize_t total, n;
6240
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
285 ngx_err_t err;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
286 ngx_array_t vec;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
287 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
288
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
289 /* 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
290
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
291 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
292 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
293 (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
294 offset);
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
295 }
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
296
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
297 total = 0;
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
298
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
299 vec.elts = iovs;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
300 vec.size = sizeof(struct iovec);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
301 vec.nalloc = NGX_IOVS;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
302 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
303
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
304 do {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
305 prev = NULL;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
306 iov = NULL;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
307 size = 0;
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
308
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
309 vec.nelts = 0;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
310
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
311 /* 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
312
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
313 while (cl && vec.nelts < IOV_MAX) {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
314 if (prev == cl->buf->pos) {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
315 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
316
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
317 } else {
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
318 iov = ngx_array_push(&vec);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
319 if (iov == NULL) {
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
320 return NGX_ERROR;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
321 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
322
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
323 iov->iov_base = (void *) cl->buf->pos;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
324 iov->iov_len = cl->buf->last - cl->buf->pos;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
325 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
326
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
327 size += cl->buf->last - cl->buf->pos;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
328 prev = cl->buf->last;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
329 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
330 }
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
331
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
332 /* 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
333
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
334 if (vec.nelts == 1) {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
335 iov = vec.elts;
4221
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
336
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
337 n = ngx_write_file(file, (u_char *) iov[0].iov_base,
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
338 iov[0].iov_len, offset);
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
339
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
340 if (n == NGX_ERROR) {
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
341 return n;
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
342 }
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
343
3203ddb78279 Fixed another return in unix ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4220
diff changeset
344 return total + n;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
345 }
170
c42be4185301 nginx-0.0.1-2003-11-03-01:56:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
346
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
347 if (file->sys_offset != offset) {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
348 if (lseek(file->fd, offset, SEEK_SET) == -1) {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
349 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
350 "lseek() \"%s\" failed", file->name.data);
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
351 return NGX_ERROR;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
352 }
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
353
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
354 file->sys_offset = offset;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
355 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
356
6240
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
357 eintr:
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
358
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
359 n = writev(file->fd, vec.elts, vec.nelts);
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
360
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
361 if (n == -1) {
6240
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
362 err = ngx_errno;
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
363
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
364 if (err == NGX_EINTR) {
6241
387696b36c29 Fixed building --with-debug, broken by 6fce16b1fc10.
Valentin Bartenev <vbart@nginx.com>
parents: 6240
diff changeset
365 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
6240
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
366 "writev() was interrupted");
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
367 goto eintr;
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
368 }
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
369
6fce16b1fc10 Writing to some file systems can be interrupted.
Valentin Bartenev <vbart@nginx.com>
parents: 6022
diff changeset
370 ngx_log_error(NGX_LOG_CRIT, file->log, err,
3157
a2c1b4f74ea7 log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents: 2615
diff changeset
371 "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
372 return NGX_ERROR;
eac26585476e nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents: 75
diff changeset
373 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 190
diff changeset
374
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
375 if ((size_t) n != size) {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
376 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
377 "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
378 file->name.data, n, size);
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
379 return NGX_ERROR;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
380 }
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
381
4919
bd6299189b49 Core: added debug logging of writev() in ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4794
diff changeset
382 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
bd6299189b49 Core: added debug logging of writev() in ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4794
diff changeset
383 "writev: %d, %z", file->fd, n);
bd6299189b49 Core: added debug logging of writev() in ngx_write_chain_to_file().
Maxim Dounin <mdounin@mdounin.ru>
parents: 4794
diff changeset
384
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
385 file->sys_offset += n;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
386 file->offset += n;
4938
64ffc28850bb Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4919
diff changeset
387 offset += n;
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
388 total += n;
74
17ab1af8c3dd nginx-0.0.1-2003-04-11-20:01:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 73
diff changeset
389
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 457
diff changeset
390 } while (cl);
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
391
4220
4be8dd8dd547 Fixed unix ngx_write_chain_to_file() to return total bytes written.
Maxim Dounin <mdounin@mdounin.ru>
parents: 3861
diff changeset
392 return total;
73
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
393 }
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
394
4534060fde92 nginx-0.0.1-2003-04-10-19:08:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 35
diff changeset
395
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
396 ngx_int_t
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
397 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s)
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
398 {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
399 struct timeval tv[2];
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
400
3861
cf80c0b0109a set current atime while setting mtime
Igor Sysoev <igor@sysoev.ru>
parents: 3657
diff changeset
401 tv[0].tv_sec = ngx_time();
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
402 tv[0].tv_usec = 0;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
403 tv[1].tv_sec = s;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
404 tv[1].tv_usec = 0;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
405
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
406 if (utimes((char *) name, tv) != -1) {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
407 return NGX_OK;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
408 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
409
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
410 return NGX_ERROR;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
411 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
412
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
413
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 633
diff changeset
414 ngx_int_t
3651
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
415 ngx_create_file_mapping(ngx_file_mapping_t *fm)
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
416 {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
417 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
418 NGX_FILE_DEFAULT_ACCESS);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
419 if (fm->fd == NGX_INVALID_FILE) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
420 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
421 ngx_open_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
422 return NGX_ERROR;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
423 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
424
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
425 if (ftruncate(fm->fd, fm->size) == -1) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
426 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
427 "ftruncate() \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
428 goto failed;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
429 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
430
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
431 fm->addr = mmap(NULL, fm->size, PROT_READ|PROT_WRITE, MAP_SHARED,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
432 fm->fd, 0);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
433 if (fm->addr != MAP_FAILED) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
434 return NGX_OK;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
435 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
436
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
437 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
438 "mmap(%uz) \"%s\" failed", fm->size, fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
439
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
440 failed:
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
441
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
442 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
443 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
444 ngx_close_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
445 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
446
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
447 return NGX_ERROR;
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
448 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
449
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
450
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
451 void
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
452 ngx_close_file_mapping(ngx_file_mapping_t *fm)
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
453 {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
454 if (munmap(fm->addr, fm->size) == -1) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
455 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
456 "munmap(%uz) \"%s\" failed", fm->size, fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
457 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
458
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
459 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) {
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
460 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno,
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
461 ngx_close_file_n " \"%s\" failed", fm->name);
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
462 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
463 }
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
464
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
465
515d50917016 ngx_create_file_mapping()
Igor Sysoev <igor@sysoev.ru>
parents: 3322
diff changeset
466 ngx_int_t
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
467 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
468 {
290
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 278
diff changeset
469 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
470
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
471 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
472 return NGX_ERROR;
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
473 }
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
474
457
ded1284520cc nginx-0.1.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
475 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
476
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
477 return NGX_OK;
c1f3a3c7c5db nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 182
diff changeset
478 }
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
479
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
480
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
481 ngx_int_t
2234
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
482 ngx_read_dir(ngx_dir_t *dir)
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
483 {
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
484 dir->de = readdir(dir->dir);
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
485
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
486 if (dir->de) {
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
487 #if (NGX_HAVE_D_TYPE)
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
488 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
489 #else
3200
26784c34e8be *) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents: 3164
diff changeset
490 dir->type = 0;
2234
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
491 #endif
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
492 return NGX_OK;
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
493 }
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
494
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
495 return NGX_ERROR;
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
496 }
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
497
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
498
c7c319896bb4 *) autoconfigure struct dirent capabilities
Igor Sysoev <igor@sysoev.ru>
parents: 2210
diff changeset
499 ngx_int_t
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
500 ngx_open_glob(ngx_glob_t *gl)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
501 {
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
502 int n;
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
503
4943
1e2d5d3f9f6b Core: removed GLOB_NOSORT glob option.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4938
diff changeset
504 n = glob((char *) gl->pattern, 0, NULL, &gl->pglob);
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
505
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
506 if (n == 0) {
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
507 return NGX_OK;
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
508 }
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
509
2199
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
510 #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
511
1980
b5263e401884 ignore glob no match error
Igor Sysoev <igor@sysoev.ru>
parents: 1046
diff changeset
512 if (n == GLOB_NOMATCH && gl->test) {
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
513 return NGX_OK;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
514 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
515
2199
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
516 #endif
ffb512f0eabd fix building on FreeBSD prior to 4.8, it has no GLOB_NOMATCH
Igor Sysoev <igor@sysoev.ru>
parents: 2129
diff changeset
517
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
518 return NGX_ERROR;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
519 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
520
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
521
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
522 ngx_int_t
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
523 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
524 {
2210
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
525 size_t count;
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
526
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
527 #ifdef GLOB_NOMATCH
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
528 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
529 #else
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
530 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
531 #endif
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
532
2cae41e51622 fix build on Linux and Solaris introduced in r2200
Igor Sysoev <igor@sysoev.ru>
parents: 2199
diff changeset
533 if (gl->n < count) {
727
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
534
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
535 name->len = (size_t) ngx_strlen(gl->pglob.gl_pathv[gl->n]);
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
536 name->data = (u_char *) gl->pglob.gl_pathv[gl->n];
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
537 gl->n++;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
538
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
539 return NGX_OK;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
540 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
541
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
542 return NGX_DONE;
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
543 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
544
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
545
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
546 void
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
547 ngx_close_glob(ngx_glob_t *gl)
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
548 {
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
549 globfree(&gl->pglob);
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
550 }
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
551
532d15ddbe68 glob support in include
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
552
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
553 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
554 ngx_trylock_fd(ngx_fd_t fd)
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
555 {
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
556 struct flock fl;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
557
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
558 ngx_memzero(&fl, sizeof(struct flock));
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
559 fl.l_type = F_WRLCK;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
560 fl.l_whence = SEEK_SET;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
561
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
562 if (fcntl(fd, F_SETLK, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
563 return ngx_errno;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
564 }
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
565
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
566 return 0;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
567 }
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
568
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
569
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
570 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
571 ngx_lock_fd(ngx_fd_t fd)
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
572 {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
573 struct flock fl;
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
574
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
575 ngx_memzero(&fl, sizeof(struct flock));
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
576 fl.l_type = F_WRLCK;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
577 fl.l_whence = SEEK_SET;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
578
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
579 if (fcntl(fd, F_SETLKW, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
580 return ngx_errno;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
581 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
582
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
583 return 0;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
584 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
585
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
586
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
587 ngx_err_t
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
588 ngx_unlock_fd(ngx_fd_t fd)
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
589 {
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
590 struct flock fl;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
591
4737
9acc1a5a5b9a Made sure to initialize the entire "struct flock" allocated on stack.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
592 ngx_memzero(&fl, sizeof(struct flock));
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
593 fl.l_type = F_UNLCK;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
594 fl.l_whence = SEEK_SET;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
595
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
596 if (fcntl(fd, F_SETLK, &fl) == -1) {
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
597 return ngx_errno;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
598 }
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
599
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
600 return 0;
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
601 }
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
602
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
603
4299
11e47bf300db FreeBSD 10-current has recently gotten POSIX_FADV_* macros.
Maxim Konovalov <maxim@nginx.com>
parents: 4221
diff changeset
604 #if (NGX_HAVE_POSIX_FADVISE) && !(NGX_HAVE_F_READAHEAD)
3322
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
605
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
606 ngx_int_t
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
607 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
608 {
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
609 int err;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
610
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
611 err = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
612
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
613 if (err == 0) {
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
614 return 0;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
615 }
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
616
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
617 ngx_set_errno(err);
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
618 return NGX_FILE_ERROR;
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
619 }
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
620
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
621 #endif
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
622
e19df6e65352 fix posix_fadvise() error handling
Igor Sysoev <igor@sysoev.ru>
parents: 3294
diff changeset
623
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
624 #if (NGX_HAVE_O_DIRECT)
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
625
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
626 ngx_int_t
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
627 ngx_directio_on(ngx_fd_t fd)
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
628 {
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
629 int flags;
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
630
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
631 flags = fcntl(fd, F_GETFL);
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
632
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
633 if (flags == -1) {
3164
b1b1775698d5 uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents: 3163
diff changeset
634 return NGX_FILE_ERROR;
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
635 }
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
636
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
637 return fcntl(fd, F_SETFL, flags | O_DIRECT);
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
638 }
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
639
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
640
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
641 ngx_int_t
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
642 ngx_directio_off(ngx_fd_t fd)
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
643 {
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
644 int flags;
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
645
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
646 flags = fcntl(fd, F_GETFL);
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
647
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
648 if (flags == -1) {
3164
b1b1775698d5 uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents: 3163
diff changeset
649 return NGX_FILE_ERROR;
2248
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
650 }
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
651
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
652 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
653 }
1adec90a0e46 disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents: 2234
diff changeset
654
2129
25add486e7aa directio
Igor Sysoev <igor@sysoev.ru>
parents: 1980
diff changeset
655 #endif
2615
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
656
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
657
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
658 #if (NGX_HAVE_STATFS)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
659
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
660 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
661 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
662 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
663 struct statfs fs;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
664
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
665 if (statfs((char *) name, &fs) == -1) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
666 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
667 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
668
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
669 if ((fs.f_bsize % 512) != 0) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
670 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
671 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
672
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
673 return (size_t) fs.f_bsize;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
674 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
675
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
676 #elif (NGX_HAVE_STATVFS)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
677
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
678 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
679 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
680 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
681 struct statvfs fs;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
682
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
683 if (statvfs((char *) name, &fs) == -1) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
684 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
685 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
686
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
687 if ((fs.f_frsize % 512) != 0) {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
688 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
689 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
690
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
691 return (size_t) fs.f_frsize;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
692 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
693
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
694 #else
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
695
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
696 size_t
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
697 ngx_fs_bsize(u_char *name)
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
698 {
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
699 return 512;
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
700 }
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
701
ceef364208c8 ngx_fs_bsize()
Igor Sysoev <igor@sysoev.ru>
parents: 2550
diff changeset
702 #endif