Line 0
Link Here
|
|
|
1 |
--- ./platform/python/psutil/psutil/_psutil_bsd.c |
2 |
+++ ./platform/python/psutil/psutil/_psutil_bsd.c |
3 |
@@ -12,6 +12,7 @@ |
4 |
#include <errno.h> |
5 |
#include <stdlib.h> |
6 |
#include <stdio.h> |
7 |
+#include <err.h> |
8 |
#include <signal.h> |
9 |
#include <fcntl.h> |
10 |
#include <paths.h> |
11 |
@@ -38,7 +39,7 @@ |
12 |
#include <netinet/tcp_fsm.h> // for TCP connection states |
13 |
#include <arpa/inet.h> // for inet_ntop() |
14 |
|
15 |
-#if __FreeBSD_version < 900000 |
16 |
+#if !defined(__FreeBSD_version) |
17 |
#include <utmp.h> // system users |
18 |
#else |
19 |
#include <utmpx.h> |
20 |
@@ -601,11 +602,7 @@ psutil_virtual_mem(PyObject *self, PyObject *args) |
21 |
struct vmtotal vm; |
22 |
int mib[] = {CTL_VM, VM_METER}; |
23 |
long pagesize = getpagesize(); |
24 |
-#if __FreeBSD_version > 702101 |
25 |
long buffers; |
26 |
-#else |
27 |
- int buffers; |
28 |
-#endif |
29 |
size_t buffers_size = sizeof(buffers); |
30 |
|
31 |
if (sysctlbyname("vm.stats.vm.v_page_count", &total, &size, NULL, 0)) |
32 |
@@ -724,13 +721,13 @@ psutil_cpu_times(PyObject *self, PyObject *args) |
33 |
|
34 |
/* |
35 |
* XXX |
36 |
- * These functions are available on FreeBSD 8 only. |
37 |
+ * These functions were seen available on FreeBSD only. |
38 |
* In the upper python layer we do various tricks to avoid crashing |
39 |
* and/or to provide alternatives where possible. |
40 |
*/ |
41 |
|
42 |
|
43 |
-#if defined(__FreeBSD_version) && __FreeBSD_version >= 800000 |
44 |
+#if defined(__FreeBSD_version) |
45 |
/* |
46 |
* Return files opened by process as a list of (path, fd) tuples. |
47 |
* TODO: this is broken as it may report empty paths. 'procstat' |
48 |
@@ -943,11 +940,19 @@ psutil_sockaddr_matches(int family, int port, void *pcb_addr, |
49 |
psutil_sockaddr_addrlen(family)) == 0); |
50 |
} |
51 |
|
52 |
+#if __FreeBSD_version >= 1200026 |
53 |
+static struct xtcpcb * |
54 |
+psutil_search_tcplist(char *buf, struct kinfo_file *kif) |
55 |
+{ |
56 |
+ struct xtcpcb *tp; |
57 |
+ struct xinpcb *inp; |
58 |
+#else |
59 |
static struct tcpcb * |
60 |
psutil_search_tcplist(char *buf, struct kinfo_file *kif) |
61 |
{ |
62 |
struct tcpcb *tp; |
63 |
struct inpcb *inp; |
64 |
+#endif |
65 |
struct xinpgen *xig, *oxig; |
66 |
struct xsocket *so; |
67 |
|
68 |
@@ -955,9 +960,15 @@ psutil_search_tcplist(char *buf, struct kinfo_file *kif) |
69 |
for (xig = (struct xinpgen *)((char *)xig + xig->xig_len); |
70 |
xig->xig_len > sizeof(struct xinpgen); |
71 |
xig = (struct xinpgen *)((char *)xig + xig->xig_len)) { |
72 |
+#if __FreeBSD_version >= 1200026 |
73 |
+ tp = (struct xtcpcb *)xig; |
74 |
+ inp = &tp->xt_inp; |
75 |
+ so = &inp->xi_socket; |
76 |
+#else |
77 |
tp = &((struct xtcpcb *)xig)->xt_tp; |
78 |
inp = &((struct xtcpcb *)xig)->xt_inp; |
79 |
so = &((struct xtcpcb *)xig)->xt_socket; |
80 |
+#endif |
81 |
|
82 |
if (so->so_type != kif->kf_sock_type || |
83 |
so->xso_family != kif->kf_sock_domain || |
84 |
@@ -967,20 +978,36 @@ psutil_search_tcplist(char *buf, struct kinfo_file *kif) |
85 |
if (kif->kf_sock_domain == AF_INET) { |
86 |
if (!psutil_sockaddr_matches( |
87 |
AF_INET, inp->inp_lport, &inp->inp_laddr, |
88 |
+#if __FreeBSD_version < 1200031 |
89 |
&kif->kf_sa_local)) |
90 |
+#else |
91 |
+ &kif->kf_un.kf_sock.kf_sa_local)) |
92 |
+#endif |
93 |
continue; |
94 |
if (!psutil_sockaddr_matches( |
95 |
AF_INET, inp->inp_fport, &inp->inp_faddr, |
96 |
+#if __FreeBSD_version < 1200031 |
97 |
&kif->kf_sa_peer)) |
98 |
+#else |
99 |
+ &kif->kf_un.kf_sock.kf_sa_peer)) |
100 |
+#endif |
101 |
continue; |
102 |
} else { |
103 |
if (!psutil_sockaddr_matches( |
104 |
AF_INET6, inp->inp_lport, &inp->in6p_laddr, |
105 |
+#if __FreeBSD_version < 1200031 |
106 |
&kif->kf_sa_local)) |
107 |
+#else |
108 |
+ &kif->kf_un.kf_sock.kf_sa_local)) |
109 |
+#endif |
110 |
continue; |
111 |
if (!psutil_sockaddr_matches( |
112 |
AF_INET6, inp->inp_fport, &inp->in6p_faddr, |
113 |
+#if __FreeBSD_version < 1200031 |
114 |
&kif->kf_sa_peer)) |
115 |
+#else |
116 |
+ &kif->kf_un.kf_sock.kf_sa_peer)) |
117 |
+#endif |
118 |
continue; |
119 |
} |
120 |
|
121 |
@@ -1005,7 +1032,11 @@ psutil_proc_connections(PyObject *self, PyObject *args) |
122 |
struct kinfo_file *freep = NULL; |
123 |
struct kinfo_file *kif; |
124 |
char *tcplist = NULL; |
125 |
+#if __FreeBSD_version >= 1200026 |
126 |
+ struct xtcpcb *tcp; |
127 |
+#else |
128 |
struct tcpcb *tcp; |
129 |
+#endif |
130 |
|
131 |
PyObject *retList = PyList_New(0); |
132 |
PyObject *tuple = NULL; |
133 |
@@ -1074,19 +1105,35 @@ psutil_proc_connections(PyObject *self, PyObject *args) |
134 |
inet_ntop( |
135 |
kif->kf_sock_domain, |
136 |
psutil_sockaddr_addr(kif->kf_sock_domain, |
137 |
+#if __FreeBSD_version < 1200031 |
138 |
&kif->kf_sa_local), |
139 |
+#else |
140 |
+ &kif->kf_un.kf_sock.kf_sa_local), |
141 |
+#endif |
142 |
lip, |
143 |
sizeof(lip)); |
144 |
inet_ntop( |
145 |
kif->kf_sock_domain, |
146 |
psutil_sockaddr_addr(kif->kf_sock_domain, |
147 |
+#if __FreeBSD_version < 1200031 |
148 |
&kif->kf_sa_peer), |
149 |
+#else |
150 |
+ &kif->kf_un.kf_sock.kf_sa_peer), |
151 |
+#endif |
152 |
rip, |
153 |
sizeof(rip)); |
154 |
lport = htons(psutil_sockaddr_port(kif->kf_sock_domain, |
155 |
+#if __FreeBSD_version < 1200031 |
156 |
&kif->kf_sa_local)); |
157 |
+#else |
158 |
+ &kif->kf_un.kf_sock.kf_sa_local)); |
159 |
+#endif |
160 |
rport = htons(psutil_sockaddr_port(kif->kf_sock_domain, |
161 |
+#if __FreeBSD_version < 1200031 |
162 |
&kif->kf_sa_peer)); |
163 |
+#else |
164 |
+ &kif->kf_un.kf_sock.kf_sa_peer)); |
165 |
+#endif |
166 |
|
167 |
// construct python tuple/list |
168 |
laddr = Py_BuildValue("(si)", lip, lport); |
169 |
@@ -1115,7 +1162,11 @@ psutil_proc_connections(PyObject *self, PyObject *args) |
170 |
else if (kif->kf_sock_domain == AF_UNIX) { |
171 |
struct sockaddr_un *sun; |
172 |
|
173 |
+#if __FreeBSD_version < 1200031 |
174 |
sun = (struct sockaddr_un *)&kif->kf_sa_local; |
175 |
+#else |
176 |
+ sun = (struct sockaddr_un *)&kif->kf_un.kf_sock.kf_sa_local; |
177 |
+#endif |
178 |
snprintf( |
179 |
path, sizeof(path), "%.*s", |
180 |
(int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))), |
181 |
@@ -1626,7 +1677,7 @@ psutil_users(PyObject *self, PyObject *args) |
182 |
if (ret_list == NULL) |
183 |
return NULL; |
184 |
|
185 |
-#if __FreeBSD_version < 900000 |
186 |
+#if !defined(__FreeBSD_version) |
187 |
struct utmp ut; |
188 |
FILE *fp; |
189 |
|
190 |
@@ -1754,7 +1805,11 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) |
191 |
struct xinpgen *xig, *exig; |
192 |
struct xinpcb *xip; |
193 |
struct xtcpcb *xtp; |
194 |
+#if __FreeBSD_version >= 1200026 |
195 |
+ struct xinpcb *inp; |
196 |
+#else |
197 |
struct inpcb *inp; |
198 |
+#endif |
199 |
struct xsocket *so; |
200 |
const char *varname = NULL; |
201 |
size_t len, bufsize; |
202 |
@@ -1820,8 +1875,13 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) |
203 |
goto error; |
204 |
} |
205 |
inp = &xtp->xt_inp; |
206 |
+#if __FreeBSD_version >= 1200026 |
207 |
+ so = &inp->xi_socket; |
208 |
+ status = xtp->t_state; |
209 |
+#else |
210 |
so = &xtp->xt_socket; |
211 |
status = xtp->xt_tp.t_state; |
212 |
+#endif |
213 |
break; |
214 |
case IPPROTO_UDP: |
215 |
xip = (struct xinpcb *)xig; |
216 |
@@ -1830,7 +1890,11 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) |
217 |
"struct xinpcb size mismatch"); |
218 |
goto error; |
219 |
} |
220 |
+#if __FreeBSD_version >= 1200026 |
221 |
+ inp = xip; |
222 |
+#else |
223 |
inp = &xip->xi_inp; |
224 |
+#endif |
225 |
so = &xip->xi_socket; |
226 |
status = PSUTIL_CONN_NONE; |
227 |
break; |
228 |
@@ -2166,7 +2230,7 @@ PsutilMethods[] = |
229 |
"Return process CPU affinity."}, |
230 |
{"proc_cpu_affinity_set", psutil_proc_cpu_affinity_set, METH_VARARGS, |
231 |
"Set process CPU affinity."}, |
232 |
-#if defined(__FreeBSD_version) && __FreeBSD_version >= 800000 |
233 |
+#if defined(__FreeBSD_version) |
234 |
{"proc_open_files", psutil_proc_open_files, METH_VARARGS, |
235 |
"Return files opened by process as a list of (path, fd) tuples"}, |
236 |
{"proc_cwd", psutil_proc_cwd, METH_VARARGS, |
237 |
@@ -2191,7 +2255,7 @@ PsutilMethods[] = |
238 |
"Return swap mem stats"}, |
239 |
{"cpu_times", psutil_cpu_times, METH_VARARGS, |
240 |
"Return system cpu times as a tuple (user, system, nice, idle, irc)"}, |
241 |
-#if defined(__FreeBSD_version) && __FreeBSD_version >= 800000 |
242 |
+#if defined(__FreeBSD_version) |
243 |
{"per_cpu_times", psutil_per_cpu_times, METH_VARARGS, |
244 |
"Return system per-cpu times as a list of tuples"}, |
245 |
#endif |