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,384 @@
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
+ #include "uv.h"
22
+ #include "internal.h"
23
+
24
+ #include <sys/types.h>
25
+ #include <sys/param.h>
26
+ #include <sys/resource.h>
27
+ #include <sys/sched.h>
28
+ #include <sys/time.h>
29
+ #include <sys/sysctl.h>
30
+
31
+ #include <ifaddrs.h>
32
+ #include <net/if.h>
33
+ #include <net/if_dl.h>
34
+
35
+ #include <errno.h>
36
+ #include <fcntl.h>
37
+ #include <kvm.h>
38
+ #include <paths.h>
39
+ #include <stdlib.h>
40
+ #include <string.h>
41
+ #include <unistd.h>
42
+
43
+ #undef NANOSEC
44
+ #define NANOSEC ((uint64_t) 1e9)
45
+
46
+
47
+ static char *process_title;
48
+
49
+
50
+ int uv__platform_loop_init(uv_loop_t* loop) {
51
+ return uv__kqueue_init(loop);
52
+ }
53
+
54
+
55
+ void uv__platform_loop_delete(uv_loop_t* loop) {
56
+ }
57
+
58
+
59
+ uint64_t uv__hrtime(uv_clocktype_t type) {
60
+ struct timespec ts;
61
+ clock_gettime(CLOCK_MONOTONIC, &ts);
62
+ return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
63
+ }
64
+
65
+
66
+ void uv_loadavg(double avg[3]) {
67
+ struct loadavg info;
68
+ size_t size = sizeof(info);
69
+ int which[] = {CTL_VM, VM_LOADAVG};
70
+
71
+ if (sysctl(which, 2, &info, &size, NULL, 0) < 0) return;
72
+
73
+ avg[0] = (double) info.ldavg[0] / info.fscale;
74
+ avg[1] = (double) info.ldavg[1] / info.fscale;
75
+ avg[2] = (double) info.ldavg[2] / info.fscale;
76
+ }
77
+
78
+
79
+ int uv_exepath(char* buffer, size_t* size) {
80
+ int mib[4];
81
+ char **argsbuf = NULL;
82
+ char **argsbuf_tmp;
83
+ size_t argsbuf_size = 100U;
84
+ size_t exepath_size;
85
+ pid_t mypid;
86
+ int err;
87
+
88
+ if (buffer == NULL || size == NULL || *size == 0)
89
+ return -EINVAL;
90
+
91
+ mypid = getpid();
92
+ for (;;) {
93
+ err = -ENOMEM;
94
+ argsbuf_tmp = realloc(argsbuf, argsbuf_size);
95
+ if (argsbuf_tmp == NULL)
96
+ goto out;
97
+ argsbuf = argsbuf_tmp;
98
+ mib[0] = CTL_KERN;
99
+ mib[1] = KERN_PROC_ARGS;
100
+ mib[2] = mypid;
101
+ mib[3] = KERN_PROC_ARGV;
102
+ if (sysctl(mib, 4, argsbuf, &argsbuf_size, NULL, 0) == 0) {
103
+ break;
104
+ }
105
+ if (errno != ENOMEM) {
106
+ err = -errno;
107
+ goto out;
108
+ }
109
+ argsbuf_size *= 2U;
110
+ }
111
+
112
+ if (argsbuf[0] == NULL) {
113
+ err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
114
+ goto out;
115
+ }
116
+
117
+ *size -= 1;
118
+ exepath_size = strlen(argsbuf[0]);
119
+ if (*size > exepath_size)
120
+ *size = exepath_size;
121
+
122
+ memcpy(buffer, argsbuf[0], *size);
123
+ buffer[*size] = '\0';
124
+ err = 0;
125
+
126
+ out:
127
+ free(argsbuf);
128
+
129
+ return err;
130
+ }
131
+
132
+
133
+ uint64_t uv_get_free_memory(void) {
134
+ struct uvmexp info;
135
+ size_t size = sizeof(info);
136
+ int which[] = {CTL_VM, VM_UVMEXP};
137
+
138
+ if (sysctl(which, 2, &info, &size, NULL, 0))
139
+ return -errno;
140
+
141
+ return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
142
+ }
143
+
144
+
145
+ uint64_t uv_get_total_memory(void) {
146
+ uint64_t info;
147
+ int which[] = {CTL_HW, HW_PHYSMEM64};
148
+ size_t size = sizeof(info);
149
+
150
+ if (sysctl(which, 2, &info, &size, NULL, 0))
151
+ return -errno;
152
+
153
+ return (uint64_t) info;
154
+ }
155
+
156
+
157
+ char** uv_setup_args(int argc, char** argv) {
158
+ process_title = argc ? strdup(argv[0]) : NULL;
159
+ return argv;
160
+ }
161
+
162
+
163
+ int uv_set_process_title(const char* title) {
164
+ if (process_title) free(process_title);
165
+ process_title = strdup(title);
166
+ setproctitle(title);
167
+ return 0;
168
+ }
169
+
170
+
171
+ int uv_get_process_title(char* buffer, size_t size) {
172
+ if (process_title) {
173
+ strncpy(buffer, process_title, size);
174
+ } else {
175
+ if (size > 0) {
176
+ buffer[0] = '\0';
177
+ }
178
+ }
179
+
180
+ return 0;
181
+ }
182
+
183
+
184
+ int uv_resident_set_memory(size_t* rss) {
185
+ struct kinfo_proc kinfo;
186
+ size_t page_size = getpagesize();
187
+ size_t size = sizeof(struct kinfo_proc);
188
+ int mib[6];
189
+
190
+ mib[0] = CTL_KERN;
191
+ mib[1] = KERN_PROC;
192
+ mib[2] = KERN_PROC_PID;
193
+ mib[3] = getpid();
194
+ mib[4] = sizeof(struct kinfo_proc);
195
+ mib[5] = 1;
196
+
197
+ if (sysctl(mib, 6, &kinfo, &size, NULL, 0) < 0)
198
+ return -errno;
199
+
200
+ *rss = kinfo.p_vm_rssize * page_size;
201
+ return 0;
202
+ }
203
+
204
+
205
+ int uv_uptime(double* uptime) {
206
+ time_t now;
207
+ struct timeval info;
208
+ size_t size = sizeof(info);
209
+ static int which[] = {CTL_KERN, KERN_BOOTTIME};
210
+
211
+ if (sysctl(which, 2, &info, &size, NULL, 0))
212
+ return -errno;
213
+
214
+ now = time(NULL);
215
+
216
+ *uptime = (double)(now - info.tv_sec);
217
+ return 0;
218
+ }
219
+
220
+
221
+ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
222
+ unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
223
+ multiplier = ((uint64_t)1000L / ticks), cpuspeed;
224
+ uint64_t info[CPUSTATES];
225
+ char model[512];
226
+ int numcpus = 1;
227
+ int which[] = {CTL_HW,HW_MODEL,0};
228
+ size_t size;
229
+ int i;
230
+ uv_cpu_info_t* cpu_info;
231
+
232
+ size = sizeof(model);
233
+ if (sysctl(which, 2, &model, &size, NULL, 0))
234
+ return -errno;
235
+
236
+ which[1] = HW_NCPU;
237
+ size = sizeof(numcpus);
238
+ if (sysctl(which, 2, &numcpus, &size, NULL, 0))
239
+ return -errno;
240
+
241
+ *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
242
+ if (!(*cpu_infos))
243
+ return -ENOMEM;
244
+
245
+ *count = numcpus;
246
+
247
+ which[1] = HW_CPUSPEED;
248
+ size = sizeof(cpuspeed);
249
+ if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) {
250
+ SAVE_ERRNO(free(*cpu_infos));
251
+ return -errno;
252
+ }
253
+
254
+ size = sizeof(info);
255
+ which[0] = CTL_KERN;
256
+ which[1] = KERN_CPTIME2;
257
+ for (i = 0; i < numcpus; i++) {
258
+ which[2] = i;
259
+ size = sizeof(info);
260
+ if (sysctl(which, 3, &info, &size, NULL, 0)) {
261
+ SAVE_ERRNO(free(*cpu_infos));
262
+ return -errno;
263
+ }
264
+
265
+ cpu_info = &(*cpu_infos)[i];
266
+
267
+ cpu_info->cpu_times.user = (uint64_t)(info[CP_USER]) * multiplier;
268
+ cpu_info->cpu_times.nice = (uint64_t)(info[CP_NICE]) * multiplier;
269
+ cpu_info->cpu_times.sys = (uint64_t)(info[CP_SYS]) * multiplier;
270
+ cpu_info->cpu_times.idle = (uint64_t)(info[CP_IDLE]) * multiplier;
271
+ cpu_info->cpu_times.irq = (uint64_t)(info[CP_INTR]) * multiplier;
272
+
273
+ cpu_info->model = strdup(model);
274
+ cpu_info->speed = cpuspeed;
275
+ }
276
+
277
+ return 0;
278
+ }
279
+
280
+
281
+ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
282
+ int i;
283
+
284
+ for (i = 0; i < count; i++) {
285
+ free(cpu_infos[i].model);
286
+ }
287
+
288
+ free(cpu_infos);
289
+ }
290
+
291
+
292
+ int uv_interface_addresses(uv_interface_address_t** addresses,
293
+ int* count) {
294
+ struct ifaddrs *addrs, *ent;
295
+ uv_interface_address_t* address;
296
+ int i;
297
+ struct sockaddr_dl *sa_addr;
298
+
299
+ if (getifaddrs(&addrs) != 0)
300
+ return -errno;
301
+
302
+ *count = 0;
303
+
304
+ /* Count the number of interfaces */
305
+ for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
306
+ if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
307
+ (ent->ifa_addr == NULL) ||
308
+ (ent->ifa_addr->sa_family != PF_INET)) {
309
+ continue;
310
+ }
311
+ (*count)++;
312
+ }
313
+
314
+ *addresses = malloc(*count * sizeof(**addresses));
315
+
316
+ if (!(*addresses))
317
+ return -ENOMEM;
318
+
319
+ address = *addresses;
320
+
321
+ for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
322
+ if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
323
+ continue;
324
+
325
+ if (ent->ifa_addr == NULL)
326
+ continue;
327
+
328
+ if (ent->ifa_addr->sa_family != PF_INET)
329
+ continue;
330
+
331
+ address->name = strdup(ent->ifa_name);
332
+
333
+ if (ent->ifa_addr->sa_family == AF_INET6) {
334
+ address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
335
+ } else {
336
+ address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr);
337
+ }
338
+
339
+ if (ent->ifa_netmask->sa_family == AF_INET6) {
340
+ address->netmask.netmask6 = *((struct sockaddr_in6*) ent->ifa_netmask);
341
+ } else {
342
+ address->netmask.netmask4 = *((struct sockaddr_in*) ent->ifa_netmask);
343
+ }
344
+
345
+ address->is_internal = !!(ent->ifa_flags & IFF_LOOPBACK);
346
+
347
+ address++;
348
+ }
349
+
350
+ /* Fill in physical addresses for each interface */
351
+ for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
352
+ if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
353
+ (ent->ifa_addr == NULL) ||
354
+ (ent->ifa_addr->sa_family != AF_LINK)) {
355
+ continue;
356
+ }
357
+
358
+ address = *addresses;
359
+
360
+ for (i = 0; i < (*count); i++) {
361
+ if (strcmp(address->name, ent->ifa_name) == 0) {
362
+ sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
363
+ memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
364
+ }
365
+ address++;
366
+ }
367
+ }
368
+
369
+ freeifaddrs(addrs);
370
+
371
+ return 0;
372
+ }
373
+
374
+
375
+ void uv_free_interface_addresses(uv_interface_address_t* addresses,
376
+ int count) {
377
+ int i;
378
+
379
+ for (i = 0; i < count; i++) {
380
+ free(addresses[i].name);
381
+ }
382
+
383
+ free(addresses);
384
+ }
@@ -0,0 +1,288 @@
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 "uv.h"
23
+ #include "internal.h"
24
+
25
+ #include <assert.h>
26
+ #include <errno.h>
27
+ #include <string.h>
28
+ #include <sys/un.h>
29
+ #include <unistd.h>
30
+ #include <stdlib.h>
31
+
32
+
33
+ int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
34
+ uv__stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE);
35
+ handle->shutdown_req = NULL;
36
+ handle->connect_req = NULL;
37
+ handle->pipe_fname = NULL;
38
+ handle->ipc = ipc;
39
+ return 0;
40
+ }
41
+
42
+
43
+ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
44
+ struct sockaddr_un saddr;
45
+ const char* pipe_fname;
46
+ int sockfd;
47
+ int err;
48
+
49
+ pipe_fname = NULL;
50
+ sockfd = -1;
51
+
52
+ /* Already bound? */
53
+ if (uv__stream_fd(handle) >= 0)
54
+ return -EINVAL;
55
+
56
+ /* Make a copy of the file name, it outlives this function's scope. */
57
+ pipe_fname = strdup(name);
58
+ if (pipe_fname == NULL)
59
+ return -ENOMEM;
60
+
61
+ /* We've got a copy, don't touch the original any more. */
62
+ name = NULL;
63
+
64
+ err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
65
+ if (err < 0)
66
+ goto err_socket;
67
+ sockfd = err;
68
+
69
+ memset(&saddr, 0, sizeof saddr);
70
+ strncpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path) - 1);
71
+ saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
72
+ saddr.sun_family = AF_UNIX;
73
+
74
+ if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
75
+ err = -errno;
76
+ /* Convert ENOENT to EACCES for compatibility with Windows. */
77
+ if (err == -ENOENT)
78
+ err = -EACCES;
79
+ goto err_bind;
80
+ }
81
+
82
+ /* Success. */
83
+ handle->pipe_fname = pipe_fname; /* Is a strdup'ed copy. */
84
+ handle->io_watcher.fd = sockfd;
85
+ return 0;
86
+
87
+ err_bind:
88
+ uv__close(sockfd);
89
+
90
+ err_socket:
91
+ free((void*)pipe_fname);
92
+ return err;
93
+ }
94
+
95
+
96
+ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
97
+ if (uv__stream_fd(handle) == -1)
98
+ return -EINVAL;
99
+
100
+ if (listen(uv__stream_fd(handle), backlog))
101
+ return -errno;
102
+
103
+ handle->connection_cb = cb;
104
+ handle->io_watcher.cb = uv__server_io;
105
+ uv__io_start(handle->loop, &handle->io_watcher, UV__POLLIN);
106
+ return 0;
107
+ }
108
+
109
+
110
+ void uv__pipe_close(uv_pipe_t* handle) {
111
+ if (handle->pipe_fname) {
112
+ /*
113
+ * Unlink the file system entity before closing the file descriptor.
114
+ * Doing it the other way around introduces a race where our process
115
+ * unlinks a socket with the same name that's just been created by
116
+ * another thread or process.
117
+ */
118
+ unlink(handle->pipe_fname);
119
+ free((void*)handle->pipe_fname);
120
+ handle->pipe_fname = NULL;
121
+ }
122
+
123
+ uv__stream_close((uv_stream_t*)handle);
124
+ }
125
+
126
+
127
+ int uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
128
+ int err;
129
+
130
+ err = uv__nonblock(fd, 1);
131
+ if (err)
132
+ return err;
133
+
134
+ #if defined(__APPLE__)
135
+ err = uv__stream_try_select((uv_stream_t*) handle, &fd);
136
+ if (err)
137
+ return err;
138
+ #endif /* defined(__APPLE__) */
139
+
140
+ return uv__stream_open((uv_stream_t*)handle,
141
+ fd,
142
+ UV_STREAM_READABLE | UV_STREAM_WRITABLE);
143
+ }
144
+
145
+
146
+ void uv_pipe_connect(uv_connect_t* req,
147
+ uv_pipe_t* handle,
148
+ const char* name,
149
+ uv_connect_cb cb) {
150
+ struct sockaddr_un saddr;
151
+ int new_sock;
152
+ int err;
153
+ int r;
154
+
155
+ new_sock = (uv__stream_fd(handle) == -1);
156
+
157
+ if (new_sock) {
158
+ err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
159
+ if (err < 0)
160
+ goto out;
161
+ handle->io_watcher.fd = err;
162
+ }
163
+
164
+ memset(&saddr, 0, sizeof saddr);
165
+ strncpy(saddr.sun_path, name, sizeof(saddr.sun_path) - 1);
166
+ saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
167
+ saddr.sun_family = AF_UNIX;
168
+
169
+ do {
170
+ r = connect(uv__stream_fd(handle),
171
+ (struct sockaddr*)&saddr, sizeof saddr);
172
+ }
173
+ while (r == -1 && errno == EINTR);
174
+
175
+ if (r == -1 && errno != EINPROGRESS) {
176
+ err = -errno;
177
+ goto out;
178
+ }
179
+
180
+ err = 0;
181
+ if (new_sock) {
182
+ err = uv__stream_open((uv_stream_t*)handle,
183
+ uv__stream_fd(handle),
184
+ UV_STREAM_READABLE | UV_STREAM_WRITABLE);
185
+ }
186
+
187
+ if (err == 0)
188
+ uv__io_start(handle->loop, &handle->io_watcher, UV__POLLIN | UV__POLLOUT);
189
+
190
+ out:
191
+ handle->delayed_error = err;
192
+ handle->connect_req = req;
193
+
194
+ uv__req_init(handle->loop, req, UV_CONNECT);
195
+ req->handle = (uv_stream_t*)handle;
196
+ req->cb = cb;
197
+ QUEUE_INIT(&req->queue);
198
+
199
+ /* Force callback to run on next tick in case of error. */
200
+ if (err)
201
+ uv__io_feed(handle->loop, &handle->io_watcher);
202
+
203
+ /* Mimic the Windows pipe implementation, always
204
+ * return 0 and let the callback handle errors.
205
+ */
206
+ }
207
+
208
+
209
+ typedef int (*uv__peersockfunc)(int, struct sockaddr*, socklen_t*);
210
+
211
+
212
+ static int uv__pipe_getsockpeername(const uv_pipe_t* handle,
213
+ uv__peersockfunc func,
214
+ char* buffer,
215
+ size_t* size) {
216
+ struct sockaddr_un sa;
217
+ socklen_t addrlen;
218
+ int err;
219
+
220
+ addrlen = sizeof(sa);
221
+ memset(&sa, 0, addrlen);
222
+ err = func(uv__stream_fd(handle), (struct sockaddr*) &sa, &addrlen);
223
+ if (err < 0) {
224
+ *size = 0;
225
+ return -errno;
226
+ }
227
+
228
+ #if defined(__linux__)
229
+ if (sa.sun_path[0] == 0)
230
+ /* Linux abstract namespace */
231
+ addrlen -= offsetof(struct sockaddr_un, sun_path);
232
+ else
233
+ #endif
234
+ addrlen = strlen(sa.sun_path);
235
+
236
+
237
+ if (addrlen > *size) {
238
+ *size = addrlen;
239
+ return UV_ENOBUFS;
240
+ }
241
+
242
+ memcpy(buffer, sa.sun_path, addrlen);
243
+ *size = addrlen;
244
+
245
+ return 0;
246
+ }
247
+
248
+
249
+ int uv_pipe_getsockname(const uv_pipe_t* handle, char* buffer, size_t* size) {
250
+ return uv__pipe_getsockpeername(handle, getsockname, buffer, size);
251
+ }
252
+
253
+
254
+ int uv_pipe_getpeername(const uv_pipe_t* handle, char* buffer, size_t* size) {
255
+ return uv__pipe_getsockpeername(handle, getpeername, buffer, size);
256
+ }
257
+
258
+
259
+ void uv_pipe_pending_instances(uv_pipe_t* handle, int count) {
260
+ }
261
+
262
+
263
+ int uv_pipe_pending_count(uv_pipe_t* handle) {
264
+ uv__stream_queued_fds_t* queued_fds;
265
+
266
+ if (!handle->ipc)
267
+ return 0;
268
+
269
+ if (handle->accepted_fd == -1)
270
+ return 0;
271
+
272
+ if (handle->queued_fds == NULL)
273
+ return 1;
274
+
275
+ queued_fds = handle->queued_fds;
276
+ return queued_fds->offset + 1;
277
+ }
278
+
279
+
280
+ uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle) {
281
+ if (!handle->ipc)
282
+ return UV_UNKNOWN_HANDLE;
283
+
284
+ if (handle->accepted_fd == -1)
285
+ return UV_UNKNOWN_HANDLE;
286
+ else
287
+ return uv__handle_type(handle->accepted_fd);
288
+ }