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,206 @@
|
|
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 <dlfcn.h>
|
22
|
+
#include <errno.h>
|
23
|
+
#include <stdlib.h>
|
24
|
+
#include <string.h>
|
25
|
+
|
26
|
+
#include <TargetConditionals.h>
|
27
|
+
|
28
|
+
#if !TARGET_OS_IPHONE
|
29
|
+
# include <CoreFoundation/CoreFoundation.h>
|
30
|
+
# include <ApplicationServices/ApplicationServices.h>
|
31
|
+
#endif
|
32
|
+
|
33
|
+
|
34
|
+
static int uv__pthread_setname_np(const char* name) {
|
35
|
+
int (*dynamic_pthread_setname_np)(const char* name);
|
36
|
+
char namebuf[64]; /* MAXTHREADNAMESIZE */
|
37
|
+
int err;
|
38
|
+
|
39
|
+
/* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
|
40
|
+
*(void **)(&dynamic_pthread_setname_np) =
|
41
|
+
dlsym(RTLD_DEFAULT, "pthread_setname_np");
|
42
|
+
|
43
|
+
if (dynamic_pthread_setname_np == NULL)
|
44
|
+
return -ENOSYS;
|
45
|
+
|
46
|
+
strncpy(namebuf, name, sizeof(namebuf) - 1);
|
47
|
+
namebuf[sizeof(namebuf) - 1] = '\0';
|
48
|
+
|
49
|
+
err = dynamic_pthread_setname_np(namebuf);
|
50
|
+
if (err)
|
51
|
+
return -err;
|
52
|
+
|
53
|
+
return 0;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
int uv__set_process_title(const char* title) {
|
58
|
+
#if TARGET_OS_IPHONE
|
59
|
+
return uv__pthread_setname_np(title);
|
60
|
+
#else
|
61
|
+
CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
|
62
|
+
const char*,
|
63
|
+
CFStringEncoding);
|
64
|
+
CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
|
65
|
+
void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
|
66
|
+
void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
|
67
|
+
CFTypeRef (*pLSGetCurrentApplicationASN)(void);
|
68
|
+
OSStatus (*pLSSetApplicationInformationItem)(int,
|
69
|
+
CFTypeRef,
|
70
|
+
CFStringRef,
|
71
|
+
CFStringRef,
|
72
|
+
CFDictionaryRef*);
|
73
|
+
void* application_services_handle;
|
74
|
+
void* core_foundation_handle;
|
75
|
+
CFBundleRef launch_services_bundle;
|
76
|
+
CFStringRef* display_name_key;
|
77
|
+
CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
|
78
|
+
CFBundleRef (*pCFBundleGetMainBundle)(void);
|
79
|
+
CFBundleRef hi_services_bundle;
|
80
|
+
OSStatus (*pSetApplicationIsDaemon)(int);
|
81
|
+
CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef);
|
82
|
+
void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t,
|
83
|
+
void*);
|
84
|
+
CFTypeRef asn;
|
85
|
+
int err;
|
86
|
+
|
87
|
+
err = -ENOENT;
|
88
|
+
application_services_handle = dlopen("/System/Library/Frameworks/"
|
89
|
+
"ApplicationServices.framework/"
|
90
|
+
"Versions/A/ApplicationServices",
|
91
|
+
RTLD_LAZY | RTLD_LOCAL);
|
92
|
+
core_foundation_handle = dlopen("/System/Library/Frameworks/"
|
93
|
+
"CoreFoundation.framework/"
|
94
|
+
"Versions/A/CoreFoundation",
|
95
|
+
RTLD_LAZY | RTLD_LOCAL);
|
96
|
+
|
97
|
+
if (application_services_handle == NULL || core_foundation_handle == NULL)
|
98
|
+
goto out;
|
99
|
+
|
100
|
+
*(void **)(&pCFStringCreateWithCString) =
|
101
|
+
dlsym(core_foundation_handle, "CFStringCreateWithCString");
|
102
|
+
*(void **)(&pCFBundleGetBundleWithIdentifier) =
|
103
|
+
dlsym(core_foundation_handle, "CFBundleGetBundleWithIdentifier");
|
104
|
+
*(void **)(&pCFBundleGetDataPointerForName) =
|
105
|
+
dlsym(core_foundation_handle, "CFBundleGetDataPointerForName");
|
106
|
+
*(void **)(&pCFBundleGetFunctionPointerForName) =
|
107
|
+
dlsym(core_foundation_handle, "CFBundleGetFunctionPointerForName");
|
108
|
+
|
109
|
+
if (pCFStringCreateWithCString == NULL ||
|
110
|
+
pCFBundleGetBundleWithIdentifier == NULL ||
|
111
|
+
pCFBundleGetDataPointerForName == NULL ||
|
112
|
+
pCFBundleGetFunctionPointerForName == NULL) {
|
113
|
+
goto out;
|
114
|
+
}
|
115
|
+
|
116
|
+
#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
|
117
|
+
|
118
|
+
launch_services_bundle =
|
119
|
+
pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices"));
|
120
|
+
|
121
|
+
if (launch_services_bundle == NULL)
|
122
|
+
goto out;
|
123
|
+
|
124
|
+
*(void **)(&pLSGetCurrentApplicationASN) =
|
125
|
+
pCFBundleGetFunctionPointerForName(launch_services_bundle,
|
126
|
+
S("_LSGetCurrentApplicationASN"));
|
127
|
+
|
128
|
+
if (pLSGetCurrentApplicationASN == NULL)
|
129
|
+
goto out;
|
130
|
+
|
131
|
+
*(void **)(&pLSSetApplicationInformationItem) =
|
132
|
+
pCFBundleGetFunctionPointerForName(launch_services_bundle,
|
133
|
+
S("_LSSetApplicationInformationItem"));
|
134
|
+
|
135
|
+
if (pLSSetApplicationInformationItem == NULL)
|
136
|
+
goto out;
|
137
|
+
|
138
|
+
display_name_key = pCFBundleGetDataPointerForName(launch_services_bundle,
|
139
|
+
S("_kLSDisplayNameKey"));
|
140
|
+
|
141
|
+
if (display_name_key == NULL || *display_name_key == NULL)
|
142
|
+
goto out;
|
143
|
+
|
144
|
+
*(void **)(&pCFBundleGetInfoDictionary) = dlsym(core_foundation_handle,
|
145
|
+
"CFBundleGetInfoDictionary");
|
146
|
+
*(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle,
|
147
|
+
"CFBundleGetMainBundle");
|
148
|
+
if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL)
|
149
|
+
goto out;
|
150
|
+
|
151
|
+
/* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */
|
152
|
+
hi_services_bundle =
|
153
|
+
pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices"));
|
154
|
+
err = -ENOENT;
|
155
|
+
if (hi_services_bundle == NULL)
|
156
|
+
goto out;
|
157
|
+
|
158
|
+
*(void **)(&pSetApplicationIsDaemon) = pCFBundleGetFunctionPointerForName(
|
159
|
+
hi_services_bundle,
|
160
|
+
S("SetApplicationIsDaemon"));
|
161
|
+
*(void **)(&pLSApplicationCheckIn) = pCFBundleGetFunctionPointerForName(
|
162
|
+
launch_services_bundle,
|
163
|
+
S("_LSApplicationCheckIn"));
|
164
|
+
*(void **)(&pLSSetApplicationLaunchServicesServerConnectionStatus) =
|
165
|
+
pCFBundleGetFunctionPointerForName(
|
166
|
+
launch_services_bundle,
|
167
|
+
S("_LSSetApplicationLaunchServicesServerConnectionStatus"));
|
168
|
+
if (pSetApplicationIsDaemon == NULL ||
|
169
|
+
pLSApplicationCheckIn == NULL ||
|
170
|
+
pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) {
|
171
|
+
goto out;
|
172
|
+
}
|
173
|
+
|
174
|
+
if (pSetApplicationIsDaemon(1) != noErr)
|
175
|
+
goto out;
|
176
|
+
|
177
|
+
pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL);
|
178
|
+
|
179
|
+
/* Check into process manager?! */
|
180
|
+
pLSApplicationCheckIn(-2,
|
181
|
+
pCFBundleGetInfoDictionary(pCFBundleGetMainBundle()));
|
182
|
+
|
183
|
+
asn = pLSGetCurrentApplicationASN();
|
184
|
+
|
185
|
+
err = -EINVAL;
|
186
|
+
if (pLSSetApplicationInformationItem(-2, /* Magic value. */
|
187
|
+
asn,
|
188
|
+
*display_name_key,
|
189
|
+
S(title),
|
190
|
+
NULL) != noErr) {
|
191
|
+
goto out;
|
192
|
+
}
|
193
|
+
|
194
|
+
uv__pthread_setname_np(title); /* Don't care if it fails. */
|
195
|
+
err = 0;
|
196
|
+
|
197
|
+
out:
|
198
|
+
if (core_foundation_handle != NULL)
|
199
|
+
dlclose(core_foundation_handle);
|
200
|
+
|
201
|
+
if (application_services_handle != NULL)
|
202
|
+
dlclose(application_services_handle);
|
203
|
+
|
204
|
+
return err;
|
205
|
+
#endif /* !TARGET_OS_IPHONE */
|
206
|
+
}
|
@@ -0,0 +1,331 @@
|
|
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 <stdint.h>
|
26
|
+
#include <errno.h>
|
27
|
+
|
28
|
+
#include <ifaddrs.h>
|
29
|
+
#include <net/if.h>
|
30
|
+
#include <net/if_dl.h>
|
31
|
+
|
32
|
+
#include <mach/mach.h>
|
33
|
+
#include <mach/mach_time.h>
|
34
|
+
#include <mach-o/dyld.h> /* _NSGetExecutablePath */
|
35
|
+
#include <sys/resource.h>
|
36
|
+
#include <sys/sysctl.h>
|
37
|
+
#include <unistd.h> /* sysconf */
|
38
|
+
|
39
|
+
|
40
|
+
int uv__platform_loop_init(uv_loop_t* loop) {
|
41
|
+
loop->cf_state = NULL;
|
42
|
+
|
43
|
+
if (uv__kqueue_init(loop))
|
44
|
+
return -errno;
|
45
|
+
|
46
|
+
return 0;
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
void uv__platform_loop_delete(uv_loop_t* loop) {
|
51
|
+
uv__fsevents_loop_delete(loop);
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
uint64_t uv__hrtime(uv_clocktype_t type) {
|
56
|
+
static mach_timebase_info_data_t info;
|
57
|
+
|
58
|
+
if ((ACCESS_ONCE(uint32_t, info.numer) == 0 ||
|
59
|
+
ACCESS_ONCE(uint32_t, info.denom) == 0) &&
|
60
|
+
mach_timebase_info(&info) != KERN_SUCCESS)
|
61
|
+
abort();
|
62
|
+
|
63
|
+
return mach_absolute_time() * info.numer / info.denom;
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
int uv_exepath(char* buffer, size_t* size) {
|
68
|
+
/* realpath(exepath) may be > PATH_MAX so double it to be on the safe side. */
|
69
|
+
char abspath[PATH_MAX * 2 + 1];
|
70
|
+
char exepath[PATH_MAX + 1];
|
71
|
+
uint32_t exepath_size;
|
72
|
+
size_t abspath_size;
|
73
|
+
|
74
|
+
if (buffer == NULL || size == NULL || *size == 0)
|
75
|
+
return -EINVAL;
|
76
|
+
|
77
|
+
exepath_size = sizeof(exepath);
|
78
|
+
if (_NSGetExecutablePath(exepath, &exepath_size))
|
79
|
+
return -EIO;
|
80
|
+
|
81
|
+
if (realpath(exepath, abspath) != abspath)
|
82
|
+
return -errno;
|
83
|
+
|
84
|
+
abspath_size = strlen(abspath);
|
85
|
+
if (abspath_size == 0)
|
86
|
+
return -EIO;
|
87
|
+
|
88
|
+
*size -= 1;
|
89
|
+
if (*size > abspath_size)
|
90
|
+
*size = abspath_size;
|
91
|
+
|
92
|
+
memcpy(buffer, abspath, *size);
|
93
|
+
buffer[*size] = '\0';
|
94
|
+
|
95
|
+
return 0;
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
uint64_t uv_get_free_memory(void) {
|
100
|
+
vm_statistics_data_t info;
|
101
|
+
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t);
|
102
|
+
|
103
|
+
if (host_statistics(mach_host_self(), HOST_VM_INFO,
|
104
|
+
(host_info_t)&info, &count) != KERN_SUCCESS) {
|
105
|
+
return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
|
106
|
+
}
|
107
|
+
|
108
|
+
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
uint64_t uv_get_total_memory(void) {
|
113
|
+
uint64_t info;
|
114
|
+
int which[] = {CTL_HW, HW_MEMSIZE};
|
115
|
+
size_t size = sizeof(info);
|
116
|
+
|
117
|
+
if (sysctl(which, 2, &info, &size, NULL, 0))
|
118
|
+
return -errno;
|
119
|
+
|
120
|
+
return (uint64_t) info;
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
void uv_loadavg(double avg[3]) {
|
125
|
+
struct loadavg info;
|
126
|
+
size_t size = sizeof(info);
|
127
|
+
int which[] = {CTL_VM, VM_LOADAVG};
|
128
|
+
|
129
|
+
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) return;
|
130
|
+
|
131
|
+
avg[0] = (double) info.ldavg[0] / info.fscale;
|
132
|
+
avg[1] = (double) info.ldavg[1] / info.fscale;
|
133
|
+
avg[2] = (double) info.ldavg[2] / info.fscale;
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
int uv_resident_set_memory(size_t* rss) {
|
138
|
+
mach_msg_type_number_t count;
|
139
|
+
task_basic_info_data_t info;
|
140
|
+
kern_return_t err;
|
141
|
+
|
142
|
+
count = TASK_BASIC_INFO_COUNT;
|
143
|
+
err = task_info(mach_task_self(),
|
144
|
+
TASK_BASIC_INFO,
|
145
|
+
(task_info_t) &info,
|
146
|
+
&count);
|
147
|
+
(void) &err;
|
148
|
+
/* task_info(TASK_BASIC_INFO) cannot really fail. Anything other than
|
149
|
+
* KERN_SUCCESS implies a libuv bug.
|
150
|
+
*/
|
151
|
+
assert(err == KERN_SUCCESS);
|
152
|
+
*rss = info.resident_size;
|
153
|
+
|
154
|
+
return 0;
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
int uv_uptime(double* uptime) {
|
159
|
+
time_t now;
|
160
|
+
struct timeval info;
|
161
|
+
size_t size = sizeof(info);
|
162
|
+
static int which[] = {CTL_KERN, KERN_BOOTTIME};
|
163
|
+
|
164
|
+
if (sysctl(which, 2, &info, &size, NULL, 0))
|
165
|
+
return -errno;
|
166
|
+
|
167
|
+
now = time(NULL);
|
168
|
+
*uptime = now - info.tv_sec;
|
169
|
+
|
170
|
+
return 0;
|
171
|
+
}
|
172
|
+
|
173
|
+
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
174
|
+
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
|
175
|
+
multiplier = ((uint64_t)1000L / ticks);
|
176
|
+
char model[512];
|
177
|
+
uint64_t cpuspeed;
|
178
|
+
size_t size;
|
179
|
+
unsigned int i;
|
180
|
+
natural_t numcpus;
|
181
|
+
mach_msg_type_number_t msg_type;
|
182
|
+
processor_cpu_load_info_data_t *info;
|
183
|
+
uv_cpu_info_t* cpu_info;
|
184
|
+
|
185
|
+
size = sizeof(model);
|
186
|
+
if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) &&
|
187
|
+
sysctlbyname("hw.model", &model, &size, NULL, 0)) {
|
188
|
+
return -errno;
|
189
|
+
}
|
190
|
+
|
191
|
+
size = sizeof(cpuspeed);
|
192
|
+
if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0))
|
193
|
+
return -errno;
|
194
|
+
|
195
|
+
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
|
196
|
+
(processor_info_array_t*)&info,
|
197
|
+
&msg_type) != KERN_SUCCESS) {
|
198
|
+
return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
|
199
|
+
}
|
200
|
+
|
201
|
+
*cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
|
202
|
+
if (!(*cpu_infos))
|
203
|
+
return -ENOMEM; /* FIXME(bnoordhuis) Deallocate info? */
|
204
|
+
|
205
|
+
*count = numcpus;
|
206
|
+
|
207
|
+
for (i = 0; i < numcpus; i++) {
|
208
|
+
cpu_info = &(*cpu_infos)[i];
|
209
|
+
|
210
|
+
cpu_info->cpu_times.user = (uint64_t)(info[i].cpu_ticks[0]) * multiplier;
|
211
|
+
cpu_info->cpu_times.nice = (uint64_t)(info[i].cpu_ticks[3]) * multiplier;
|
212
|
+
cpu_info->cpu_times.sys = (uint64_t)(info[i].cpu_ticks[1]) * multiplier;
|
213
|
+
cpu_info->cpu_times.idle = (uint64_t)(info[i].cpu_ticks[2]) * multiplier;
|
214
|
+
cpu_info->cpu_times.irq = 0;
|
215
|
+
|
216
|
+
cpu_info->model = strdup(model);
|
217
|
+
cpu_info->speed = cpuspeed/1000000;
|
218
|
+
}
|
219
|
+
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
|
220
|
+
|
221
|
+
return 0;
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
|
226
|
+
int i;
|
227
|
+
|
228
|
+
for (i = 0; i < count; i++) {
|
229
|
+
free(cpu_infos[i].model);
|
230
|
+
}
|
231
|
+
|
232
|
+
free(cpu_infos);
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
|
237
|
+
struct ifaddrs *addrs, *ent;
|
238
|
+
uv_interface_address_t* address;
|
239
|
+
int i;
|
240
|
+
struct sockaddr_dl *sa_addr;
|
241
|
+
|
242
|
+
if (getifaddrs(&addrs))
|
243
|
+
return -errno;
|
244
|
+
|
245
|
+
*count = 0;
|
246
|
+
|
247
|
+
/* Count the number of interfaces */
|
248
|
+
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
|
249
|
+
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
|
250
|
+
(ent->ifa_addr == NULL) ||
|
251
|
+
(ent->ifa_addr->sa_family == AF_LINK)) {
|
252
|
+
continue;
|
253
|
+
}
|
254
|
+
|
255
|
+
(*count)++;
|
256
|
+
}
|
257
|
+
|
258
|
+
*addresses = malloc(*count * sizeof(**addresses));
|
259
|
+
if (!(*addresses))
|
260
|
+
return -ENOMEM;
|
261
|
+
|
262
|
+
address = *addresses;
|
263
|
+
|
264
|
+
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
|
265
|
+
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
|
266
|
+
continue;
|
267
|
+
|
268
|
+
if (ent->ifa_addr == NULL)
|
269
|
+
continue;
|
270
|
+
|
271
|
+
/*
|
272
|
+
* On Mac OS X getifaddrs returns information related to Mac Addresses for
|
273
|
+
* various devices, such as firewire, etc. These are not relevant here.
|
274
|
+
*/
|
275
|
+
if (ent->ifa_addr->sa_family == AF_LINK)
|
276
|
+
continue;
|
277
|
+
|
278
|
+
address->name = strdup(ent->ifa_name);
|
279
|
+
|
280
|
+
if (ent->ifa_addr->sa_family == AF_INET6) {
|
281
|
+
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
|
282
|
+
} else {
|
283
|
+
address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr);
|
284
|
+
}
|
285
|
+
|
286
|
+
if (ent->ifa_netmask->sa_family == AF_INET6) {
|
287
|
+
address->netmask.netmask6 = *((struct sockaddr_in6*) ent->ifa_netmask);
|
288
|
+
} else {
|
289
|
+
address->netmask.netmask4 = *((struct sockaddr_in*) ent->ifa_netmask);
|
290
|
+
}
|
291
|
+
|
292
|
+
address->is_internal = !!(ent->ifa_flags & IFF_LOOPBACK);
|
293
|
+
|
294
|
+
address++;
|
295
|
+
}
|
296
|
+
|
297
|
+
/* Fill in physical addresses for each interface */
|
298
|
+
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
|
299
|
+
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
|
300
|
+
(ent->ifa_addr == NULL) ||
|
301
|
+
(ent->ifa_addr->sa_family != AF_LINK)) {
|
302
|
+
continue;
|
303
|
+
}
|
304
|
+
|
305
|
+
address = *addresses;
|
306
|
+
|
307
|
+
for (i = 0; i < (*count); i++) {
|
308
|
+
if (strcmp(address->name, ent->ifa_name) == 0) {
|
309
|
+
sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
|
310
|
+
memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
|
311
|
+
}
|
312
|
+
address++;
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
freeifaddrs(addrs);
|
317
|
+
|
318
|
+
return 0;
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
void uv_free_interface_addresses(uv_interface_address_t* addresses,
|
323
|
+
int count) {
|
324
|
+
int i;
|
325
|
+
|
326
|
+
for (i = 0; i < count; i++) {
|
327
|
+
free(addresses[i].name);
|
328
|
+
}
|
329
|
+
|
330
|
+
free(addresses);
|
331
|
+
}
|