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.

Files changed (168) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/.editorconfig +20 -0
  5. data/CHANGELOG +21 -0
  6. data/bin/passenger-install-apache2-module +3 -1
  7. data/build/agents.rb +7 -5
  8. data/build/basics.rb +3 -3
  9. data/build/common_library.rb +52 -30
  10. data/build/cxx_tests.rb +20 -13
  11. data/build/misc.rb +5 -5
  12. data/doc/Design and Architecture.html +1 -1
  13. data/doc/Design and Architecture.txt +1 -1
  14. data/doc/Packaging.html +4 -4
  15. data/doc/Packaging.txt.md +4 -4
  16. data/doc/Users guide Apache.html +22 -9
  17. data/doc/Users guide Apache.idmap.txt +4 -2
  18. data/doc/Users guide Apache.txt +2 -0
  19. data/doc/Users guide Nginx.html +22 -9
  20. data/doc/Users guide Nginx.idmap.txt +4 -2
  21. data/doc/Users guide Nginx.txt +2 -0
  22. data/doc/Users guide Standalone.html +14 -9
  23. data/doc/Users guide Standalone.idmap.txt +4 -2
  24. data/doc/users_guide_snippets/installation.txt +10 -6
  25. data/ext/apache2/Hooks.cpp +13 -2
  26. data/ext/common/ApplicationPool2/Pool/Inspection.h +8 -3
  27. data/ext/common/BackgroundEventLoop.cpp +249 -67
  28. data/ext/common/BackgroundEventLoop.h +5 -5
  29. data/ext/common/Constants.h +1 -1
  30. data/ext/common/InstanceDirectory.h +8 -6
  31. data/ext/common/ServerKit/Context.h +8 -2
  32. data/ext/common/ServerKit/FileBufferedChannel.h +262 -226
  33. data/ext/common/ServerKit/HeaderTable.h +28 -3
  34. data/ext/common/ServerKit/HttpHeaderParser.h +37 -13
  35. data/ext/common/ServerKit/HttpServer.h +17 -1
  36. data/ext/common/ServerKit/Implementation.cpp +2 -0
  37. data/ext/common/ServerKit/Server.h +25 -28
  38. data/ext/common/Utils/IOUtils.cpp +11 -0
  39. data/ext/common/Utils/ProcessMetricsCollector.h +4 -0
  40. data/ext/common/Utils/StrIntUtils.cpp +11 -7
  41. data/ext/common/Utils/StrIntUtils.h +1 -1
  42. data/ext/common/Utils/StrIntUtilsNoStrictAliasing.cpp +21 -16
  43. data/ext/common/agents/Base.cpp +6 -0
  44. data/ext/common/agents/Base.h +2 -0
  45. data/ext/common/agents/HelperAgent/AdminServer.h +25 -25
  46. data/ext/common/agents/HelperAgent/Main.cpp +37 -12
  47. data/ext/common/agents/HelperAgent/RequestHandler.h +18 -20
  48. data/ext/common/agents/HelperAgent/RequestHandler/AppResponse.h +4 -0
  49. data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +10 -6
  50. data/ext/common/agents/HelperAgent/RequestHandler/Hooks.cpp +2 -0
  51. data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +1 -1
  52. data/ext/common/agents/HelperAgent/RequestHandler/SendRequest.cpp +1 -1
  53. data/ext/common/agents/HelperAgent/RequestHandler/Utils.cpp +9 -2
  54. data/ext/common/agents/HelperAgent/ResponseCache.h +11 -11
  55. data/ext/common/agents/LoggingAgent/AdminServer.h +8 -8
  56. data/ext/common/agents/LoggingAgent/Main.cpp +6 -5
  57. data/ext/common/agents/Watchdog/AdminServer.h +13 -13
  58. data/ext/common/agents/Watchdog/Main.cpp +8 -3
  59. data/ext/libuv/.gitignore +72 -0
  60. data/ext/libuv/AUTHORS +199 -0
  61. data/ext/libuv/ChangeLog +2023 -0
  62. data/ext/libuv/LICENSE +46 -0
  63. data/ext/libuv/Makefile.am +336 -0
  64. data/ext/libuv/README.md +197 -0
  65. data/ext/libuv/checksparse.sh +233 -0
  66. data/ext/libuv/common.gypi +210 -0
  67. data/ext/libuv/configure.ac +67 -0
  68. data/ext/libuv/gyp_uv.py +96 -0
  69. data/ext/libuv/include/android-ifaddrs.h +54 -0
  70. data/ext/libuv/include/pthread-fixes.h +72 -0
  71. data/ext/libuv/include/tree.h +768 -0
  72. data/ext/libuv/include/uv-aix.h +32 -0
  73. data/ext/libuv/include/uv-bsd.h +34 -0
  74. data/ext/libuv/include/uv-darwin.h +61 -0
  75. data/ext/libuv/include/uv-errno.h +418 -0
  76. data/ext/libuv/include/uv-linux.h +34 -0
  77. data/ext/libuv/include/uv-sunos.h +44 -0
  78. data/ext/libuv/include/uv-threadpool.h +37 -0
  79. data/ext/libuv/include/uv-unix.h +383 -0
  80. data/ext/libuv/include/uv-version.h +39 -0
  81. data/ext/libuv/include/uv.h +1455 -0
  82. data/ext/libuv/libuv.pc.in +11 -0
  83. data/ext/libuv/m4/.gitignore +4 -0
  84. data/ext/libuv/m4/as_case.m4 +21 -0
  85. data/ext/libuv/m4/libuv-check-flags.m4 +319 -0
  86. data/ext/libuv/src/fs-poll.c +255 -0
  87. data/ext/libuv/src/heap-inl.h +245 -0
  88. data/ext/libuv/src/inet.c +313 -0
  89. data/ext/libuv/src/queue.h +92 -0
  90. data/ext/libuv/src/threadpool.c +303 -0
  91. data/ext/libuv/src/unix/aix.c +1240 -0
  92. data/ext/libuv/src/unix/android-ifaddrs.c +703 -0
  93. data/ext/libuv/src/unix/async.c +284 -0
  94. data/ext/libuv/src/unix/atomic-ops.h +60 -0
  95. data/ext/libuv/src/unix/core.c +985 -0
  96. data/ext/libuv/src/unix/darwin-proctitle.c +206 -0
  97. data/ext/libuv/src/unix/darwin.c +331 -0
  98. data/ext/libuv/src/unix/dl.c +83 -0
  99. data/ext/libuv/src/unix/freebsd.c +435 -0
  100. data/ext/libuv/src/unix/fs.c +1189 -0
  101. data/ext/libuv/src/unix/fsevents.c +899 -0
  102. data/ext/libuv/src/unix/getaddrinfo.c +202 -0
  103. data/ext/libuv/src/unix/getnameinfo.c +120 -0
  104. data/ext/libuv/src/unix/internal.h +314 -0
  105. data/ext/libuv/src/unix/kqueue.c +418 -0
  106. data/ext/libuv/src/unix/linux-core.c +876 -0
  107. data/ext/libuv/src/unix/linux-inotify.c +257 -0
  108. data/ext/libuv/src/unix/linux-syscalls.c +471 -0
  109. data/ext/libuv/src/unix/linux-syscalls.h +158 -0
  110. data/ext/libuv/src/unix/loop-watcher.c +63 -0
  111. data/ext/libuv/src/unix/loop.c +135 -0
  112. data/ext/libuv/src/unix/netbsd.c +368 -0
  113. data/ext/libuv/src/unix/openbsd.c +384 -0
  114. data/ext/libuv/src/unix/pipe.c +288 -0
  115. data/ext/libuv/src/unix/poll.c +113 -0
  116. data/ext/libuv/src/unix/process.c +551 -0
  117. data/ext/libuv/src/unix/proctitle.c +102 -0
  118. data/ext/libuv/src/unix/pthread-fixes.c +103 -0
  119. data/ext/libuv/src/unix/signal.c +465 -0
  120. data/ext/libuv/src/unix/spinlock.h +53 -0
  121. data/ext/libuv/src/unix/stream.c +1598 -0
  122. data/ext/libuv/src/unix/sunos.c +763 -0
  123. data/ext/libuv/src/unix/tcp.c +327 -0
  124. data/ext/libuv/src/unix/thread.c +519 -0
  125. data/ext/libuv/src/unix/timer.c +172 -0
  126. data/ext/libuv/src/unix/tty.c +265 -0
  127. data/ext/libuv/src/unix/udp.c +833 -0
  128. data/ext/libuv/src/uv-common.c +544 -0
  129. data/ext/libuv/src/uv-common.h +214 -0
  130. data/ext/libuv/src/version.c +49 -0
  131. data/ext/libuv/uv.gyp +487 -0
  132. data/ext/nginx/ContentHandler.c +21 -10
  133. data/ext/nginx/ngx_http_passenger_module.c +7 -0
  134. data/ext/oxt/implementation.cpp +9 -2
  135. data/ext/oxt/initialize.hpp +5 -1
  136. data/lib/phusion_passenger.rb +3 -3
  137. data/lib/phusion_passenger/admin_tools/instance.rb +10 -6
  138. data/lib/phusion_passenger/admin_tools/instance_registry.rb +6 -2
  139. data/lib/phusion_passenger/packaging.rb +3 -4
  140. data/lib/phusion_passenger/platform_info.rb +13 -1
  141. data/lib/phusion_passenger/platform_info/apache.rb +15 -4
  142. data/lib/phusion_passenger/platform_info/apache_detector.rb +5 -1
  143. data/lib/phusion_passenger/rack/thread_handler_extension.rb +184 -99
  144. data/lib/phusion_passenger/request_handler/thread_handler.rb +13 -6
  145. data/lib/phusion_passenger/standalone/start_command.rb +2 -2
  146. data/resources/templates/apache2/apache_install_broken.txt.erb +2 -1
  147. metadata +99 -22
  148. metadata.gz.asc +7 -7
  149. data/ext/libeio/Changes +0 -76
  150. data/ext/libeio/LICENSE +0 -36
  151. data/ext/libeio/Makefile.am +0 -15
  152. data/ext/libeio/Makefile.in +0 -694
  153. data/ext/libeio/aclocal.m4 +0 -9418
  154. data/ext/libeio/autogen.sh +0 -3
  155. data/ext/libeio/config.guess +0 -1540
  156. data/ext/libeio/config.h.in +0 -136
  157. data/ext/libeio/config.sub +0 -1779
  158. data/ext/libeio/configure +0 -14822
  159. data/ext/libeio/configure.ac +0 -22
  160. data/ext/libeio/demo.c +0 -194
  161. data/ext/libeio/ecb.h +0 -714
  162. data/ext/libeio/eio.c +0 -2818
  163. data/ext/libeio/eio.h +0 -414
  164. data/ext/libeio/install-sh +0 -520
  165. data/ext/libeio/libeio.m4 +0 -195
  166. data/ext/libeio/ltmain.sh +0 -9636
  167. data/ext/libeio/missing +0 -376
  168. data/ext/libeio/xthread.h +0 -166
