passenger 5.0.8 → 5.0.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of passenger might be problematic. Click here for more details.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/.editorconfig +20 -0
- data/CHANGELOG +21 -0
- data/bin/passenger-install-apache2-module +3 -1
- data/build/agents.rb +7 -5
- data/build/basics.rb +3 -3
- data/build/common_library.rb +52 -30
- data/build/cxx_tests.rb +20 -13
- data/build/misc.rb +5 -5
- data/doc/Design and Architecture.html +1 -1
- data/doc/Design and Architecture.txt +1 -1
- data/doc/Packaging.html +4 -4
- data/doc/Packaging.txt.md +4 -4
- data/doc/Users guide Apache.html +22 -9
- data/doc/Users guide Apache.idmap.txt +4 -2
- data/doc/Users guide Apache.txt +2 -0
- data/doc/Users guide Nginx.html +22 -9
- data/doc/Users guide Nginx.idmap.txt +4 -2
- data/doc/Users guide Nginx.txt +2 -0
- data/doc/Users guide Standalone.html +14 -9
- data/doc/Users guide Standalone.idmap.txt +4 -2
- data/doc/users_guide_snippets/installation.txt +10 -6
- data/ext/apache2/Hooks.cpp +13 -2
- data/ext/common/ApplicationPool2/Pool/Inspection.h +8 -3
- data/ext/common/BackgroundEventLoop.cpp +249 -67
- data/ext/common/BackgroundEventLoop.h +5 -5
- data/ext/common/Constants.h +1 -1
- data/ext/common/InstanceDirectory.h +8 -6
- data/ext/common/ServerKit/Context.h +8 -2
- data/ext/common/ServerKit/FileBufferedChannel.h +262 -226
- data/ext/common/ServerKit/HeaderTable.h +28 -3
- data/ext/common/ServerKit/HttpHeaderParser.h +37 -13
- data/ext/common/ServerKit/HttpServer.h +17 -1
- data/ext/common/ServerKit/Implementation.cpp +2 -0
- data/ext/common/ServerKit/Server.h +25 -28
- data/ext/common/Utils/IOUtils.cpp +11 -0
- data/ext/common/Utils/ProcessMetricsCollector.h +4 -0
- data/ext/common/Utils/StrIntUtils.cpp +11 -7
- data/ext/common/Utils/StrIntUtils.h +1 -1
- data/ext/common/Utils/StrIntUtilsNoStrictAliasing.cpp +21 -16
- data/ext/common/agents/Base.cpp +6 -0
- data/ext/common/agents/Base.h +2 -0
- data/ext/common/agents/HelperAgent/AdminServer.h +25 -25
- data/ext/common/agents/HelperAgent/Main.cpp +37 -12
- data/ext/common/agents/HelperAgent/RequestHandler.h +18 -20
- data/ext/common/agents/HelperAgent/RequestHandler/AppResponse.h +4 -0
- data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +10 -6
- data/ext/common/agents/HelperAgent/RequestHandler/Hooks.cpp +2 -0
- data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +1 -1
- data/ext/common/agents/HelperAgent/RequestHandler/SendRequest.cpp +1 -1
- data/ext/common/agents/HelperAgent/RequestHandler/Utils.cpp +9 -2
- data/ext/common/agents/HelperAgent/ResponseCache.h +11 -11
- data/ext/common/agents/LoggingAgent/AdminServer.h +8 -8
- data/ext/common/agents/LoggingAgent/Main.cpp +6 -5
- data/ext/common/agents/Watchdog/AdminServer.h +13 -13
- data/ext/common/agents/Watchdog/Main.cpp +8 -3
- data/ext/libuv/.gitignore +72 -0
- data/ext/libuv/AUTHORS +199 -0
- data/ext/libuv/ChangeLog +2023 -0
- data/ext/libuv/LICENSE +46 -0
- data/ext/libuv/Makefile.am +336 -0
- data/ext/libuv/README.md +197 -0
- data/ext/libuv/checksparse.sh +233 -0
- data/ext/libuv/common.gypi +210 -0
- data/ext/libuv/configure.ac +67 -0
- data/ext/libuv/gyp_uv.py +96 -0
- data/ext/libuv/include/android-ifaddrs.h +54 -0
- data/ext/libuv/include/pthread-fixes.h +72 -0
- data/ext/libuv/include/tree.h +768 -0
- data/ext/libuv/include/uv-aix.h +32 -0
- data/ext/libuv/include/uv-bsd.h +34 -0
- data/ext/libuv/include/uv-darwin.h +61 -0
- data/ext/libuv/include/uv-errno.h +418 -0
- data/ext/libuv/include/uv-linux.h +34 -0
- data/ext/libuv/include/uv-sunos.h +44 -0
- data/ext/libuv/include/uv-threadpool.h +37 -0
- data/ext/libuv/include/uv-unix.h +383 -0
- data/ext/libuv/include/uv-version.h +39 -0
- data/ext/libuv/include/uv.h +1455 -0
- data/ext/libuv/libuv.pc.in +11 -0
- data/ext/libuv/m4/.gitignore +4 -0
- data/ext/libuv/m4/as_case.m4 +21 -0
- data/ext/libuv/m4/libuv-check-flags.m4 +319 -0
- data/ext/libuv/src/fs-poll.c +255 -0
- data/ext/libuv/src/heap-inl.h +245 -0
- data/ext/libuv/src/inet.c +313 -0
- data/ext/libuv/src/queue.h +92 -0
- data/ext/libuv/src/threadpool.c +303 -0
- data/ext/libuv/src/unix/aix.c +1240 -0
- data/ext/libuv/src/unix/android-ifaddrs.c +703 -0
- data/ext/libuv/src/unix/async.c +284 -0
- data/ext/libuv/src/unix/atomic-ops.h +60 -0
- data/ext/libuv/src/unix/core.c +985 -0
- data/ext/libuv/src/unix/darwin-proctitle.c +206 -0
- data/ext/libuv/src/unix/darwin.c +331 -0
- data/ext/libuv/src/unix/dl.c +83 -0
- data/ext/libuv/src/unix/freebsd.c +435 -0
- data/ext/libuv/src/unix/fs.c +1189 -0
- data/ext/libuv/src/unix/fsevents.c +899 -0
- data/ext/libuv/src/unix/getaddrinfo.c +202 -0
- data/ext/libuv/src/unix/getnameinfo.c +120 -0
- data/ext/libuv/src/unix/internal.h +314 -0
- data/ext/libuv/src/unix/kqueue.c +418 -0
- data/ext/libuv/src/unix/linux-core.c +876 -0
- data/ext/libuv/src/unix/linux-inotify.c +257 -0
- data/ext/libuv/src/unix/linux-syscalls.c +471 -0
- data/ext/libuv/src/unix/linux-syscalls.h +158 -0
- data/ext/libuv/src/unix/loop-watcher.c +63 -0
- data/ext/libuv/src/unix/loop.c +135 -0
- data/ext/libuv/src/unix/netbsd.c +368 -0
- data/ext/libuv/src/unix/openbsd.c +384 -0
- data/ext/libuv/src/unix/pipe.c +288 -0
- data/ext/libuv/src/unix/poll.c +113 -0
- data/ext/libuv/src/unix/process.c +551 -0
- data/ext/libuv/src/unix/proctitle.c +102 -0
- data/ext/libuv/src/unix/pthread-fixes.c +103 -0
- data/ext/libuv/src/unix/signal.c +465 -0
- data/ext/libuv/src/unix/spinlock.h +53 -0
- data/ext/libuv/src/unix/stream.c +1598 -0
- data/ext/libuv/src/unix/sunos.c +763 -0
- data/ext/libuv/src/unix/tcp.c +327 -0
- data/ext/libuv/src/unix/thread.c +519 -0
- data/ext/libuv/src/unix/timer.c +172 -0
- data/ext/libuv/src/unix/tty.c +265 -0
- data/ext/libuv/src/unix/udp.c +833 -0
- data/ext/libuv/src/uv-common.c +544 -0
- data/ext/libuv/src/uv-common.h +214 -0
- data/ext/libuv/src/version.c +49 -0
- data/ext/libuv/uv.gyp +487 -0
- data/ext/nginx/ContentHandler.c +21 -10
- data/ext/nginx/ngx_http_passenger_module.c +7 -0
- data/ext/oxt/implementation.cpp +9 -2
- data/ext/oxt/initialize.hpp +5 -1
- data/lib/phusion_passenger.rb +3 -3
- data/lib/phusion_passenger/admin_tools/instance.rb +10 -6
- data/lib/phusion_passenger/admin_tools/instance_registry.rb +6 -2
- data/lib/phusion_passenger/packaging.rb +3 -4
- data/lib/phusion_passenger/platform_info.rb +13 -1
- data/lib/phusion_passenger/platform_info/apache.rb +15 -4
- data/lib/phusion_passenger/platform_info/apache_detector.rb +5 -1
- data/lib/phusion_passenger/rack/thread_handler_extension.rb +184 -99
- data/lib/phusion_passenger/request_handler/thread_handler.rb +13 -6
- data/lib/phusion_passenger/standalone/start_command.rb +2 -2
- data/resources/templates/apache2/apache_install_broken.txt.erb +2 -1
- metadata +99 -22
- metadata.gz.asc +7 -7
- data/ext/libeio/Changes +0 -76
- data/ext/libeio/LICENSE +0 -36
- data/ext/libeio/Makefile.am +0 -15
- data/ext/libeio/Makefile.in +0 -694
- data/ext/libeio/aclocal.m4 +0 -9418
- data/ext/libeio/autogen.sh +0 -3
- data/ext/libeio/config.guess +0 -1540
- data/ext/libeio/config.h.in +0 -136
- data/ext/libeio/config.sub +0 -1779
- data/ext/libeio/configure +0 -14822
- data/ext/libeio/configure.ac +0 -22
- data/ext/libeio/demo.c +0 -194
- data/ext/libeio/ecb.h +0 -714
- data/ext/libeio/eio.c +0 -2818
- data/ext/libeio/eio.h +0 -414
- data/ext/libeio/install-sh +0 -520
- data/ext/libeio/libeio.m4 +0 -195
- data/ext/libeio/ltmain.sh +0 -9636
- data/ext/libeio/missing +0 -376
- data/ext/libeio/xthread.h +0 -166
@@ -0,0 +1,1189 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
/* Caveat emptor: this file deviates from the libuv convention of returning
|
23
|
+
* negated errno codes. Most uv_fs_*() functions map directly to the system
|
24
|
+
* call of the same name. For more complex wrappers, it's easier to just
|
25
|
+
* return -1 with errno set. The dispatcher in uv__fs_work() takes care of
|
26
|
+
* getting the errno to the right place (req->result or as the return value.)
|
27
|
+
*/
|
28
|
+
|
29
|
+
#include "uv.h"
|
30
|
+
#include "internal.h"
|
31
|
+
|
32
|
+
#include <errno.h>
|
33
|
+
#include <stdio.h>
|
34
|
+
#include <stdlib.h>
|
35
|
+
#include <string.h>
|
36
|
+
|
37
|
+
#include <sys/types.h>
|
38
|
+
#include <sys/socket.h>
|
39
|
+
#include <sys/stat.h>
|
40
|
+
#include <sys/time.h>
|
41
|
+
#include <sys/uio.h>
|
42
|
+
#include <pthread.h>
|
43
|
+
#include <unistd.h>
|
44
|
+
#include <fcntl.h>
|
45
|
+
#include <utime.h>
|
46
|
+
#include <poll.h>
|
47
|
+
|
48
|
+
#if defined(__DragonFly__) || \
|
49
|
+
defined(__FreeBSD__) || \
|
50
|
+
defined(__OpenBSD__) || \
|
51
|
+
defined(__NetBSD__)
|
52
|
+
# define HAVE_PREADV 1
|
53
|
+
#else
|
54
|
+
# define HAVE_PREADV 0
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#if defined(__linux__) || defined(__sun)
|
58
|
+
# include <sys/sendfile.h>
|
59
|
+
#endif
|
60
|
+
|
61
|
+
#define INIT(type) \
|
62
|
+
do { \
|
63
|
+
uv__req_init((loop), (req), UV_FS); \
|
64
|
+
(req)->fs_type = UV_FS_ ## type; \
|
65
|
+
(req)->result = 0; \
|
66
|
+
(req)->ptr = NULL; \
|
67
|
+
(req)->loop = loop; \
|
68
|
+
(req)->path = NULL; \
|
69
|
+
(req)->new_path = NULL; \
|
70
|
+
(req)->cb = (cb); \
|
71
|
+
} \
|
72
|
+
while (0)
|
73
|
+
|
74
|
+
#define PATH \
|
75
|
+
do { \
|
76
|
+
(req)->path = strdup(path); \
|
77
|
+
if ((req)->path == NULL) \
|
78
|
+
return -ENOMEM; \
|
79
|
+
} \
|
80
|
+
while (0)
|
81
|
+
|
82
|
+
#define PATH2 \
|
83
|
+
do { \
|
84
|
+
size_t path_len; \
|
85
|
+
size_t new_path_len; \
|
86
|
+
path_len = strlen((path)) + 1; \
|
87
|
+
new_path_len = strlen((new_path)) + 1; \
|
88
|
+
(req)->path = malloc(path_len + new_path_len); \
|
89
|
+
if ((req)->path == NULL) \
|
90
|
+
return -ENOMEM; \
|
91
|
+
(req)->new_path = (req)->path + path_len; \
|
92
|
+
memcpy((void*) (req)->path, (path), path_len); \
|
93
|
+
memcpy((void*) (req)->new_path, (new_path), new_path_len); \
|
94
|
+
} \
|
95
|
+
while (0)
|
96
|
+
|
97
|
+
#define POST \
|
98
|
+
do { \
|
99
|
+
if ((cb) != NULL) { \
|
100
|
+
uv__work_submit((loop), &(req)->work_req, uv__fs_work, uv__fs_done); \
|
101
|
+
return 0; \
|
102
|
+
} \
|
103
|
+
else { \
|
104
|
+
uv__fs_work(&(req)->work_req); \
|
105
|
+
uv__fs_done(&(req)->work_req, 0); \
|
106
|
+
return (req)->result; \
|
107
|
+
} \
|
108
|
+
} \
|
109
|
+
while (0)
|
110
|
+
|
111
|
+
|
112
|
+
static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
|
113
|
+
#if defined(__linux__) || defined(__sun) || defined(__NetBSD__)
|
114
|
+
return fdatasync(req->file);
|
115
|
+
#elif defined(__APPLE__) && defined(F_FULLFSYNC)
|
116
|
+
return fcntl(req->file, F_FULLFSYNC);
|
117
|
+
#else
|
118
|
+
return fsync(req->file);
|
119
|
+
#endif
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
static ssize_t uv__fs_futime(uv_fs_t* req) {
|
124
|
+
#if defined(__linux__)
|
125
|
+
/* utimesat() has nanosecond resolution but we stick to microseconds
|
126
|
+
* for the sake of consistency with other platforms.
|
127
|
+
*/
|
128
|
+
static int no_utimesat;
|
129
|
+
struct timespec ts[2];
|
130
|
+
struct timeval tv[2];
|
131
|
+
char path[sizeof("/proc/self/fd/") + 3 * sizeof(int)];
|
132
|
+
int r;
|
133
|
+
|
134
|
+
if (no_utimesat)
|
135
|
+
goto skip;
|
136
|
+
|
137
|
+
ts[0].tv_sec = req->atime;
|
138
|
+
ts[0].tv_nsec = (unsigned long)(req->atime * 1000000) % 1000000 * 1000;
|
139
|
+
ts[1].tv_sec = req->mtime;
|
140
|
+
ts[1].tv_nsec = (unsigned long)(req->mtime * 1000000) % 1000000 * 1000;
|
141
|
+
|
142
|
+
r = uv__utimesat(req->file, NULL, ts, 0);
|
143
|
+
if (r == 0)
|
144
|
+
return r;
|
145
|
+
|
146
|
+
if (errno != ENOSYS)
|
147
|
+
return r;
|
148
|
+
|
149
|
+
no_utimesat = 1;
|
150
|
+
|
151
|
+
skip:
|
152
|
+
|
153
|
+
tv[0].tv_sec = req->atime;
|
154
|
+
tv[0].tv_usec = (unsigned long)(req->atime * 1000000) % 1000000;
|
155
|
+
tv[1].tv_sec = req->mtime;
|
156
|
+
tv[1].tv_usec = (unsigned long)(req->mtime * 1000000) % 1000000;
|
157
|
+
snprintf(path, sizeof(path), "/proc/self/fd/%d", (int) req->file);
|
158
|
+
|
159
|
+
r = utimes(path, tv);
|
160
|
+
if (r == 0)
|
161
|
+
return r;
|
162
|
+
|
163
|
+
switch (errno) {
|
164
|
+
case ENOENT:
|
165
|
+
if (fcntl(req->file, F_GETFL) == -1 && errno == EBADF)
|
166
|
+
break;
|
167
|
+
/* Fall through. */
|
168
|
+
|
169
|
+
case EACCES:
|
170
|
+
case ENOTDIR:
|
171
|
+
errno = ENOSYS;
|
172
|
+
break;
|
173
|
+
}
|
174
|
+
|
175
|
+
return r;
|
176
|
+
|
177
|
+
#elif defined(__APPLE__) \
|
178
|
+
|| defined(__DragonFly__) \
|
179
|
+
|| defined(__FreeBSD__) \
|
180
|
+
|| defined(__NetBSD__) \
|
181
|
+
|| defined(__OpenBSD__) \
|
182
|
+
|| defined(__sun)
|
183
|
+
struct timeval tv[2];
|
184
|
+
tv[0].tv_sec = req->atime;
|
185
|
+
tv[0].tv_usec = (unsigned long)(req->atime * 1000000) % 1000000;
|
186
|
+
tv[1].tv_sec = req->mtime;
|
187
|
+
tv[1].tv_usec = (unsigned long)(req->mtime * 1000000) % 1000000;
|
188
|
+
# if defined(__sun)
|
189
|
+
return futimesat(req->file, NULL, tv);
|
190
|
+
# else
|
191
|
+
return futimes(req->file, tv);
|
192
|
+
# endif
|
193
|
+
#else
|
194
|
+
errno = ENOSYS;
|
195
|
+
return -1;
|
196
|
+
#endif
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
static ssize_t uv__fs_mkdtemp(uv_fs_t* req) {
|
201
|
+
return mkdtemp((char*) req->path) ? 0 : -1;
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
static ssize_t uv__fs_open(uv_fs_t* req) {
|
206
|
+
static int no_cloexec_support;
|
207
|
+
int r;
|
208
|
+
|
209
|
+
/* Try O_CLOEXEC before entering locks */
|
210
|
+
if (no_cloexec_support == 0) {
|
211
|
+
#ifdef O_CLOEXEC
|
212
|
+
r = open(req->path, req->flags | O_CLOEXEC, req->mode);
|
213
|
+
if (r >= 0)
|
214
|
+
return r;
|
215
|
+
if (errno != EINVAL)
|
216
|
+
return r;
|
217
|
+
no_cloexec_support = 1;
|
218
|
+
#endif /* O_CLOEXEC */
|
219
|
+
}
|
220
|
+
|
221
|
+
if (req->cb != NULL)
|
222
|
+
uv_rwlock_rdlock(&req->loop->cloexec_lock);
|
223
|
+
|
224
|
+
r = open(req->path, req->flags, req->mode);
|
225
|
+
|
226
|
+
/* In case of failure `uv__cloexec` will leave error in `errno`,
|
227
|
+
* so it is enough to just set `r` to `-1`.
|
228
|
+
*/
|
229
|
+
if (r >= 0 && uv__cloexec(r, 1) != 0) {
|
230
|
+
r = uv__close(r);
|
231
|
+
if (r != 0 && r != -EINPROGRESS)
|
232
|
+
abort();
|
233
|
+
r = -1;
|
234
|
+
}
|
235
|
+
|
236
|
+
if (req->cb != NULL)
|
237
|
+
uv_rwlock_rdunlock(&req->loop->cloexec_lock);
|
238
|
+
|
239
|
+
return r;
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
static ssize_t uv__fs_read(uv_fs_t* req) {
|
244
|
+
#if defined(__linux__)
|
245
|
+
static int no_preadv;
|
246
|
+
#endif
|
247
|
+
ssize_t result;
|
248
|
+
|
249
|
+
#if defined(_AIX)
|
250
|
+
struct stat buf;
|
251
|
+
if(fstat(req->file, &buf))
|
252
|
+
return -1;
|
253
|
+
if(S_ISDIR(buf.st_mode)) {
|
254
|
+
errno = EISDIR;
|
255
|
+
return -1;
|
256
|
+
}
|
257
|
+
#endif /* defined(_AIX) */
|
258
|
+
if (req->off < 0) {
|
259
|
+
if (req->nbufs == 1)
|
260
|
+
result = read(req->file, req->bufs[0].base, req->bufs[0].len);
|
261
|
+
else
|
262
|
+
result = readv(req->file, (struct iovec*) req->bufs, req->nbufs);
|
263
|
+
} else {
|
264
|
+
if (req->nbufs == 1) {
|
265
|
+
result = pread(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
|
266
|
+
goto done;
|
267
|
+
}
|
268
|
+
|
269
|
+
#if HAVE_PREADV
|
270
|
+
result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
|
271
|
+
#else
|
272
|
+
# if defined(__linux__)
|
273
|
+
if (no_preadv) retry:
|
274
|
+
# endif
|
275
|
+
{
|
276
|
+
off_t nread;
|
277
|
+
size_t index;
|
278
|
+
|
279
|
+
nread = 0;
|
280
|
+
index = 0;
|
281
|
+
result = 1;
|
282
|
+
do {
|
283
|
+
if (req->bufs[index].len > 0) {
|
284
|
+
result = pread(req->file,
|
285
|
+
req->bufs[index].base,
|
286
|
+
req->bufs[index].len,
|
287
|
+
req->off + nread);
|
288
|
+
if (result > 0)
|
289
|
+
nread += result;
|
290
|
+
}
|
291
|
+
index++;
|
292
|
+
} while (index < req->nbufs && result > 0);
|
293
|
+
if (nread > 0)
|
294
|
+
result = nread;
|
295
|
+
}
|
296
|
+
# if defined(__linux__)
|
297
|
+
else {
|
298
|
+
result = uv__preadv(req->file,
|
299
|
+
(struct iovec*)req->bufs,
|
300
|
+
req->nbufs,
|
301
|
+
req->off);
|
302
|
+
if (result == -1 && errno == ENOSYS) {
|
303
|
+
no_preadv = 1;
|
304
|
+
goto retry;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
# endif
|
308
|
+
#endif
|
309
|
+
}
|
310
|
+
|
311
|
+
done:
|
312
|
+
if (req->bufs != req->bufsml)
|
313
|
+
free(req->bufs);
|
314
|
+
return result;
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
#if defined(__OpenBSD__) || (defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_8))
|
319
|
+
static int uv__fs_scandir_filter(uv__dirent_t* dent) {
|
320
|
+
#else
|
321
|
+
static int uv__fs_scandir_filter(const uv__dirent_t* dent) {
|
322
|
+
#endif
|
323
|
+
return strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0;
|
324
|
+
}
|
325
|
+
|
326
|
+
|
327
|
+
static ssize_t uv__fs_scandir(uv_fs_t* req) {
|
328
|
+
uv__dirent_t **dents;
|
329
|
+
int saved_errno;
|
330
|
+
int n;
|
331
|
+
|
332
|
+
dents = NULL;
|
333
|
+
n = scandir(req->path, &dents, uv__fs_scandir_filter, alphasort);
|
334
|
+
|
335
|
+
/* NOTE: We will use nbufs as an index field */
|
336
|
+
req->nbufs = 0;
|
337
|
+
|
338
|
+
if (n == 0)
|
339
|
+
goto out; /* osx still needs to deallocate some memory */
|
340
|
+
else if (n == -1)
|
341
|
+
return n;
|
342
|
+
|
343
|
+
req->ptr = dents;
|
344
|
+
|
345
|
+
return n;
|
346
|
+
|
347
|
+
out:
|
348
|
+
saved_errno = errno;
|
349
|
+
if (dents != NULL) {
|
350
|
+
int i;
|
351
|
+
|
352
|
+
for (i = 0; i < n; i++)
|
353
|
+
free(dents[i]);
|
354
|
+
free(dents);
|
355
|
+
}
|
356
|
+
errno = saved_errno;
|
357
|
+
|
358
|
+
req->ptr = NULL;
|
359
|
+
|
360
|
+
return n;
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
static ssize_t uv__fs_readlink(uv_fs_t* req) {
|
365
|
+
ssize_t len;
|
366
|
+
char* buf;
|
367
|
+
|
368
|
+
len = pathconf(req->path, _PC_PATH_MAX);
|
369
|
+
|
370
|
+
if (len == -1) {
|
371
|
+
#if defined(PATH_MAX)
|
372
|
+
len = PATH_MAX;
|
373
|
+
#else
|
374
|
+
len = 4096;
|
375
|
+
#endif
|
376
|
+
}
|
377
|
+
|
378
|
+
buf = malloc(len + 1);
|
379
|
+
|
380
|
+
if (buf == NULL) {
|
381
|
+
errno = ENOMEM;
|
382
|
+
return -1;
|
383
|
+
}
|
384
|
+
|
385
|
+
len = readlink(req->path, buf, len);
|
386
|
+
|
387
|
+
if (len == -1) {
|
388
|
+
free(buf);
|
389
|
+
return -1;
|
390
|
+
}
|
391
|
+
|
392
|
+
buf[len] = '\0';
|
393
|
+
req->ptr = buf;
|
394
|
+
|
395
|
+
return 0;
|
396
|
+
}
|
397
|
+
|
398
|
+
|
399
|
+
static ssize_t uv__fs_sendfile_emul(uv_fs_t* req) {
|
400
|
+
struct pollfd pfd;
|
401
|
+
int use_pread;
|
402
|
+
off_t offset;
|
403
|
+
ssize_t nsent;
|
404
|
+
ssize_t nread;
|
405
|
+
ssize_t nwritten;
|
406
|
+
size_t buflen;
|
407
|
+
size_t len;
|
408
|
+
ssize_t n;
|
409
|
+
int in_fd;
|
410
|
+
int out_fd;
|
411
|
+
char buf[8192];
|
412
|
+
|
413
|
+
len = req->bufsml[0].len;
|
414
|
+
in_fd = req->flags;
|
415
|
+
out_fd = req->file;
|
416
|
+
offset = req->off;
|
417
|
+
use_pread = 1;
|
418
|
+
|
419
|
+
/* Here are the rules regarding errors:
|
420
|
+
*
|
421
|
+
* 1. Read errors are reported only if nsent==0, otherwise we return nsent.
|
422
|
+
* The user needs to know that some data has already been sent, to stop
|
423
|
+
* them from sending it twice.
|
424
|
+
*
|
425
|
+
* 2. Write errors are always reported. Write errors are bad because they
|
426
|
+
* mean data loss: we've read data but now we can't write it out.
|
427
|
+
*
|
428
|
+
* We try to use pread() and fall back to regular read() if the source fd
|
429
|
+
* doesn't support positional reads, for example when it's a pipe fd.
|
430
|
+
*
|
431
|
+
* If we get EAGAIN when writing to the target fd, we poll() on it until
|
432
|
+
* it becomes writable again.
|
433
|
+
*
|
434
|
+
* FIXME: If we get a write error when use_pread==1, it should be safe to
|
435
|
+
* return the number of sent bytes instead of an error because pread()
|
436
|
+
* is, in theory, idempotent. However, special files in /dev or /proc
|
437
|
+
* may support pread() but not necessarily return the same data on
|
438
|
+
* successive reads.
|
439
|
+
*
|
440
|
+
* FIXME: There is no way now to signal that we managed to send *some* data
|
441
|
+
* before a write error.
|
442
|
+
*/
|
443
|
+
for (nsent = 0; (size_t) nsent < len; ) {
|
444
|
+
buflen = len - nsent;
|
445
|
+
|
446
|
+
if (buflen > sizeof(buf))
|
447
|
+
buflen = sizeof(buf);
|
448
|
+
|
449
|
+
do
|
450
|
+
if (use_pread)
|
451
|
+
nread = pread(in_fd, buf, buflen, offset);
|
452
|
+
else
|
453
|
+
nread = read(in_fd, buf, buflen);
|
454
|
+
while (nread == -1 && errno == EINTR);
|
455
|
+
|
456
|
+
if (nread == 0)
|
457
|
+
goto out;
|
458
|
+
|
459
|
+
if (nread == -1) {
|
460
|
+
if (use_pread && nsent == 0 && (errno == EIO || errno == ESPIPE)) {
|
461
|
+
use_pread = 0;
|
462
|
+
continue;
|
463
|
+
}
|
464
|
+
|
465
|
+
if (nsent == 0)
|
466
|
+
nsent = -1;
|
467
|
+
|
468
|
+
goto out;
|
469
|
+
}
|
470
|
+
|
471
|
+
for (nwritten = 0; nwritten < nread; ) {
|
472
|
+
do
|
473
|
+
n = write(out_fd, buf + nwritten, nread - nwritten);
|
474
|
+
while (n == -1 && errno == EINTR);
|
475
|
+
|
476
|
+
if (n != -1) {
|
477
|
+
nwritten += n;
|
478
|
+
continue;
|
479
|
+
}
|
480
|
+
|
481
|
+
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
482
|
+
nsent = -1;
|
483
|
+
goto out;
|
484
|
+
}
|
485
|
+
|
486
|
+
pfd.fd = out_fd;
|
487
|
+
pfd.events = POLLOUT;
|
488
|
+
pfd.revents = 0;
|
489
|
+
|
490
|
+
do
|
491
|
+
n = poll(&pfd, 1, -1);
|
492
|
+
while (n == -1 && errno == EINTR);
|
493
|
+
|
494
|
+
if (n == -1 || (pfd.revents & ~POLLOUT) != 0) {
|
495
|
+
errno = EIO;
|
496
|
+
nsent = -1;
|
497
|
+
goto out;
|
498
|
+
}
|
499
|
+
}
|
500
|
+
|
501
|
+
offset += nread;
|
502
|
+
nsent += nread;
|
503
|
+
}
|
504
|
+
|
505
|
+
out:
|
506
|
+
if (nsent != -1)
|
507
|
+
req->off = offset;
|
508
|
+
|
509
|
+
return nsent;
|
510
|
+
}
|
511
|
+
|
512
|
+
|
513
|
+
static ssize_t uv__fs_sendfile(uv_fs_t* req) {
|
514
|
+
int in_fd;
|
515
|
+
int out_fd;
|
516
|
+
|
517
|
+
in_fd = req->flags;
|
518
|
+
out_fd = req->file;
|
519
|
+
|
520
|
+
#if defined(__linux__) || defined(__sun)
|
521
|
+
{
|
522
|
+
off_t off;
|
523
|
+
ssize_t r;
|
524
|
+
|
525
|
+
off = req->off;
|
526
|
+
r = sendfile(out_fd, in_fd, &off, req->bufsml[0].len);
|
527
|
+
|
528
|
+
/* sendfile() on SunOS returns EINVAL if the target fd is not a socket but
|
529
|
+
* it still writes out data. Fortunately, we can detect it by checking if
|
530
|
+
* the offset has been updated.
|
531
|
+
*/
|
532
|
+
if (r != -1 || off > req->off) {
|
533
|
+
r = off - req->off;
|
534
|
+
req->off = off;
|
535
|
+
return r;
|
536
|
+
}
|
537
|
+
|
538
|
+
if (errno == EINVAL ||
|
539
|
+
errno == EIO ||
|
540
|
+
errno == ENOTSOCK ||
|
541
|
+
errno == EXDEV) {
|
542
|
+
errno = 0;
|
543
|
+
return uv__fs_sendfile_emul(req);
|
544
|
+
}
|
545
|
+
|
546
|
+
return -1;
|
547
|
+
}
|
548
|
+
#elif defined(__FreeBSD__) || defined(__APPLE__)
|
549
|
+
{
|
550
|
+
off_t len;
|
551
|
+
ssize_t r;
|
552
|
+
|
553
|
+
/* sendfile() on FreeBSD and Darwin returns EAGAIN if the target fd is in
|
554
|
+
* non-blocking mode and not all data could be written. If a non-zero
|
555
|
+
* number of bytes have been sent, we don't consider it an error.
|
556
|
+
*/
|
557
|
+
|
558
|
+
#if defined(__FreeBSD__)
|
559
|
+
len = 0;
|
560
|
+
r = sendfile(in_fd, out_fd, req->off, req->bufsml[0].len, NULL, &len, 0);
|
561
|
+
#else
|
562
|
+
/* The darwin sendfile takes len as an input for the length to send,
|
563
|
+
* so make sure to initialize it with the caller's value. */
|
564
|
+
len = req->bufsml[0].len;
|
565
|
+
r = sendfile(in_fd, out_fd, req->off, &len, NULL, 0);
|
566
|
+
#endif
|
567
|
+
|
568
|
+
if (r != -1 || len != 0) {
|
569
|
+
req->off += len;
|
570
|
+
return (ssize_t) len;
|
571
|
+
}
|
572
|
+
|
573
|
+
if (errno == EINVAL ||
|
574
|
+
errno == EIO ||
|
575
|
+
errno == ENOTSOCK ||
|
576
|
+
errno == EXDEV) {
|
577
|
+
errno = 0;
|
578
|
+
return uv__fs_sendfile_emul(req);
|
579
|
+
}
|
580
|
+
|
581
|
+
return -1;
|
582
|
+
}
|
583
|
+
#else
|
584
|
+
/* Squelch compiler warnings. */
|
585
|
+
(void) &in_fd;
|
586
|
+
(void) &out_fd;
|
587
|
+
|
588
|
+
return uv__fs_sendfile_emul(req);
|
589
|
+
#endif
|
590
|
+
}
|
591
|
+
|
592
|
+
|
593
|
+
static ssize_t uv__fs_utime(uv_fs_t* req) {
|
594
|
+
struct utimbuf buf;
|
595
|
+
buf.actime = req->atime;
|
596
|
+
buf.modtime = req->mtime;
|
597
|
+
return utime(req->path, &buf); /* TODO use utimes() where available */
|
598
|
+
}
|
599
|
+
|
600
|
+
|
601
|
+
static ssize_t uv__fs_write(uv_fs_t* req) {
|
602
|
+
#if defined(__linux__)
|
603
|
+
static int no_pwritev;
|
604
|
+
#endif
|
605
|
+
ssize_t r;
|
606
|
+
|
607
|
+
/* Serialize writes on OS X, concurrent write() and pwrite() calls result in
|
608
|
+
* data loss. We can't use a per-file descriptor lock, the descriptor may be
|
609
|
+
* a dup().
|
610
|
+
*/
|
611
|
+
#if defined(__APPLE__)
|
612
|
+
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
613
|
+
pthread_mutex_lock(&lock);
|
614
|
+
#endif
|
615
|
+
|
616
|
+
if (req->off < 0) {
|
617
|
+
if (req->nbufs == 1)
|
618
|
+
r = write(req->file, req->bufs[0].base, req->bufs[0].len);
|
619
|
+
else
|
620
|
+
r = writev(req->file, (struct iovec*) req->bufs, req->nbufs);
|
621
|
+
} else {
|
622
|
+
if (req->nbufs == 1) {
|
623
|
+
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
|
624
|
+
goto done;
|
625
|
+
}
|
626
|
+
#if HAVE_PREADV
|
627
|
+
r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
|
628
|
+
#else
|
629
|
+
# if defined(__linux__)
|
630
|
+
if (no_pwritev) retry:
|
631
|
+
# endif
|
632
|
+
{
|
633
|
+
off_t written;
|
634
|
+
size_t index;
|
635
|
+
|
636
|
+
written = 0;
|
637
|
+
index = 0;
|
638
|
+
r = 0;
|
639
|
+
do {
|
640
|
+
if (req->bufs[index].len > 0) {
|
641
|
+
r = pwrite(req->file,
|
642
|
+
req->bufs[index].base,
|
643
|
+
req->bufs[index].len,
|
644
|
+
req->off + written);
|
645
|
+
if (r > 0)
|
646
|
+
written += r;
|
647
|
+
}
|
648
|
+
index++;
|
649
|
+
} while (index < req->nbufs && r >= 0);
|
650
|
+
if (written > 0)
|
651
|
+
r = written;
|
652
|
+
}
|
653
|
+
# if defined(__linux__)
|
654
|
+
else {
|
655
|
+
r = uv__pwritev(req->file,
|
656
|
+
(struct iovec*) req->bufs,
|
657
|
+
req->nbufs,
|
658
|
+
req->off);
|
659
|
+
if (r == -1 && errno == ENOSYS) {
|
660
|
+
no_pwritev = 1;
|
661
|
+
goto retry;
|
662
|
+
}
|
663
|
+
}
|
664
|
+
# endif
|
665
|
+
#endif
|
666
|
+
}
|
667
|
+
|
668
|
+
done:
|
669
|
+
#if defined(__APPLE__)
|
670
|
+
pthread_mutex_unlock(&lock);
|
671
|
+
#endif
|
672
|
+
|
673
|
+
if (req->bufs != req->bufsml)
|
674
|
+
free(req->bufs);
|
675
|
+
|
676
|
+
return r;
|
677
|
+
}
|
678
|
+
|
679
|
+
static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
|
680
|
+
dst->st_dev = src->st_dev;
|
681
|
+
dst->st_mode = src->st_mode;
|
682
|
+
dst->st_nlink = src->st_nlink;
|
683
|
+
dst->st_uid = src->st_uid;
|
684
|
+
dst->st_gid = src->st_gid;
|
685
|
+
dst->st_rdev = src->st_rdev;
|
686
|
+
dst->st_ino = src->st_ino;
|
687
|
+
dst->st_size = src->st_size;
|
688
|
+
dst->st_blksize = src->st_blksize;
|
689
|
+
dst->st_blocks = src->st_blocks;
|
690
|
+
|
691
|
+
#if defined(__APPLE__)
|
692
|
+
dst->st_atim.tv_sec = src->st_atimespec.tv_sec;
|
693
|
+
dst->st_atim.tv_nsec = src->st_atimespec.tv_nsec;
|
694
|
+
dst->st_mtim.tv_sec = src->st_mtimespec.tv_sec;
|
695
|
+
dst->st_mtim.tv_nsec = src->st_mtimespec.tv_nsec;
|
696
|
+
dst->st_ctim.tv_sec = src->st_ctimespec.tv_sec;
|
697
|
+
dst->st_ctim.tv_nsec = src->st_ctimespec.tv_nsec;
|
698
|
+
dst->st_birthtim.tv_sec = src->st_birthtimespec.tv_sec;
|
699
|
+
dst->st_birthtim.tv_nsec = src->st_birthtimespec.tv_nsec;
|
700
|
+
dst->st_flags = src->st_flags;
|
701
|
+
dst->st_gen = src->st_gen;
|
702
|
+
#elif defined(__ANDROID__)
|
703
|
+
dst->st_atim.tv_sec = src->st_atime;
|
704
|
+
dst->st_atim.tv_nsec = src->st_atime_nsec;
|
705
|
+
dst->st_mtim.tv_sec = src->st_mtime;
|
706
|
+
dst->st_mtim.tv_nsec = src->st_mtime_nsec;
|
707
|
+
dst->st_ctim.tv_sec = src->st_ctime;
|
708
|
+
dst->st_ctim.tv_nsec = src->st_ctime_nsec;
|
709
|
+
dst->st_birthtim.tv_sec = src->st_ctime;
|
710
|
+
dst->st_birthtim.tv_nsec = src->st_ctime_nsec;
|
711
|
+
dst->st_flags = 0;
|
712
|
+
dst->st_gen = 0;
|
713
|
+
#elif !defined(_AIX) && ( \
|
714
|
+
defined(_BSD_SOURCE) || \
|
715
|
+
defined(_SVID_SOURCE) || \
|
716
|
+
defined(_XOPEN_SOURCE) || \
|
717
|
+
defined(_DEFAULT_SOURCE))
|
718
|
+
dst->st_atim.tv_sec = src->st_atim.tv_sec;
|
719
|
+
dst->st_atim.tv_nsec = src->st_atim.tv_nsec;
|
720
|
+
dst->st_mtim.tv_sec = src->st_mtim.tv_sec;
|
721
|
+
dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec;
|
722
|
+
dst->st_ctim.tv_sec = src->st_ctim.tv_sec;
|
723
|
+
dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec;
|
724
|
+
# if defined(__DragonFly__) || \
|
725
|
+
defined(__FreeBSD__) || \
|
726
|
+
defined(__OpenBSD__) || \
|
727
|
+
defined(__NetBSD__)
|
728
|
+
dst->st_birthtim.tv_sec = src->st_birthtim.tv_sec;
|
729
|
+
dst->st_birthtim.tv_nsec = src->st_birthtim.tv_nsec;
|
730
|
+
dst->st_flags = src->st_flags;
|
731
|
+
dst->st_gen = src->st_gen;
|
732
|
+
# else
|
733
|
+
dst->st_birthtim.tv_sec = src->st_ctim.tv_sec;
|
734
|
+
dst->st_birthtim.tv_nsec = src->st_ctim.tv_nsec;
|
735
|
+
dst->st_flags = 0;
|
736
|
+
dst->st_gen = 0;
|
737
|
+
# endif
|
738
|
+
#else
|
739
|
+
dst->st_atim.tv_sec = src->st_atime;
|
740
|
+
dst->st_atim.tv_nsec = 0;
|
741
|
+
dst->st_mtim.tv_sec = src->st_mtime;
|
742
|
+
dst->st_mtim.tv_nsec = 0;
|
743
|
+
dst->st_ctim.tv_sec = src->st_ctime;
|
744
|
+
dst->st_ctim.tv_nsec = 0;
|
745
|
+
dst->st_birthtim.tv_sec = src->st_ctime;
|
746
|
+
dst->st_birthtim.tv_nsec = 0;
|
747
|
+
dst->st_flags = 0;
|
748
|
+
dst->st_gen = 0;
|
749
|
+
#endif
|
750
|
+
}
|
751
|
+
|
752
|
+
|
753
|
+
static int uv__fs_stat(const char *path, uv_stat_t *buf) {
|
754
|
+
struct stat pbuf;
|
755
|
+
int ret;
|
756
|
+
ret = stat(path, &pbuf);
|
757
|
+
uv__to_stat(&pbuf, buf);
|
758
|
+
return ret;
|
759
|
+
}
|
760
|
+
|
761
|
+
|
762
|
+
static int uv__fs_lstat(const char *path, uv_stat_t *buf) {
|
763
|
+
struct stat pbuf;
|
764
|
+
int ret;
|
765
|
+
ret = lstat(path, &pbuf);
|
766
|
+
uv__to_stat(&pbuf, buf);
|
767
|
+
return ret;
|
768
|
+
}
|
769
|
+
|
770
|
+
|
771
|
+
static int uv__fs_fstat(int fd, uv_stat_t *buf) {
|
772
|
+
struct stat pbuf;
|
773
|
+
int ret;
|
774
|
+
ret = fstat(fd, &pbuf);
|
775
|
+
uv__to_stat(&pbuf, buf);
|
776
|
+
return ret;
|
777
|
+
}
|
778
|
+
|
779
|
+
|
780
|
+
static void uv__fs_work(struct uv__work* w) {
|
781
|
+
int retry_on_eintr;
|
782
|
+
uv_fs_t* req;
|
783
|
+
ssize_t r;
|
784
|
+
|
785
|
+
req = container_of(w, uv_fs_t, work_req);
|
786
|
+
retry_on_eintr = !(req->fs_type == UV_FS_CLOSE);
|
787
|
+
|
788
|
+
do {
|
789
|
+
errno = 0;
|
790
|
+
|
791
|
+
#define X(type, action) \
|
792
|
+
case UV_FS_ ## type: \
|
793
|
+
r = action; \
|
794
|
+
break;
|
795
|
+
|
796
|
+
switch (req->fs_type) {
|
797
|
+
X(ACCESS, access(req->path, req->flags));
|
798
|
+
X(CHMOD, chmod(req->path, req->mode));
|
799
|
+
X(CHOWN, chown(req->path, req->uid, req->gid));
|
800
|
+
X(CLOSE, close(req->file));
|
801
|
+
X(FCHMOD, fchmod(req->file, req->mode));
|
802
|
+
X(FCHOWN, fchown(req->file, req->uid, req->gid));
|
803
|
+
X(FDATASYNC, uv__fs_fdatasync(req));
|
804
|
+
X(FSTAT, uv__fs_fstat(req->file, &req->statbuf));
|
805
|
+
X(FSYNC, fsync(req->file));
|
806
|
+
X(FTRUNCATE, ftruncate(req->file, req->off));
|
807
|
+
X(FUTIME, uv__fs_futime(req));
|
808
|
+
X(LSTAT, uv__fs_lstat(req->path, &req->statbuf));
|
809
|
+
X(LINK, link(req->path, req->new_path));
|
810
|
+
X(MKDIR, mkdir(req->path, req->mode));
|
811
|
+
X(MKDTEMP, uv__fs_mkdtemp(req));
|
812
|
+
X(OPEN, uv__fs_open(req));
|
813
|
+
X(READ, uv__fs_read(req));
|
814
|
+
X(SCANDIR, uv__fs_scandir(req));
|
815
|
+
X(READLINK, uv__fs_readlink(req));
|
816
|
+
X(RENAME, rename(req->path, req->new_path));
|
817
|
+
X(RMDIR, rmdir(req->path));
|
818
|
+
X(SENDFILE, uv__fs_sendfile(req));
|
819
|
+
X(STAT, uv__fs_stat(req->path, &req->statbuf));
|
820
|
+
X(SYMLINK, symlink(req->path, req->new_path));
|
821
|
+
X(UNLINK, unlink(req->path));
|
822
|
+
X(UTIME, uv__fs_utime(req));
|
823
|
+
X(WRITE, uv__fs_write(req));
|
824
|
+
default: abort();
|
825
|
+
}
|
826
|
+
#undef X
|
827
|
+
} while (r == -1 && errno == EINTR && retry_on_eintr);
|
828
|
+
|
829
|
+
if (r == -1)
|
830
|
+
req->result = -errno;
|
831
|
+
else
|
832
|
+
req->result = r;
|
833
|
+
|
834
|
+
if (r == 0 && (req->fs_type == UV_FS_STAT ||
|
835
|
+
req->fs_type == UV_FS_FSTAT ||
|
836
|
+
req->fs_type == UV_FS_LSTAT)) {
|
837
|
+
req->ptr = &req->statbuf;
|
838
|
+
}
|
839
|
+
}
|
840
|
+
|
841
|
+
|
842
|
+
static void uv__fs_done(struct uv__work* w, int status) {
|
843
|
+
uv_fs_t* req;
|
844
|
+
|
845
|
+
req = container_of(w, uv_fs_t, work_req);
|
846
|
+
uv__req_unregister(req->loop, req);
|
847
|
+
|
848
|
+
if (status == -ECANCELED) {
|
849
|
+
assert(req->result == 0);
|
850
|
+
req->result = -ECANCELED;
|
851
|
+
}
|
852
|
+
|
853
|
+
if (req->cb != NULL)
|
854
|
+
req->cb(req);
|
855
|
+
}
|
856
|
+
|
857
|
+
|
858
|
+
int uv_fs_access(uv_loop_t* loop,
|
859
|
+
uv_fs_t* req,
|
860
|
+
const char* path,
|
861
|
+
int flags,
|
862
|
+
uv_fs_cb cb) {
|
863
|
+
INIT(ACCESS);
|
864
|
+
PATH;
|
865
|
+
req->flags = flags;
|
866
|
+
POST;
|
867
|
+
}
|
868
|
+
|
869
|
+
|
870
|
+
int uv_fs_chmod(uv_loop_t* loop,
|
871
|
+
uv_fs_t* req,
|
872
|
+
const char* path,
|
873
|
+
int mode,
|
874
|
+
uv_fs_cb cb) {
|
875
|
+
INIT(CHMOD);
|
876
|
+
PATH;
|
877
|
+
req->mode = mode;
|
878
|
+
POST;
|
879
|
+
}
|
880
|
+
|
881
|
+
|
882
|
+
int uv_fs_chown(uv_loop_t* loop,
|
883
|
+
uv_fs_t* req,
|
884
|
+
const char* path,
|
885
|
+
uv_uid_t uid,
|
886
|
+
uv_gid_t gid,
|
887
|
+
uv_fs_cb cb) {
|
888
|
+
INIT(CHOWN);
|
889
|
+
PATH;
|
890
|
+
req->uid = uid;
|
891
|
+
req->gid = gid;
|
892
|
+
POST;
|
893
|
+
}
|
894
|
+
|
895
|
+
|
896
|
+
int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
|
897
|
+
INIT(CLOSE);
|
898
|
+
req->file = file;
|
899
|
+
POST;
|
900
|
+
}
|
901
|
+
|
902
|
+
|
903
|
+
int uv_fs_fchmod(uv_loop_t* loop,
|
904
|
+
uv_fs_t* req,
|
905
|
+
uv_file file,
|
906
|
+
int mode,
|
907
|
+
uv_fs_cb cb) {
|
908
|
+
INIT(FCHMOD);
|
909
|
+
req->file = file;
|
910
|
+
req->mode = mode;
|
911
|
+
POST;
|
912
|
+
}
|
913
|
+
|
914
|
+
|
915
|
+
int uv_fs_fchown(uv_loop_t* loop,
|
916
|
+
uv_fs_t* req,
|
917
|
+
uv_file file,
|
918
|
+
uv_uid_t uid,
|
919
|
+
uv_gid_t gid,
|
920
|
+
uv_fs_cb cb) {
|
921
|
+
INIT(FCHOWN);
|
922
|
+
req->file = file;
|
923
|
+
req->uid = uid;
|
924
|
+
req->gid = gid;
|
925
|
+
POST;
|
926
|
+
}
|
927
|
+
|
928
|
+
|
929
|
+
int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
|
930
|
+
INIT(FDATASYNC);
|
931
|
+
req->file = file;
|
932
|
+
POST;
|
933
|
+
}
|
934
|
+
|
935
|
+
|
936
|
+
int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
|
937
|
+
INIT(FSTAT);
|
938
|
+
req->file = file;
|
939
|
+
POST;
|
940
|
+
}
|
941
|
+
|
942
|
+
|
943
|
+
int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
|
944
|
+
INIT(FSYNC);
|
945
|
+
req->file = file;
|
946
|
+
POST;
|
947
|
+
}
|
948
|
+
|
949
|
+
|
950
|
+
int uv_fs_ftruncate(uv_loop_t* loop,
|
951
|
+
uv_fs_t* req,
|
952
|
+
uv_file file,
|
953
|
+
int64_t off,
|
954
|
+
uv_fs_cb cb) {
|
955
|
+
INIT(FTRUNCATE);
|
956
|
+
req->file = file;
|
957
|
+
req->off = off;
|
958
|
+
POST;
|
959
|
+
}
|
960
|
+
|
961
|
+
|
962
|
+
int uv_fs_futime(uv_loop_t* loop,
|
963
|
+
uv_fs_t* req,
|
964
|
+
uv_file file,
|
965
|
+
double atime,
|
966
|
+
double mtime,
|
967
|
+
uv_fs_cb cb) {
|
968
|
+
INIT(FUTIME);
|
969
|
+
req->file = file;
|
970
|
+
req->atime = atime;
|
971
|
+
req->mtime = mtime;
|
972
|
+
POST;
|
973
|
+
}
|
974
|
+
|
975
|
+
|
976
|
+
int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
977
|
+
INIT(LSTAT);
|
978
|
+
PATH;
|
979
|
+
POST;
|
980
|
+
}
|
981
|
+
|
982
|
+
|
983
|
+
int uv_fs_link(uv_loop_t* loop,
|
984
|
+
uv_fs_t* req,
|
985
|
+
const char* path,
|
986
|
+
const char* new_path,
|
987
|
+
uv_fs_cb cb) {
|
988
|
+
INIT(LINK);
|
989
|
+
PATH2;
|
990
|
+
POST;
|
991
|
+
}
|
992
|
+
|
993
|
+
|
994
|
+
int uv_fs_mkdir(uv_loop_t* loop,
|
995
|
+
uv_fs_t* req,
|
996
|
+
const char* path,
|
997
|
+
int mode,
|
998
|
+
uv_fs_cb cb) {
|
999
|
+
INIT(MKDIR);
|
1000
|
+
PATH;
|
1001
|
+
req->mode = mode;
|
1002
|
+
POST;
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
|
1006
|
+
int uv_fs_mkdtemp(uv_loop_t* loop,
|
1007
|
+
uv_fs_t* req,
|
1008
|
+
const char* tpl,
|
1009
|
+
uv_fs_cb cb) {
|
1010
|
+
INIT(MKDTEMP);
|
1011
|
+
req->path = strdup(tpl);
|
1012
|
+
if (req->path == NULL)
|
1013
|
+
return -ENOMEM;
|
1014
|
+
POST;
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
|
1018
|
+
int uv_fs_open(uv_loop_t* loop,
|
1019
|
+
uv_fs_t* req,
|
1020
|
+
const char* path,
|
1021
|
+
int flags,
|
1022
|
+
int mode,
|
1023
|
+
uv_fs_cb cb) {
|
1024
|
+
INIT(OPEN);
|
1025
|
+
PATH;
|
1026
|
+
req->flags = flags;
|
1027
|
+
req->mode = mode;
|
1028
|
+
POST;
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
|
1032
|
+
int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
|
1033
|
+
uv_file file,
|
1034
|
+
const uv_buf_t bufs[],
|
1035
|
+
unsigned int nbufs,
|
1036
|
+
int64_t off,
|
1037
|
+
uv_fs_cb cb) {
|
1038
|
+
INIT(READ);
|
1039
|
+
req->file = file;
|
1040
|
+
|
1041
|
+
req->nbufs = nbufs;
|
1042
|
+
req->bufs = req->bufsml;
|
1043
|
+
if (nbufs > ARRAY_SIZE(req->bufsml))
|
1044
|
+
req->bufs = malloc(nbufs * sizeof(*bufs));
|
1045
|
+
|
1046
|
+
if (req->bufs == NULL)
|
1047
|
+
return -ENOMEM;
|
1048
|
+
|
1049
|
+
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
|
1050
|
+
|
1051
|
+
req->off = off;
|
1052
|
+
POST;
|
1053
|
+
}
|
1054
|
+
|
1055
|
+
|
1056
|
+
int uv_fs_scandir(uv_loop_t* loop,
|
1057
|
+
uv_fs_t* req,
|
1058
|
+
const char* path,
|
1059
|
+
int flags,
|
1060
|
+
uv_fs_cb cb) {
|
1061
|
+
INIT(SCANDIR);
|
1062
|
+
PATH;
|
1063
|
+
req->flags = flags;
|
1064
|
+
POST;
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
|
1068
|
+
int uv_fs_readlink(uv_loop_t* loop,
|
1069
|
+
uv_fs_t* req,
|
1070
|
+
const char* path,
|
1071
|
+
uv_fs_cb cb) {
|
1072
|
+
INIT(READLINK);
|
1073
|
+
PATH;
|
1074
|
+
POST;
|
1075
|
+
}
|
1076
|
+
|
1077
|
+
|
1078
|
+
int uv_fs_rename(uv_loop_t* loop,
|
1079
|
+
uv_fs_t* req,
|
1080
|
+
const char* path,
|
1081
|
+
const char* new_path,
|
1082
|
+
uv_fs_cb cb) {
|
1083
|
+
INIT(RENAME);
|
1084
|
+
PATH2;
|
1085
|
+
POST;
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
|
1089
|
+
int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
1090
|
+
INIT(RMDIR);
|
1091
|
+
PATH;
|
1092
|
+
POST;
|
1093
|
+
}
|
1094
|
+
|
1095
|
+
|
1096
|
+
int uv_fs_sendfile(uv_loop_t* loop,
|
1097
|
+
uv_fs_t* req,
|
1098
|
+
uv_file out_fd,
|
1099
|
+
uv_file in_fd,
|
1100
|
+
int64_t off,
|
1101
|
+
size_t len,
|
1102
|
+
uv_fs_cb cb) {
|
1103
|
+
INIT(SENDFILE);
|
1104
|
+
req->flags = in_fd; /* hack */
|
1105
|
+
req->file = out_fd;
|
1106
|
+
req->off = off;
|
1107
|
+
req->bufsml[0].len = len;
|
1108
|
+
POST;
|
1109
|
+
}
|
1110
|
+
|
1111
|
+
|
1112
|
+
int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
1113
|
+
INIT(STAT);
|
1114
|
+
PATH;
|
1115
|
+
POST;
|
1116
|
+
}
|
1117
|
+
|
1118
|
+
|
1119
|
+
int uv_fs_symlink(uv_loop_t* loop,
|
1120
|
+
uv_fs_t* req,
|
1121
|
+
const char* path,
|
1122
|
+
const char* new_path,
|
1123
|
+
int flags,
|
1124
|
+
uv_fs_cb cb) {
|
1125
|
+
INIT(SYMLINK);
|
1126
|
+
PATH2;
|
1127
|
+
req->flags = flags;
|
1128
|
+
POST;
|
1129
|
+
}
|
1130
|
+
|
1131
|
+
|
1132
|
+
int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
1133
|
+
INIT(UNLINK);
|
1134
|
+
PATH;
|
1135
|
+
POST;
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
|
1139
|
+
int uv_fs_utime(uv_loop_t* loop,
|
1140
|
+
uv_fs_t* req,
|
1141
|
+
const char* path,
|
1142
|
+
double atime,
|
1143
|
+
double mtime,
|
1144
|
+
uv_fs_cb cb) {
|
1145
|
+
INIT(UTIME);
|
1146
|
+
PATH;
|
1147
|
+
req->atime = atime;
|
1148
|
+
req->mtime = mtime;
|
1149
|
+
POST;
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
|
1153
|
+
int uv_fs_write(uv_loop_t* loop,
|
1154
|
+
uv_fs_t* req,
|
1155
|
+
uv_file file,
|
1156
|
+
const uv_buf_t bufs[],
|
1157
|
+
unsigned int nbufs,
|
1158
|
+
int64_t off,
|
1159
|
+
uv_fs_cb cb) {
|
1160
|
+
INIT(WRITE);
|
1161
|
+
req->file = file;
|
1162
|
+
|
1163
|
+
req->nbufs = nbufs;
|
1164
|
+
req->bufs = req->bufsml;
|
1165
|
+
if (nbufs > ARRAY_SIZE(req->bufsml))
|
1166
|
+
req->bufs = malloc(nbufs * sizeof(*bufs));
|
1167
|
+
|
1168
|
+
if (req->bufs == NULL)
|
1169
|
+
return -ENOMEM;
|
1170
|
+
|
1171
|
+
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
|
1172
|
+
|
1173
|
+
req->off = off;
|
1174
|
+
POST;
|
1175
|
+
}
|
1176
|
+
|
1177
|
+
|
1178
|
+
void uv_fs_req_cleanup(uv_fs_t* req) {
|
1179
|
+
free((void*) req->path);
|
1180
|
+
req->path = NULL;
|
1181
|
+
req->new_path = NULL;
|
1182
|
+
|
1183
|
+
if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL)
|
1184
|
+
uv__fs_scandir_cleanup(req);
|
1185
|
+
|
1186
|
+
if (req->ptr != &req->statbuf)
|
1187
|
+
free(req->ptr);
|
1188
|
+
req->ptr = NULL;
|
1189
|
+
}
|