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,158 @@
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_LINUX_SYSCALL_H_
23
+ #define UV_LINUX_SYSCALL_H_
24
+
25
+ #undef _GNU_SOURCE
26
+ #define _GNU_SOURCE
27
+
28
+ #include <stdint.h>
29
+ #include <signal.h>
30
+ #include <sys/types.h>
31
+ #include <sys/time.h>
32
+ #include <sys/socket.h>
33
+
34
+ #if defined(__alpha__)
35
+ # define UV__O_CLOEXEC 0x200000
36
+ #elif defined(__hppa__)
37
+ # define UV__O_CLOEXEC 0x200000
38
+ #elif defined(__sparc__)
39
+ # define UV__O_CLOEXEC 0x400000
40
+ #else
41
+ # define UV__O_CLOEXEC 0x80000
42
+ #endif
43
+
44
+ #if defined(__alpha__)
45
+ # define UV__O_NONBLOCK 0x4
46
+ #elif defined(__hppa__)
47
+ # define UV__O_NONBLOCK O_NONBLOCK
48
+ #elif defined(__mips__)
49
+ # define UV__O_NONBLOCK 0x80
50
+ #elif defined(__sparc__)
51
+ # define UV__O_NONBLOCK 0x4000
52
+ #else
53
+ # define UV__O_NONBLOCK 0x800
54
+ #endif
55
+
56
+ #define UV__EFD_CLOEXEC UV__O_CLOEXEC
57
+ #define UV__EFD_NONBLOCK UV__O_NONBLOCK
58
+
59
+ #define UV__IN_CLOEXEC UV__O_CLOEXEC
60
+ #define UV__IN_NONBLOCK UV__O_NONBLOCK
61
+
62
+ #define UV__SOCK_CLOEXEC UV__O_CLOEXEC
63
+ #if defined(SOCK_NONBLOCK)
64
+ # define UV__SOCK_NONBLOCK SOCK_NONBLOCK
65
+ #else
66
+ # define UV__SOCK_NONBLOCK UV__O_NONBLOCK
67
+ #endif
68
+
69
+ /* epoll flags */
70
+ #define UV__EPOLL_CLOEXEC UV__O_CLOEXEC
71
+ #define UV__EPOLL_CTL_ADD 1
72
+ #define UV__EPOLL_CTL_DEL 2
73
+ #define UV__EPOLL_CTL_MOD 3
74
+
75
+ #define UV__EPOLLIN 1
76
+ #define UV__EPOLLOUT 4
77
+ #define UV__EPOLLERR 8
78
+ #define UV__EPOLLHUP 16
79
+ #define UV__EPOLLONESHOT 0x40000000
80
+ #define UV__EPOLLET 0x80000000
81
+
82
+ /* inotify flags */
83
+ #define UV__IN_ACCESS 0x001
84
+ #define UV__IN_MODIFY 0x002
85
+ #define UV__IN_ATTRIB 0x004
86
+ #define UV__IN_CLOSE_WRITE 0x008
87
+ #define UV__IN_CLOSE_NOWRITE 0x010
88
+ #define UV__IN_OPEN 0x020
89
+ #define UV__IN_MOVED_FROM 0x040
90
+ #define UV__IN_MOVED_TO 0x080
91
+ #define UV__IN_CREATE 0x100
92
+ #define UV__IN_DELETE 0x200
93
+ #define UV__IN_DELETE_SELF 0x400
94
+ #define UV__IN_MOVE_SELF 0x800
95
+
96
+ #if defined(__x86_64__)
97
+ struct uv__epoll_event {
98
+ uint32_t events;
99
+ uint64_t data;
100
+ } __attribute__((packed));
101
+ #else
102
+ struct uv__epoll_event {
103
+ uint32_t events;
104
+ uint64_t data;
105
+ };
106
+ #endif
107
+
108
+ struct uv__inotify_event {
109
+ int32_t wd;
110
+ uint32_t mask;
111
+ uint32_t cookie;
112
+ uint32_t len;
113
+ /* char name[0]; */
114
+ };
115
+
116
+ struct uv__mmsghdr {
117
+ struct msghdr msg_hdr;
118
+ unsigned int msg_len;
119
+ };
120
+
121
+ int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags);
122
+ int uv__eventfd(unsigned int count);
123
+ int uv__epoll_create(int size);
124
+ int uv__epoll_create1(int flags);
125
+ int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event *ev);
126
+ int uv__epoll_wait(int epfd,
127
+ struct uv__epoll_event* events,
128
+ int nevents,
129
+ int timeout);
130
+ int uv__epoll_pwait(int epfd,
131
+ struct uv__epoll_event* events,
132
+ int nevents,
133
+ int timeout,
134
+ uint64_t sigmask);
135
+ int uv__eventfd2(unsigned int count, int flags);
136
+ int uv__inotify_init(void);
137
+ int uv__inotify_init1(int flags);
138
+ int uv__inotify_add_watch(int fd, const char* path, uint32_t mask);
139
+ int uv__inotify_rm_watch(int fd, int32_t wd);
140
+ int uv__pipe2(int pipefd[2], int flags);
141
+ int uv__recvmmsg(int fd,
142
+ struct uv__mmsghdr* mmsg,
143
+ unsigned int vlen,
144
+ unsigned int flags,
145
+ struct timespec* timeout);
146
+ int uv__sendmmsg(int fd,
147
+ struct uv__mmsghdr* mmsg,
148
+ unsigned int vlen,
149
+ unsigned int flags);
150
+ int uv__utimesat(int dirfd,
151
+ const char* path,
152
+ const struct timespec times[2],
153
+ int flags);
154
+ ssize_t uv__preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
155
+ ssize_t uv__pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);
156
+ int uv__dup3(int oldfd, int newfd, int flags);
157
+
158
+ #endif /* UV_LINUX_SYSCALL_H_ */
@@ -0,0 +1,63 @@
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
+ #define UV_LOOP_WATCHER_DEFINE(name, type) \
26
+ int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \
27
+ uv__handle_init(loop, (uv_handle_t*)handle, UV_##type); \
28
+ handle->name##_cb = NULL; \
29
+ return 0; \
30
+ } \
31
+ \
32
+ int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
33
+ if (uv__is_active(handle)) return 0; \
34
+ if (cb == NULL) return -EINVAL; \
35
+ QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \
36
+ handle->name##_cb = cb; \
37
+ uv__handle_start(handle); \
38
+ return 0; \
39
+ } \
40
+ \
41
+ int uv_##name##_stop(uv_##name##_t* handle) { \
42
+ if (!uv__is_active(handle)) return 0; \
43
+ QUEUE_REMOVE(&handle->queue); \
44
+ uv__handle_stop(handle); \
45
+ return 0; \
46
+ } \
47
+ \
48
+ void uv__run_##name(uv_loop_t* loop) { \
49
+ uv_##name##_t* h; \
50
+ QUEUE* q; \
51
+ QUEUE_FOREACH(q, &loop->name##_handles) { \
52
+ h = QUEUE_DATA(q, uv_##name##_t, queue); \
53
+ h->name##_cb(h); \
54
+ } \
55
+ } \
56
+ \
57
+ void uv__##name##_close(uv_##name##_t* handle) { \
58
+ uv_##name##_stop(handle); \
59
+ }
60
+
61
+ UV_LOOP_WATCHER_DEFINE(prepare, PREPARE)
62
+ UV_LOOP_WATCHER_DEFINE(check, CHECK)
63
+ UV_LOOP_WATCHER_DEFINE(idle, IDLE)
@@ -0,0 +1,135 @@
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 "tree.h"
24
+ #include "internal.h"
25
+ #include "heap-inl.h"
26
+ #include <stdlib.h>
27
+ #include <string.h>
28
+ #include <unistd.h>
29
+
30
+ int uv_loop_init(uv_loop_t* loop) {
31
+ int err;
32
+
33
+ uv__signal_global_once_init();
34
+
35
+ memset(loop, 0, sizeof(*loop));
36
+ heap_init((struct heap*) &loop->timer_heap);
37
+ QUEUE_INIT(&loop->wq);
38
+ QUEUE_INIT(&loop->active_reqs);
39
+ QUEUE_INIT(&loop->idle_handles);
40
+ QUEUE_INIT(&loop->async_handles);
41
+ QUEUE_INIT(&loop->check_handles);
42
+ QUEUE_INIT(&loop->prepare_handles);
43
+ QUEUE_INIT(&loop->handle_queue);
44
+
45
+ loop->nfds = 0;
46
+ loop->watchers = NULL;
47
+ loop->nwatchers = 0;
48
+ QUEUE_INIT(&loop->pending_queue);
49
+ QUEUE_INIT(&loop->watcher_queue);
50
+
51
+ loop->closing_handles = NULL;
52
+ uv__update_time(loop);
53
+ uv__async_init(&loop->async_watcher);
54
+ loop->signal_pipefd[0] = -1;
55
+ loop->signal_pipefd[1] = -1;
56
+ loop->backend_fd = -1;
57
+ loop->emfile_fd = -1;
58
+
59
+ loop->timer_counter = 0;
60
+ loop->stop_flag = 0;
61
+
62
+ err = uv__platform_loop_init(loop);
63
+ if (err)
64
+ return err;
65
+
66
+ uv_signal_init(loop, &loop->child_watcher);
67
+ uv__handle_unref(&loop->child_watcher);
68
+ loop->child_watcher.flags |= UV__HANDLE_INTERNAL;
69
+ QUEUE_INIT(&loop->process_handles);
70
+
71
+ if (uv_rwlock_init(&loop->cloexec_lock))
72
+ abort();
73
+
74
+ if (uv_mutex_init(&loop->wq_mutex))
75
+ abort();
76
+
77
+ if (uv_async_init(loop, &loop->wq_async, uv__work_done))
78
+ abort();
79
+
80
+ uv__handle_unref(&loop->wq_async);
81
+ loop->wq_async.flags |= UV__HANDLE_INTERNAL;
82
+
83
+ return 0;
84
+ }
85
+
86
+
87
+ void uv__loop_close(uv_loop_t* loop) {
88
+ uv__signal_loop_cleanup(loop);
89
+ uv__platform_loop_delete(loop);
90
+ uv__async_stop(loop, &loop->async_watcher);
91
+
92
+ if (loop->emfile_fd != -1) {
93
+ uv__close(loop->emfile_fd);
94
+ loop->emfile_fd = -1;
95
+ }
96
+
97
+ if (loop->backend_fd != -1) {
98
+ uv__close(loop->backend_fd);
99
+ loop->backend_fd = -1;
100
+ }
101
+
102
+ uv_mutex_lock(&loop->wq_mutex);
103
+ assert(QUEUE_EMPTY(&loop->wq) && "thread pool work queue not empty!");
104
+ assert(!uv__has_active_reqs(loop));
105
+ uv_mutex_unlock(&loop->wq_mutex);
106
+ uv_mutex_destroy(&loop->wq_mutex);
107
+
108
+ /*
109
+ * Note that all thread pool stuff is finished at this point and
110
+ * it is safe to just destroy rw lock
111
+ */
112
+ uv_rwlock_destroy(&loop->cloexec_lock);
113
+
114
+ #if 0
115
+ assert(QUEUE_EMPTY(&loop->pending_queue));
116
+ assert(QUEUE_EMPTY(&loop->watcher_queue));
117
+ assert(loop->nfds == 0);
118
+ #endif
119
+
120
+ free(loop->watchers);
121
+ loop->watchers = NULL;
122
+ loop->nwatchers = 0;
123
+ }
124
+
125
+
126
+ int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list ap) {
127
+ if (option != UV_LOOP_BLOCK_SIGNAL)
128
+ return UV_ENOSYS;
129
+
130
+ if (va_arg(ap, int) != SIGPROF)
131
+ return UV_EINVAL;
132
+
133
+ loop->flags |= UV_LOOP_BLOCK_SIGPROF;
134
+ return 0;
135
+ }
@@ -0,0 +1,368 @@
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 <assert.h>
25
+ #include <string.h>
26
+ #include <errno.h>
27
+
28
+ #include <kvm.h>
29
+ #include <paths.h>
30
+ #include <ifaddrs.h>
31
+ #include <unistd.h>
32
+ #include <time.h>
33
+ #include <stdlib.h>
34
+ #include <fcntl.h>
35
+
36
+ #include <net/if.h>
37
+ #include <net/if_dl.h>
38
+ #include <sys/resource.h>
39
+ #include <sys/types.h>
40
+ #include <sys/sysctl.h>
41
+ #include <uvm/uvm_extern.h>
42
+
43
+ #include <unistd.h>
44
+ #include <time.h>
45
+
46
+ #undef NANOSEC
47
+ #define NANOSEC ((uint64_t) 1e9)
48
+
49
+ static char *process_title;
50
+
51
+
52
+ int uv__platform_loop_init(uv_loop_t* loop) {
53
+ return uv__kqueue_init(loop);
54
+ }
55
+
56
+
57
+ void uv__platform_loop_delete(uv_loop_t* loop) {
58
+ }
59
+
60
+
61
+ uint64_t uv__hrtime(uv_clocktype_t type) {
62
+ struct timespec ts;
63
+ clock_gettime(CLOCK_MONOTONIC, &ts);
64
+ return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
65
+ }
66
+
67
+
68
+ void uv_loadavg(double avg[3]) {
69
+ struct loadavg info;
70
+ size_t size = sizeof(info);
71
+ int which[] = {CTL_VM, VM_LOADAVG};
72
+
73
+ if (sysctl(which, 2, &info, &size, NULL, 0) == -1) return;
74
+
75
+ avg[0] = (double) info.ldavg[0] / info.fscale;
76
+ avg[1] = (double) info.ldavg[1] / info.fscale;
77
+ avg[2] = (double) info.ldavg[2] / info.fscale;
78
+ }
79
+
80
+
81
+ int uv_exepath(char* buffer, size_t* size) {
82
+ int mib[4];
83
+ size_t cb;
84
+ pid_t mypid;
85
+
86
+ if (buffer == NULL || size == NULL || *size == 0)
87
+ return -EINVAL;
88
+
89
+ mypid = getpid();
90
+ mib[0] = CTL_KERN;
91
+ mib[1] = KERN_PROC_ARGS;
92
+ mib[2] = mypid;
93
+ mib[3] = KERN_PROC_ARGV;
94
+
95
+ cb = *size;
96
+ if (sysctl(mib, 4, buffer, &cb, NULL, 0))
97
+ return -errno;
98
+ *size = strlen(buffer);
99
+
100
+ return 0;
101
+ }
102
+
103
+
104
+ uint64_t uv_get_free_memory(void) {
105
+ struct uvmexp info;
106
+ size_t size = sizeof(info);
107
+ int which[] = {CTL_VM, VM_UVMEXP};
108
+
109
+ if (sysctl(which, 2, &info, &size, NULL, 0))
110
+ return -errno;
111
+
112
+ return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
113
+ }
114
+
115
+
116
+ uint64_t uv_get_total_memory(void) {
117
+ #if defined(HW_PHYSMEM64)
118
+ uint64_t info;
119
+ int which[] = {CTL_HW, HW_PHYSMEM64};
120
+ #else
121
+ unsigned int info;
122
+ int which[] = {CTL_HW, HW_PHYSMEM};
123
+ #endif
124
+ size_t size = sizeof(info);
125
+
126
+ if (sysctl(which, 2, &info, &size, NULL, 0))
127
+ return -errno;
128
+
129
+ return (uint64_t) info;
130
+ }
131
+
132
+
133
+ char** uv_setup_args(int argc, char** argv) {
134
+ process_title = argc ? strdup(argv[0]) : NULL;
135
+ return argv;
136
+ }
137
+
138
+
139
+ int uv_set_process_title(const char* title) {
140
+ if (process_title) free(process_title);
141
+
142
+ process_title = strdup(title);
143
+ setproctitle("%s", title);
144
+
145
+ return 0;
146
+ }
147
+
148
+
149
+ int uv_get_process_title(char* buffer, size_t size) {
150
+ if (process_title) {
151
+ strncpy(buffer, process_title, size);
152
+ } else {
153
+ if (size > 0) {
154
+ buffer[0] = '\0';
155
+ }
156
+ }
157
+
158
+ return 0;
159
+ }
160
+
161
+
162
+ int uv_resident_set_memory(size_t* rss) {
163
+ kvm_t *kd = NULL;
164
+ struct kinfo_proc2 *kinfo = NULL;
165
+ pid_t pid;
166
+ int nprocs;
167
+ int max_size = sizeof(struct kinfo_proc2);
168
+ int page_size;
169
+
170
+ page_size = getpagesize();
171
+ pid = getpid();
172
+
173
+ kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open");
174
+
175
+ if (kd == NULL) goto error;
176
+
177
+ kinfo = kvm_getproc2(kd, KERN_PROC_PID, pid, max_size, &nprocs);
178
+ if (kinfo == NULL) goto error;
179
+
180
+ *rss = kinfo->p_vm_rssize * page_size;
181
+
182
+ kvm_close(kd);
183
+
184
+ return 0;
185
+
186
+ error:
187
+ if (kd) kvm_close(kd);
188
+ return -EPERM;
189
+ }
190
+
191
+
192
+ int uv_uptime(double* uptime) {
193
+ time_t now;
194
+ struct timeval info;
195
+ size_t size = sizeof(info);
196
+ static int which[] = {CTL_KERN, KERN_BOOTTIME};
197
+
198
+ if (sysctl(which, 2, &info, &size, NULL, 0))
199
+ return -errno;
200
+
201
+ now = time(NULL);
202
+
203
+ *uptime = (double)(now - info.tv_sec);
204
+ return 0;
205
+ }
206
+
207
+
208
+ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
209
+ unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK);
210
+ unsigned int multiplier = ((uint64_t)1000L / ticks);
211
+ unsigned int cur = 0;
212
+ uv_cpu_info_t* cpu_info;
213
+ u_int64_t* cp_times;
214
+ char model[512];
215
+ u_int64_t cpuspeed;
216
+ int numcpus;
217
+ size_t size;
218
+ int i;
219
+
220
+ size = sizeof(model);
221
+ if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) &&
222
+ sysctlbyname("hw.model", &model, &size, NULL, 0)) {
223
+ return -errno;
224
+ }
225
+
226
+ size = sizeof(numcpus);
227
+ if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
228
+ return -errno;
229
+ *count = numcpus;
230
+
231
+ /* Only i386 and amd64 have machdep.tsc_freq */
232
+ size = sizeof(cpuspeed);
233
+ if (sysctlbyname("machdep.tsc_freq", &cpuspeed, &size, NULL, 0))
234
+ cpuspeed = 0;
235
+
236
+ size = numcpus * CPUSTATES * sizeof(*cp_times);
237
+ cp_times = malloc(size);
238
+ if (cp_times == NULL)
239
+ return -ENOMEM;
240
+
241
+ if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0))
242
+ return -errno;
243
+
244
+ *cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
245
+ if (!(*cpu_infos)) {
246
+ free(cp_times);
247
+ free(*cpu_infos);
248
+ return -ENOMEM;
249
+ }
250
+
251
+ for (i = 0; i < numcpus; i++) {
252
+ cpu_info = &(*cpu_infos)[i];
253
+ cpu_info->cpu_times.user = (uint64_t)(cp_times[CP_USER+cur]) * multiplier;
254
+ cpu_info->cpu_times.nice = (uint64_t)(cp_times[CP_NICE+cur]) * multiplier;
255
+ cpu_info->cpu_times.sys = (uint64_t)(cp_times[CP_SYS+cur]) * multiplier;
256
+ cpu_info->cpu_times.idle = (uint64_t)(cp_times[CP_IDLE+cur]) * multiplier;
257
+ cpu_info->cpu_times.irq = (uint64_t)(cp_times[CP_INTR+cur]) * multiplier;
258
+ cpu_info->model = strdup(model);
259
+ cpu_info->speed = (int)(cpuspeed/(uint64_t) 1e6);
260
+ cur += CPUSTATES;
261
+ }
262
+ free(cp_times);
263
+ return 0;
264
+ }
265
+
266
+
267
+ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
268
+ int i;
269
+
270
+ for (i = 0; i < count; i++) {
271
+ free(cpu_infos[i].model);
272
+ }
273
+
274
+ free(cpu_infos);
275
+ }
276
+
277
+
278
+ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
279
+ struct ifaddrs *addrs, *ent;
280
+ uv_interface_address_t* address;
281
+ int i;
282
+ struct sockaddr_dl *sa_addr;
283
+
284
+ if (getifaddrs(&addrs))
285
+ return -errno;
286
+
287
+ *count = 0;
288
+
289
+ /* Count the number of interfaces */
290
+ for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
291
+ if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
292
+ (ent->ifa_addr == NULL) ||
293
+ (ent->ifa_addr->sa_family != PF_INET)) {
294
+ continue;
295
+ }
296
+ (*count)++;
297
+ }
298
+
299
+ *addresses = malloc(*count * sizeof(**addresses));
300
+
301
+ if (!(*addresses))
302
+ return -ENOMEM;
303
+
304
+ address = *addresses;
305
+
306
+ for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
307
+ if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
308
+ continue;
309
+
310
+ if (ent->ifa_addr == NULL)
311
+ continue;
312
+
313
+ if (ent->ifa_addr->sa_family != PF_INET)
314
+ continue;
315
+
316
+ address->name = strdup(ent->ifa_name);
317
+
318
+ if (ent->ifa_addr->sa_family == AF_INET6) {
319
+ address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
320
+ } else {
321
+ address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr);
322
+ }
323
+
324
+ if (ent->ifa_netmask->sa_family == AF_INET6) {
325
+ address->netmask.netmask6 = *((struct sockaddr_in6*) ent->ifa_netmask);
326
+ } else {
327
+ address->netmask.netmask4 = *((struct sockaddr_in*) ent->ifa_netmask);
328
+ }
329
+
330
+ address->is_internal = !!(ent->ifa_flags & IFF_LOOPBACK);
331
+
332
+ address++;
333
+ }
334
+
335
+ /* Fill in physical addresses for each interface */
336
+ for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
337
+ if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
338
+ (ent->ifa_addr == NULL) ||
339
+ (ent->ifa_addr->sa_family != AF_LINK)) {
340
+ continue;
341
+ }
342
+
343
+ address = *addresses;
344
+
345
+ for (i = 0; i < (*count); i++) {
346
+ if (strcmp(address->name, ent->ifa_name) == 0) {
347
+ sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
348
+ memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
349
+ }
350
+ address++;
351
+ }
352
+ }
353
+
354
+ freeifaddrs(addrs);
355
+
356
+ return 0;
357
+ }
358
+
359
+
360
+ void uv_free_interface_addresses(uv_interface_address_t* addresses, int count) {
361
+ int i;
362
+
363
+ for (i = 0; i < count; i++) {
364
+ free(addresses[i].name);
365
+ }
366
+
367
+ free(addresses);
368
+ }