@@ -0,0 +1,202 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ * of this software and associated documentation files (the "Software"), to
4
+ * deal in the Software without restriction, including without limitation the
5
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6
+ * sell copies of the Software, and to permit persons to whom the Software is
7
+ * furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in
10
+ * all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18
+ * IN THE SOFTWARE.
19
+ */
20
+
21
+ /* Expose glibc-specific EAI_* error codes. Needs to be defined before we
22
+ * include any headers.
23
+ */
24
+ #ifndef _GNU_SOURCE
25
+ # define _GNU_SOURCE
26
+ #endif
27
+
28
+ #include "uv.h"
29
+ #include "internal.h"
30
+
31
+ #include <errno.h>
32
+ #include <stddef.h> /* NULL */
33
+ #include <stdlib.h>
34
+ #include <string.h>
35
+
36
+ /* EAI_* constants. */
37
+ #include <netdb.h>
38
+
39
+
40
+ int uv__getaddrinfo_translate_error(int sys_err) {
41
+ switch (sys_err) {
42
+ case 0: return 0;
43
+ #if defined(EAI_ADDRFAMILY)
44
+ case EAI_ADDRFAMILY: return UV_EAI_ADDRFAMILY;
45
+ #endif
46
+ #if defined(EAI_AGAIN)
47
+ case EAI_AGAIN: return UV_EAI_AGAIN;
48
+ #endif
49
+ #if defined(EAI_BADFLAGS)
50
+ case EAI_BADFLAGS: return UV_EAI_BADFLAGS;
51
+ #endif
52
+ #if defined(EAI_BADHINTS)
53
+ case EAI_BADHINTS: return UV_EAI_BADHINTS;
54
+ #endif
55
+ #if defined(EAI_CANCELED)
56
+ case EAI_CANCELED: return UV_EAI_CANCELED;
57
+ #endif
58
+ #if defined(EAI_FAIL)
59
+ case EAI_FAIL: return UV_EAI_FAIL;
60
+ #endif
61
+ #if defined(EAI_FAMILY)
62
+ case EAI_FAMILY: return UV_EAI_FAMILY;
63
+ #endif
64
+ #if defined(EAI_MEMORY)
65
+ case EAI_MEMORY: return UV_EAI_MEMORY;
66
+ #endif
67
+ #if defined(EAI_NODATA)
68
+ case EAI_NODATA: return UV_EAI_NODATA;
69
+ #endif
70
+ #if defined(EAI_NONAME)
71
+ # if !defined(EAI_NODATA) || EAI_NODATA != EAI_NONAME
72
+ case EAI_NONAME: return UV_EAI_NONAME;
73
+ # endif
74
+ #endif
75
+ #if defined(EAI_OVERFLOW)
76
+ case EAI_OVERFLOW: return UV_EAI_OVERFLOW;
77
+ #endif
78
+ #if defined(EAI_PROTOCOL)
79
+ case EAI_PROTOCOL: return UV_EAI_PROTOCOL;
80
+ #endif
81
+ #if defined(EAI_SERVICE)
82
+ case EAI_SERVICE: return UV_EAI_SERVICE;
83
+ #endif
84
+ #if defined(EAI_SOCKTYPE)
85
+ case EAI_SOCKTYPE: return UV_EAI_SOCKTYPE;
86
+ #endif
87
+ #if defined(EAI_SYSTEM)
88
+ case EAI_SYSTEM: return -errno;
89
+ #endif
90
+ }
91
+ assert(!"unknown EAI_* error code");
92
+ abort();
93
+ return 0; /* Pacify compiler. */
94
+ }
95
+
96
+
97
+ static void uv__getaddrinfo_work(struct uv__work* w) {
98
+ uv_getaddrinfo_t* req;
99
+ int err;
100
+
101
+ req = container_of(w, uv_getaddrinfo_t, work_req);
102
+ err = getaddrinfo(req->hostname, req->service, req->hints, &req->addrinfo);
103
+ req->retcode = uv__getaddrinfo_translate_error(err);
104
+ }
105
+
106
+
107
+ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
108
+ uv_getaddrinfo_t* req;
109
+
110
+ req = container_of(w, uv_getaddrinfo_t, work_req);
111
+ uv__req_unregister(req->loop, req);
112
+
113
+ /* See initialization in uv_getaddrinfo(). */
114
+ if (req->hints)
115
+ free(req->hints);
116
+ else if (req->service)
117
+ free(req->service);
118
+ else if (req->hostname)
119
+ free(req->hostname);
120
+ else
121
+ assert(0);
122
+
123
+ req->hints = NULL;
124
+ req->service = NULL;
125
+ req->hostname = NULL;
126
+
127
+ if (status == -ECANCELED) {
128
+ assert(req->retcode == 0);
129
+ req->retcode = UV_EAI_CANCELED;
130
+ }
131
+
132
+ if (req->cb)
133
+ req->cb(req, req->retcode, req->addrinfo);
134
+ }
135
+
136
+
137
+ int uv_getaddrinfo(uv_loop_t* loop,
138
+ uv_getaddrinfo_t* req,
139
+ uv_getaddrinfo_cb cb,
140
+ const char* hostname,
141
+ const char* service,
142
+ const struct addrinfo* hints) {
143
+ size_t hostname_len;
144
+ size_t service_len;
145
+ size_t hints_len;
146
+ size_t len;
147
+ char* buf;
148
+
149
+ if (req == NULL || (hostname == NULL && service == NULL))
150
+ return -EINVAL;
151
+
152
+ hostname_len = hostname ? strlen(hostname) + 1 : 0;
153
+ service_len = service ? strlen(service) + 1 : 0;
154
+ hints_len = hints ? sizeof(*hints) : 0;
155
+ buf = malloc(hostname_len + service_len + hints_len);
156
+
157
+ if (buf == NULL)
158
+ return -ENOMEM;
159
+
160
+ uv__req_init(loop, req, UV_GETADDRINFO);
161
+ req->loop = loop;
162
+ req->cb = cb;
163
+ req->addrinfo = NULL;
164
+ req->hints = NULL;
165
+ req->service = NULL;
166
+ req->hostname = NULL;
167
+ req->retcode = 0;
168
+
169
+ /* order matters, see uv_getaddrinfo_done() */
170
+ len = 0;
171
+
172
+ if (hints) {
173
+ req->hints = memcpy(buf + len, hints, sizeof(*hints));
174
+ len += sizeof(*hints);
175
+ }
176
+
177
+ if (service) {
178
+ req->service = memcpy(buf + len, service, service_len);
179
+ len += service_len;
180
+ }
181
+
182
+ if (hostname)
183
+ req->hostname = memcpy(buf + len, hostname, hostname_len);
184
+
185
+ if (cb) {
186
+ uv__work_submit(loop,
187
+ &req->work_req,
188
+ uv__getaddrinfo_work,
189
+ uv__getaddrinfo_done);
190
+ return 0;
191
+ } else {
192
+ uv__getaddrinfo_work(&req->work_req);
193
+ uv__getaddrinfo_done(&req->work_req, 0);
194
+ return req->retcode;
195
+ }
196
+ }
197
+
198
+
199
+ void uv_freeaddrinfo(struct addrinfo* ai) {
200
+ if (ai)
201
+ freeaddrinfo(ai);
202
+ }
@@ -0,0 +1,120 @@
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
+ #include <assert.h>
23
+ #include <stdlib.h>
24
+ #include <stdio.h>
25
+ #include <string.h>
26
+
27
+ #include "uv.h"
28
+ #include "internal.h"
29
+
30
+
31
+ static void uv__getnameinfo_work(struct uv__work* w) {
32
+ uv_getnameinfo_t* req;
33
+ int err;
34
+ socklen_t salen;
35
+
36
+ req = container_of(w, uv_getnameinfo_t, work_req);
37
+
38
+ if (req->storage.ss_family == AF_INET)
39
+ salen = sizeof(struct sockaddr_in);
40
+ else if (req->storage.ss_family == AF_INET6)
41
+ salen = sizeof(struct sockaddr_in6);
42
+ else
43
+ abort();
44
+
45
+ err = getnameinfo((struct sockaddr*) &req->storage,
46
+ salen,
47
+ req->host,
48
+ sizeof(req->host),
49
+ req->service,
50
+ sizeof(req->service),
51
+ req->flags);
52
+ req->retcode = uv__getaddrinfo_translate_error(err);
53
+ }
54
+
55
+ static void uv__getnameinfo_done(struct uv__work* w, int status) {
56
+ uv_getnameinfo_t* req;
57
+ char* host;
58
+ char* service;
59
+
60
+ req = container_of(w, uv_getnameinfo_t, work_req);
61
+ uv__req_unregister(req->loop, req);
62
+ host = service = NULL;
63
+
64
+ if (status == -ECANCELED) {
65
+ assert(req->retcode == 0);
66
+ req->retcode = UV_EAI_CANCELED;
67
+ } else if (req->retcode == 0) {
68
+ host = req->host;
69
+ service = req->service;
70
+ }
71
+
72
+ if (req->getnameinfo_cb)
73
+ req->getnameinfo_cb(req, req->retcode, host, service);
74
+ }
75
+
76
+ /*
77
+ * Entry point for getnameinfo
78
+ * return 0 if a callback will be made
79
+ * return error code if validation fails
80
+ */
81
+ int uv_getnameinfo(uv_loop_t* loop,
82
+ uv_getnameinfo_t* req,
83
+ uv_getnameinfo_cb getnameinfo_cb,
84
+ const struct sockaddr* addr,
85
+ int flags) {
86
+ if (req == NULL || addr == NULL)
87
+ return UV_EINVAL;
88
+
89
+ if (addr->sa_family == AF_INET) {
90
+ memcpy(&req->storage,
91
+ addr,
92
+ sizeof(struct sockaddr_in));
93
+ } else if (addr->sa_family == AF_INET6) {
94
+ memcpy(&req->storage,
95
+ addr,
96
+ sizeof(struct sockaddr_in6));
97
+ } else {
98
+ return UV_EINVAL;
99
+ }
100
+
101
+ uv__req_init(loop, (uv_req_t*)req, UV_GETNAMEINFO);
102
+
103
+ req->getnameinfo_cb = getnameinfo_cb;
104
+ req->flags = flags;
105
+ req->type = UV_GETNAMEINFO;
106
+ req->loop = loop;
107
+ req->retcode = 0;
108
+
109
+ if (getnameinfo_cb) {
110
+ uv__work_submit(loop,
111
+ &req->work_req,
112
+ uv__getnameinfo_work,
113
+ uv__getnameinfo_done);
114
+ return 0;
115
+ } else {
116
+ uv__getnameinfo_work(&req->work_req);
117
+ uv__getnameinfo_done(&req->work_req, 0);
118
+ return req->retcode;
119
+ }
120
+ }
@@ -0,0 +1,314 @@
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
+ #ifndef UV_UNIX_INTERNAL_H_
23
+ #define UV_UNIX_INTERNAL_H_
24
+
25
+ #include "uv-common.h"
26
+
27
+ #include <assert.h>
28
+ #include <stdlib.h> /* abort */
29
+ #include <string.h> /* strrchr */
30
+ #include <fcntl.h> /* O_CLOEXEC, may be */
31
+
32
+ #if defined(__STRICT_ANSI__)
33
+ # define inline __inline
34
+ #endif
35
+
36
+ #if defined(__linux__)
37
+ # include "linux-syscalls.h"
38
+ #endif /* __linux__ */
39
+
40
+ #if defined(__sun)
41
+ # include <sys/port.h>
42
+ # include <port.h>
43
+ #endif /* __sun */
44
+
45
+ #if defined(_AIX)
46
+ #define reqevents events
47
+ #define rtnevents revents
48
+ #include <sys/poll.h>
49
+ #endif /* _AIX */
50
+
51
+ #if defined(__APPLE__) && !TARGET_OS_IPHONE
52
+ # include <CoreServices/CoreServices.h>
53
+ #endif
54
+
55
+ #define ACCESS_ONCE(type, var) \
56
+ (*(volatile type*) &(var))
57
+
58
+ #define ROUND_UP(a, b) \
59
+ ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
60
+
61
+ #define UNREACHABLE() \
62
+ do { \
63
+ assert(0 && "unreachable code"); \
64
+ abort(); \
65
+ } \
66
+ while (0)
67
+
68
+ #define SAVE_ERRNO(block) \
69
+ do { \
70
+ int _saved_errno = errno; \
71
+ do { block; } while (0); \
72
+ errno = _saved_errno; \
73
+ } \
74
+ while (0)
75
+
76
+ /* The __clang__ and __INTEL_COMPILER checks are superfluous because they
77
+ * define __GNUC__. They are here to convey to you, dear reader, that these
78
+ * macros are enabled when compiling with clang or icc.
79
+ */
80
+ #if defined(__clang__) || \
81
+ defined(__GNUC__) || \
82
+ defined(__INTEL_COMPILER) || \
83
+ defined(__SUNPRO_C)
84
+ # define UV_DESTRUCTOR(declaration) __attribute__((destructor)) declaration
85
+ # define UV_UNUSED(declaration) __attribute__((unused)) declaration
86
+ #else
87
+ # define UV_DESTRUCTOR(declaration) declaration
88
+ # define UV_UNUSED(declaration) declaration
89
+ #endif
90
+
91
+ #if defined(__linux__)
92
+ # define UV__POLLIN UV__EPOLLIN
93
+ # define UV__POLLOUT UV__EPOLLOUT
94
+ # define UV__POLLERR UV__EPOLLERR
95
+ # define UV__POLLHUP UV__EPOLLHUP
96
+ #endif
97
+
98
+ #if defined(__sun) || defined(_AIX)
99
+ # define UV__POLLIN POLLIN
100
+ # define UV__POLLOUT POLLOUT
101
+ # define UV__POLLERR POLLERR
102
+ # define UV__POLLHUP POLLHUP
103
+ #endif
104
+
105
+ #ifndef UV__POLLIN
106
+ # define UV__POLLIN 1
107
+ #endif
108
+
109
+ #ifndef UV__POLLOUT
110
+ # define UV__POLLOUT 2
111
+ #endif
112
+
113
+ #ifndef UV__POLLERR
114
+ # define UV__POLLERR 4
115
+ #endif
116
+
117
+ #ifndef UV__POLLHUP
118
+ # define UV__POLLHUP 8
119
+ #endif
120
+
121
+ #if !defined(O_CLOEXEC) && defined(__FreeBSD__)
122
+ /*
123
+ * It may be that we are just missing `__POSIX_VISIBLE >= 200809`.
124
+ * Try using fixed value const and give up, if it doesn't work
125
+ */
126
+ # define O_CLOEXEC 0x00100000
127
+ #endif
128
+
129
+ typedef struct uv__stream_queued_fds_s uv__stream_queued_fds_t;
130
+
131
+ /* handle flags */
132
+ enum {
133
+ UV_CLOSING = 0x01, /* uv_close() called but not finished. */
134
+ UV_CLOSED = 0x02, /* close(2) finished. */
135
+ UV_STREAM_READING = 0x04, /* uv_read_start() called. */
136
+ UV_STREAM_SHUTTING = 0x08, /* uv_shutdown() called but not complete. */
137
+ UV_STREAM_SHUT = 0x10, /* Write side closed. */
138
+ UV_STREAM_READABLE = 0x20, /* The stream is readable */
139
+ UV_STREAM_WRITABLE = 0x40, /* The stream is writable */
140
+ UV_STREAM_BLOCKING = 0x80, /* Synchronous writes. */
141
+ UV_STREAM_READ_PARTIAL = 0x100, /* read(2) read less than requested. */
142
+ UV_STREAM_READ_EOF = 0x200, /* read(2) read EOF. */
143
+ UV_TCP_NODELAY = 0x400, /* Disable Nagle. */
144
+ UV_TCP_KEEPALIVE = 0x800, /* Turn on keep-alive. */
145
+ UV_TCP_SINGLE_ACCEPT = 0x1000, /* Only accept() when idle. */
146
+ UV_HANDLE_IPV6 = 0x10000 /* Handle is bound to a IPv6 socket. */
147
+ };
148
+
149
+ /* loop flags */
150
+ enum {
151
+ UV_LOOP_BLOCK_SIGPROF = 1
152
+ };
153
+
154
+ typedef enum {
155
+ UV_CLOCK_PRECISE = 0, /* Use the highest resolution clock available. */
156
+ UV_CLOCK_FAST = 1 /* Use the fastest clock with <= 1ms granularity. */
157
+ } uv_clocktype_t;
158
+
159
+ struct uv__stream_queued_fds_s {
160
+ unsigned int size;
161
+ unsigned int offset;
162
+ int fds[1];
163
+ };
164
+
165
+
166
+ /* core */
167
+ int uv__nonblock(int fd, int set);
168
+ int uv__close(int fd);
169
+ int uv__cloexec(int fd, int set);
170
+ int uv__socket(int domain, int type, int protocol);
171
+ int uv__dup(int fd);
172
+ ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags);
173
+ void uv__make_close_pending(uv_handle_t* handle);
174
+
175
+ void uv__io_init(uv__io_t* w, uv__io_cb cb, int fd);
176
+ void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events);
177
+ void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events);
178
+ void uv__io_close(uv_loop_t* loop, uv__io_t* w);
179
+ void uv__io_feed(uv_loop_t* loop, uv__io_t* w);
180
+ int uv__io_active(const uv__io_t* w, unsigned int events);
181
+ void uv__io_poll(uv_loop_t* loop, int timeout); /* in milliseconds or -1 */
182
+
183
+ /* async */
184
+ void uv__async_send(struct uv__async* wa);
185
+ void uv__async_init(struct uv__async* wa);
186
+ int uv__async_start(uv_loop_t* loop, struct uv__async* wa, uv__async_cb cb);
187
+ void uv__async_stop(uv_loop_t* loop, struct uv__async* wa);
188
+
189
+ /* loop */
190
+ void uv__run_idle(uv_loop_t* loop);
191
+ void uv__run_check(uv_loop_t* loop);
192
+ void uv__run_prepare(uv_loop_t* loop);
193
+
194
+ /* stream */
195
+ void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
196
+ uv_handle_type type);
197
+ int uv__stream_open(uv_stream_t*, int fd, int flags);
198
+ void uv__stream_destroy(uv_stream_t* stream);
199
+ #if defined(__APPLE__)
200
+ int uv__stream_try_select(uv_stream_t* stream, int* fd);
201
+ #endif /* defined(__APPLE__) */
202
+ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events);
203
+ int uv__accept(int sockfd);
204
+ int uv__dup2_cloexec(int oldfd, int newfd);
205
+ int uv__open_cloexec(const char* path, int flags);
206
+
207
+ /* tcp */
208
+ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb);
209
+ int uv__tcp_nodelay(int fd, int on);
210
+ int uv__tcp_keepalive(int fd, int on, unsigned int delay);
211
+
212
+ /* pipe */
213
+ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
214
+
215
+ /* timer */
216
+ void uv__run_timers(uv_loop_t* loop);
217
+ int uv__next_timeout(const uv_loop_t* loop);
218
+
219
+ /* signal */
220
+ void uv__signal_close(uv_signal_t* handle);
221
+ void uv__signal_global_once_init(void);
222
+ void uv__signal_loop_cleanup(uv_loop_t* loop);
223
+
224
+ /* platform specific */
225
+ uint64_t uv__hrtime(uv_clocktype_t type);
226
+ int uv__kqueue_init(uv_loop_t* loop);
227
+ int uv__platform_loop_init(uv_loop_t* loop);
228
+ void uv__platform_loop_delete(uv_loop_t* loop);
229
+ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd);
230
+
231
+ /* various */
232
+ void uv__async_close(uv_async_t* handle);
233
+ void uv__check_close(uv_check_t* handle);
234
+ void uv__fs_event_close(uv_fs_event_t* handle);
235
+ void uv__idle_close(uv_idle_t* handle);
236
+ void uv__pipe_close(uv_pipe_t* handle);
237
+ void uv__poll_close(uv_poll_t* handle);
238
+ void uv__prepare_close(uv_prepare_t* handle);
239
+ void uv__process_close(uv_process_t* handle);
240
+ void uv__stream_close(uv_stream_t* handle);
241
+ void uv__tcp_close(uv_tcp_t* handle);
242
+ void uv__timer_close(uv_timer_t* handle);
243
+ void uv__udp_close(uv_udp_t* handle);
244
+ void uv__udp_finish_close(uv_udp_t* handle);
245
+ uv_handle_type uv__handle_type(int fd);
246
+
247
+ #if defined(__APPLE__)
248
+ int uv___stream_fd(const uv_stream_t* handle);
249
+ #define uv__stream_fd(handle) (uv___stream_fd((const uv_stream_t*) (handle)))
250
+ #else
251
+ #define uv__stream_fd(handle) ((handle)->io_watcher.fd)
252
+ #endif /* defined(__APPLE__) */
253
+
254
+ #ifdef UV__O_NONBLOCK
255
+ # define UV__F_NONBLOCK UV__O_NONBLOCK
256
+ #else
257
+ # define UV__F_NONBLOCK 1
258
+ #endif
259
+
260
+ int uv__make_socketpair(int fds[2], int flags);
261
+ int uv__make_pipe(int fds[2], int flags);
262
+
263
+ #if defined(__APPLE__)
264
+
265
+ int uv__fsevents_init(uv_fs_event_t* handle);
266
+ int uv__fsevents_close(uv_fs_event_t* handle);
267
+ void uv__fsevents_loop_delete(uv_loop_t* loop);
268
+
269
+ /* OSX < 10.7 has no file events, polyfill them */
270
+ #ifndef MAC_OS_X_VERSION_10_7
271
+
272
+ static const int kFSEventStreamCreateFlagFileEvents = 0x00000010;
273
+ static const int kFSEventStreamEventFlagItemCreated = 0x00000100;
274
+ static const int kFSEventStreamEventFlagItemRemoved = 0x00000200;
275
+ static const int kFSEventStreamEventFlagItemInodeMetaMod = 0x00000400;
276
+ static const int kFSEventStreamEventFlagItemRenamed = 0x00000800;
277
+ static const int kFSEventStreamEventFlagItemModified = 0x00001000;
278
+ static const int kFSEventStreamEventFlagItemFinderInfoMod = 0x00002000;
279
+ static const int kFSEventStreamEventFlagItemChangeOwner = 0x00004000;
280
+ static const int kFSEventStreamEventFlagItemXattrMod = 0x00008000;
281
+ static const int kFSEventStreamEventFlagItemIsFile = 0x00010000;
282
+ static const int kFSEventStreamEventFlagItemIsDir = 0x00020000;
283
+ static const int kFSEventStreamEventFlagItemIsSymlink = 0x00040000;
284
+
285
+ #endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070 */
286
+
287
+ #endif /* defined(__APPLE__) */
288
+
289
+ UV_UNUSED(static void uv__req_init(uv_loop_t* loop,
290
+ uv_req_t* req,
291
+ uv_req_type type)) {
292
+ req->type = type;
293
+ uv__req_register(loop, req);
294
+ }
295
+ #define uv__req_init(loop, req, type) \
296
+ uv__req_init((loop), (uv_req_t*)(req), (type))
297
+
298
+ UV_UNUSED(static void uv__update_time(uv_loop_t* loop)) {
299
+ /* Use a fast time source if available. We only need millisecond precision.
300
+ */
301
+ loop->time = uv__hrtime(UV_CLOCK_FAST) / 1000000;
302
+ }
303
+
304
+ UV_UNUSED(static char* uv__basename_r(const char* path)) {
305
+ char* s;
306
+
307
+ s = strrchr(path, '/');
308
+ if (s == NULL)
309
+ return (char*) path;
310
+
311
+ return s + 1;
312
+ }
313
+
314
+ #endif /* UV_UNIX_INTERNAL_H_ */