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,83 @@
|
|
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 <dlfcn.h>
|
26
|
+
#include <errno.h>
|
27
|
+
#include <string.h>
|
28
|
+
#include <locale.h>
|
29
|
+
|
30
|
+
static int uv__dlerror(uv_lib_t* lib);
|
31
|
+
|
32
|
+
|
33
|
+
int uv_dlopen(const char* filename, uv_lib_t* lib) {
|
34
|
+
dlerror(); /* Reset error status. */
|
35
|
+
lib->errmsg = NULL;
|
36
|
+
lib->handle = dlopen(filename, RTLD_LAZY);
|
37
|
+
return lib->handle ? 0 : uv__dlerror(lib);
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
void uv_dlclose(uv_lib_t* lib) {
|
42
|
+
if (lib->errmsg) {
|
43
|
+
free(lib->errmsg);
|
44
|
+
lib->errmsg = NULL;
|
45
|
+
}
|
46
|
+
|
47
|
+
if (lib->handle) {
|
48
|
+
/* Ignore errors. No good way to signal them without leaking memory. */
|
49
|
+
dlclose(lib->handle);
|
50
|
+
lib->handle = NULL;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr) {
|
56
|
+
dlerror(); /* Reset error status. */
|
57
|
+
*ptr = dlsym(lib->handle, name);
|
58
|
+
return uv__dlerror(lib);
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
const char* uv_dlerror(const uv_lib_t* lib) {
|
63
|
+
return lib->errmsg ? lib->errmsg : "no error";
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
static int uv__dlerror(uv_lib_t* lib) {
|
68
|
+
const char* errmsg;
|
69
|
+
|
70
|
+
if (lib->errmsg)
|
71
|
+
free(lib->errmsg);
|
72
|
+
|
73
|
+
errmsg = dlerror();
|
74
|
+
|
75
|
+
if (errmsg) {
|
76
|
+
lib->errmsg = strdup(errmsg);
|
77
|
+
return -1;
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
lib->errmsg = NULL;
|
81
|
+
return 0;
|
82
|
+
}
|
83
|
+
}
|
@@ -0,0 +1,435 @@
|
|
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 <ifaddrs.h>
|
29
|
+
#include <net/if.h>
|
30
|
+
#include <net/if_dl.h>
|
31
|
+
|
32
|
+
#include <kvm.h>
|
33
|
+
#include <paths.h>
|
34
|
+
#include <sys/user.h>
|
35
|
+
#include <sys/types.h>
|
36
|
+
#include <sys/resource.h>
|
37
|
+
#include <sys/sysctl.h>
|
38
|
+
#include <vm/vm_param.h> /* VM_LOADAVG */
|
39
|
+
#include <time.h>
|
40
|
+
#include <stdlib.h>
|
41
|
+
#include <unistd.h> /* sysconf */
|
42
|
+
#include <fcntl.h>
|
43
|
+
|
44
|
+
#undef NANOSEC
|
45
|
+
#define NANOSEC ((uint64_t) 1e9)
|
46
|
+
|
47
|
+
#ifndef CPUSTATES
|
48
|
+
# define CPUSTATES 5U
|
49
|
+
#endif
|
50
|
+
#ifndef CP_USER
|
51
|
+
# define CP_USER 0
|
52
|
+
# define CP_NICE 1
|
53
|
+
# define CP_SYS 2
|
54
|
+
# define CP_IDLE 3
|
55
|
+
# define CP_INTR 4
|
56
|
+
#endif
|
57
|
+
|
58
|
+
static char *process_title;
|
59
|
+
|
60
|
+
|
61
|
+
int uv__platform_loop_init(uv_loop_t* loop) {
|
62
|
+
return uv__kqueue_init(loop);
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
void uv__platform_loop_delete(uv_loop_t* loop) {
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
uint64_t uv__hrtime(uv_clocktype_t type) {
|
71
|
+
struct timespec ts;
|
72
|
+
clock_gettime(CLOCK_MONOTONIC, &ts);
|
73
|
+
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
int uv_exepath(char* buffer, size_t* size) {
|
78
|
+
char abspath[PATH_MAX * 2 + 1];
|
79
|
+
int mib[4];
|
80
|
+
size_t abspath_size;
|
81
|
+
|
82
|
+
if (buffer == NULL || size == NULL || *size == 0)
|
83
|
+
return -EINVAL;
|
84
|
+
|
85
|
+
#ifdef __DragonFly__
|
86
|
+
mib[0] = CTL_KERN;
|
87
|
+
mib[1] = KERN_PROC;
|
88
|
+
mib[2] = KERN_PROC_ARGS;
|
89
|
+
mib[3] = getpid();
|
90
|
+
#else
|
91
|
+
mib[0] = CTL_KERN;
|
92
|
+
mib[1] = KERN_PROC;
|
93
|
+
mib[2] = KERN_PROC_PATHNAME;
|
94
|
+
mib[3] = -1;
|
95
|
+
#endif
|
96
|
+
|
97
|
+
abspath_size = sizeof abspath;;
|
98
|
+
if (sysctl(mib, 4, abspath, &abspath_size, NULL, 0))
|
99
|
+
return -errno;
|
100
|
+
|
101
|
+
assert(abspath_size > 0);
|
102
|
+
abspath_size -= 1;
|
103
|
+
*size -= 1;
|
104
|
+
|
105
|
+
if (*size > abspath_size)
|
106
|
+
*size = abspath_size;
|
107
|
+
|
108
|
+
memcpy(buffer, abspath, *size);
|
109
|
+
buffer[*size] = '\0';
|
110
|
+
|
111
|
+
return 0;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
uint64_t uv_get_free_memory(void) {
|
116
|
+
int freecount;
|
117
|
+
size_t size = sizeof(freecount);
|
118
|
+
|
119
|
+
if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0))
|
120
|
+
return -errno;
|
121
|
+
|
122
|
+
return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
|
123
|
+
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
uint64_t uv_get_total_memory(void) {
|
128
|
+
unsigned long info;
|
129
|
+
int which[] = {CTL_HW, HW_PHYSMEM};
|
130
|
+
|
131
|
+
size_t size = sizeof(info);
|
132
|
+
|
133
|
+
if (sysctl(which, 2, &info, &size, NULL, 0))
|
134
|
+
return -errno;
|
135
|
+
|
136
|
+
return (uint64_t) info;
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
void uv_loadavg(double avg[3]) {
|
141
|
+
struct loadavg info;
|
142
|
+
size_t size = sizeof(info);
|
143
|
+
int which[] = {CTL_VM, VM_LOADAVG};
|
144
|
+
|
145
|
+
if (sysctl(which, 2, &info, &size, NULL, 0) < 0) return;
|
146
|
+
|
147
|
+
avg[0] = (double) info.ldavg[0] / info.fscale;
|
148
|
+
avg[1] = (double) info.ldavg[1] / info.fscale;
|
149
|
+
avg[2] = (double) info.ldavg[2] / info.fscale;
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
char** uv_setup_args(int argc, char** argv) {
|
154
|
+
process_title = argc ? strdup(argv[0]) : NULL;
|
155
|
+
return argv;
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
int uv_set_process_title(const char* title) {
|
160
|
+
int oid[4];
|
161
|
+
|
162
|
+
if (process_title) free(process_title);
|
163
|
+
process_title = strdup(title);
|
164
|
+
|
165
|
+
oid[0] = CTL_KERN;
|
166
|
+
oid[1] = KERN_PROC;
|
167
|
+
oid[2] = KERN_PROC_ARGS;
|
168
|
+
oid[3] = getpid();
|
169
|
+
|
170
|
+
sysctl(oid,
|
171
|
+
ARRAY_SIZE(oid),
|
172
|
+
NULL,
|
173
|
+
NULL,
|
174
|
+
process_title,
|
175
|
+
strlen(process_title) + 1);
|
176
|
+
|
177
|
+
return 0;
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
int uv_get_process_title(char* buffer, size_t size) {
|
182
|
+
if (process_title) {
|
183
|
+
strncpy(buffer, process_title, size);
|
184
|
+
} else {
|
185
|
+
if (size > 0) {
|
186
|
+
buffer[0] = '\0';
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
return 0;
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
int uv_resident_set_memory(size_t* rss) {
|
195
|
+
kvm_t *kd = NULL;
|
196
|
+
struct kinfo_proc *kinfo = NULL;
|
197
|
+
pid_t pid;
|
198
|
+
int nprocs;
|
199
|
+
size_t page_size = getpagesize();
|
200
|
+
|
201
|
+
pid = getpid();
|
202
|
+
|
203
|
+
kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
|
204
|
+
if (kd == NULL) goto error;
|
205
|
+
|
206
|
+
kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs);
|
207
|
+
if (kinfo == NULL) goto error;
|
208
|
+
|
209
|
+
#ifdef __DragonFly__
|
210
|
+
*rss = kinfo->kp_vm_rssize * page_size;
|
211
|
+
#else
|
212
|
+
*rss = kinfo->ki_rssize * page_size;
|
213
|
+
#endif
|
214
|
+
|
215
|
+
kvm_close(kd);
|
216
|
+
|
217
|
+
return 0;
|
218
|
+
|
219
|
+
error:
|
220
|
+
if (kd) kvm_close(kd);
|
221
|
+
return -EPERM;
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
int uv_uptime(double* uptime) {
|
226
|
+
time_t now;
|
227
|
+
struct timeval info;
|
228
|
+
size_t size = sizeof(info);
|
229
|
+
static int which[] = {CTL_KERN, KERN_BOOTTIME};
|
230
|
+
|
231
|
+
if (sysctl(which, 2, &info, &size, NULL, 0))
|
232
|
+
return -errno;
|
233
|
+
|
234
|
+
now = time(NULL);
|
235
|
+
|
236
|
+
*uptime = (double)(now - info.tv_sec);
|
237
|
+
return 0;
|
238
|
+
}
|
239
|
+
|
240
|
+
|
241
|
+
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
242
|
+
unsigned int ticks = (unsigned int)sysconf(_SC_CLK_TCK),
|
243
|
+
multiplier = ((uint64_t)1000L / ticks), cpuspeed, maxcpus,
|
244
|
+
cur = 0;
|
245
|
+
uv_cpu_info_t* cpu_info;
|
246
|
+
const char* maxcpus_key;
|
247
|
+
const char* cptimes_key;
|
248
|
+
char model[512];
|
249
|
+
long* cp_times;
|
250
|
+
int numcpus;
|
251
|
+
size_t size;
|
252
|
+
int i;
|
253
|
+
|
254
|
+
#if defined(__DragonFly__)
|
255
|
+
/* This is not quite correct but DragonFlyBSD doesn't seem to have anything
|
256
|
+
* comparable to kern.smp.maxcpus or kern.cp_times (kern.cp_time is a total,
|
257
|
+
* not per CPU). At least this stops uv_cpu_info() from failing completely.
|
258
|
+
*/
|
259
|
+
maxcpus_key = "hw.ncpu";
|
260
|
+
cptimes_key = "kern.cp_time";
|
261
|
+
#else
|
262
|
+
maxcpus_key = "kern.smp.maxcpus";
|
263
|
+
cptimes_key = "kern.cp_times";
|
264
|
+
#endif
|
265
|
+
|
266
|
+
size = sizeof(model);
|
267
|
+
if (sysctlbyname("hw.model", &model, &size, NULL, 0))
|
268
|
+
return -errno;
|
269
|
+
|
270
|
+
size = sizeof(numcpus);
|
271
|
+
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
|
272
|
+
return -errno;
|
273
|
+
|
274
|
+
*cpu_infos = malloc(numcpus * sizeof(**cpu_infos));
|
275
|
+
if (!(*cpu_infos))
|
276
|
+
return -ENOMEM;
|
277
|
+
|
278
|
+
*count = numcpus;
|
279
|
+
|
280
|
+
size = sizeof(cpuspeed);
|
281
|
+
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {
|
282
|
+
SAVE_ERRNO(free(*cpu_infos));
|
283
|
+
return -errno;
|
284
|
+
}
|
285
|
+
|
286
|
+
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of
|
287
|
+
* ncpu.
|
288
|
+
*/
|
289
|
+
size = sizeof(maxcpus);
|
290
|
+
if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) {
|
291
|
+
SAVE_ERRNO(free(*cpu_infos));
|
292
|
+
return -errno;
|
293
|
+
}
|
294
|
+
|
295
|
+
size = maxcpus * CPUSTATES * sizeof(long);
|
296
|
+
|
297
|
+
cp_times = malloc(size);
|
298
|
+
if (cp_times == NULL) {
|
299
|
+
free(*cpu_infos);
|
300
|
+
return -ENOMEM;
|
301
|
+
}
|
302
|
+
|
303
|
+
if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) {
|
304
|
+
SAVE_ERRNO(free(cp_times));
|
305
|
+
SAVE_ERRNO(free(*cpu_infos));
|
306
|
+
return -errno;
|
307
|
+
}
|
308
|
+
|
309
|
+
for (i = 0; i < numcpus; i++) {
|
310
|
+
cpu_info = &(*cpu_infos)[i];
|
311
|
+
|
312
|
+
cpu_info->cpu_times.user = (uint64_t)(cp_times[CP_USER+cur]) * multiplier;
|
313
|
+
cpu_info->cpu_times.nice = (uint64_t)(cp_times[CP_NICE+cur]) * multiplier;
|
314
|
+
cpu_info->cpu_times.sys = (uint64_t)(cp_times[CP_SYS+cur]) * multiplier;
|
315
|
+
cpu_info->cpu_times.idle = (uint64_t)(cp_times[CP_IDLE+cur]) * multiplier;
|
316
|
+
cpu_info->cpu_times.irq = (uint64_t)(cp_times[CP_INTR+cur]) * multiplier;
|
317
|
+
|
318
|
+
cpu_info->model = strdup(model);
|
319
|
+
cpu_info->speed = cpuspeed;
|
320
|
+
|
321
|
+
cur+=CPUSTATES;
|
322
|
+
}
|
323
|
+
|
324
|
+
free(cp_times);
|
325
|
+
return 0;
|
326
|
+
}
|
327
|
+
|
328
|
+
|
329
|
+
void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
|
330
|
+
int i;
|
331
|
+
|
332
|
+
for (i = 0; i < count; i++) {
|
333
|
+
free(cpu_infos[i].model);
|
334
|
+
}
|
335
|
+
|
336
|
+
free(cpu_infos);
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
|
341
|
+
struct ifaddrs *addrs, *ent;
|
342
|
+
uv_interface_address_t* address;
|
343
|
+
int i;
|
344
|
+
struct sockaddr_dl *sa_addr;
|
345
|
+
|
346
|
+
if (getifaddrs(&addrs))
|
347
|
+
return -errno;
|
348
|
+
|
349
|
+
*count = 0;
|
350
|
+
|
351
|
+
/* Count the number of interfaces */
|
352
|
+
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
|
353
|
+
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
|
354
|
+
(ent->ifa_addr == NULL) ||
|
355
|
+
(ent->ifa_addr->sa_family == AF_LINK)) {
|
356
|
+
continue;
|
357
|
+
}
|
358
|
+
|
359
|
+
(*count)++;
|
360
|
+
}
|
361
|
+
|
362
|
+
*addresses = malloc(*count * sizeof(**addresses));
|
363
|
+
if (!(*addresses))
|
364
|
+
return -ENOMEM;
|
365
|
+
|
366
|
+
address = *addresses;
|
367
|
+
|
368
|
+
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
|
369
|
+
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
|
370
|
+
continue;
|
371
|
+
|
372
|
+
if (ent->ifa_addr == NULL)
|
373
|
+
continue;
|
374
|
+
|
375
|
+
/*
|
376
|
+
* On FreeBSD getifaddrs returns information related to the raw underlying
|
377
|
+
* devices. We're not interested in this information yet.
|
378
|
+
*/
|
379
|
+
if (ent->ifa_addr->sa_family == AF_LINK)
|
380
|
+
continue;
|
381
|
+
|
382
|
+
address->name = strdup(ent->ifa_name);
|
383
|
+
|
384
|
+
if (ent->ifa_addr->sa_family == AF_INET6) {
|
385
|
+
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
|
386
|
+
} else {
|
387
|
+
address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr);
|
388
|
+
}
|
389
|
+
|
390
|
+
if (ent->ifa_netmask->sa_family == AF_INET6) {
|
391
|
+
address->netmask.netmask6 = *((struct sockaddr_in6*) ent->ifa_netmask);
|
392
|
+
} else {
|
393
|
+
address->netmask.netmask4 = *((struct sockaddr_in*) ent->ifa_netmask);
|
394
|
+
}
|
395
|
+
|
396
|
+
address->is_internal = !!(ent->ifa_flags & IFF_LOOPBACK);
|
397
|
+
|
398
|
+
address++;
|
399
|
+
}
|
400
|
+
|
401
|
+
/* Fill in physical addresses for each interface */
|
402
|
+
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
|
403
|
+
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)) ||
|
404
|
+
(ent->ifa_addr == NULL) ||
|
405
|
+
(ent->ifa_addr->sa_family != AF_LINK)) {
|
406
|
+
continue;
|
407
|
+
}
|
408
|
+
|
409
|
+
address = *addresses;
|
410
|
+
|
411
|
+
for (i = 0; i < (*count); i++) {
|
412
|
+
if (strcmp(address->name, ent->ifa_name) == 0) {
|
413
|
+
sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
|
414
|
+
memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
|
415
|
+
}
|
416
|
+
address++;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
freeifaddrs(addrs);
|
421
|
+
|
422
|
+
return 0;
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
void uv_free_interface_addresses(uv_interface_address_t* addresses,
|
427
|
+
int count) {
|
428
|
+
int i;
|
429
|
+
|
430
|
+
for (i = 0; i < count; i++) {
|
431
|
+
free(addresses[i].name);
|
432
|
+
}
|
433
|
+
|
434
|
+
free(addresses);
|
435
|
+
}
|