summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-14 13:46:53 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-14 13:46:53 +0200
commit06ded749e398c1dbec32548302d73b2832b1c5a2 (patch)
tree13e2ca11822815e2a9c71bba34bb3be7da501760
parent010e0c0ed99fce8ac6a403103af3e10b63f1b555 (diff)
downloadpsutil-06ded749e398c1dbec32548302d73b2832b1c5a2.tar.gz
fix #1042: psutil won't compile on FreeBSD 12; applied patch by @glebius
-rw-r--r--CREDITS4
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/arch/bsd/freebsd_socks.c31
3 files changed, 36 insertions, 0 deletions
diff --git a/CREDITS b/CREDITS
index 4c2b6c70..a514d7ee 100644
--- a/CREDITS
+++ b/CREDITS
@@ -472,3 +472,7 @@ I: 1036
N: Yannick Gingras
W: https://github.com/ygingras
I: 1057
+
+N: Gleb Smirnoff
+W: https://github.com/glebius
+I: 1042
diff --git a/HISTORY.rst b/HISTORY.rst
index a80d1123..2ada3621 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -41,6 +41,7 @@
Process.connections() when retrieving UNIX sockets (kind='unix').
- 1040_: fixed many unicode related issues such as UnicodeDecodeError on
Python 3 + UNIX and invalid encoded data on Windows.
+- 1042_: [FreeBSD] psutil won't compile on FreeBSD 12.
- 1046_: [Windows] disk_partitions() on Windows overrides user's SetErrorMode.
- 1047_: [Windows] Process username(): memory leak in case exception is thrown.
- 1050_: [Windows] Process.memory_maps memory() leaks memory.
diff --git a/psutil/arch/bsd/freebsd_socks.c b/psutil/arch/bsd/freebsd_socks.c
index 54c09ab1..5c4a47df 100644
--- a/psutil/arch/bsd/freebsd_socks.c
+++ b/psutil/arch/bsd/freebsd_socks.c
@@ -112,10 +112,17 @@ psutil_sockaddr_matches(int family, int port, void *pcb_addr,
}
+#if __FreeBSD_version >= 1200026
+static struct xtcpcb *
+psutil_search_tcplist(char *buf, struct kinfo_file *kif) {
+ struct xtcpcb *tp;
+ struct xinpcb *inp;
+#else
static struct tcpcb *
psutil_search_tcplist(char *buf, struct kinfo_file *kif) {
struct tcpcb *tp;
struct inpcb *inp;
+#endif
struct xinpgen *xig, *oxig;
struct xsocket *so;
@@ -123,9 +130,16 @@ psutil_search_tcplist(char *buf, struct kinfo_file *kif) {
for (xig = (struct xinpgen *)((char *)xig + xig->xig_len);
xig->xig_len > sizeof(struct xinpgen);
xig = (struct xinpgen *)((char *)xig + xig->xig_len)) {
+
+#if __FreeBSD_version >= 1200026
+ tp = (struct xtcpcb *)xig;
+ inp = &tp->xt_inp;
+ so = &inp->xi_socket;
+#else
tp = &((struct xtcpcb *)xig)->xt_tp;
inp = &((struct xtcpcb *)xig)->xt_inp;
so = &((struct xtcpcb *)xig)->xt_socket;
+#endif
if (so->so_type != kif->kf_sock_type ||
so->xso_family != kif->kf_sock_domain ||
@@ -207,7 +221,11 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
struct xinpgen *xig, *exig;
struct xinpcb *xip;
struct xtcpcb *xtp;
+#if __FreeBSD_version >= 1200026
+ struct xinpcb *inp;
+#else
struct inpcb *inp;
+#endif
struct xsocket *so;
const char *varname = NULL;
size_t len, bufsize;
@@ -272,8 +290,13 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
goto error;
}
inp = &xtp->xt_inp;
+#if __FreeBSD_version >= 1200026
+ so = &inp->xi_socket;
+ status = xtp->t_state;
+#else
so = &xtp->xt_socket;
status = xtp->xt_tp.t_state;
+#endif
break;
case IPPROTO_UDP:
xip = (struct xinpcb *)xig;
@@ -282,7 +305,11 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
"struct xinpcb size mismatch");
goto error;
}
+#if __FreeBSD_version >= 1200026
+ inp = xip;
+#else
inp = &xip->xi_inp;
+#endif
so = &xip->xi_socket;
status = PSUTIL_CONN_NONE;
break;
@@ -483,7 +510,11 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
struct kinfo_file *freep = NULL;
struct kinfo_file *kif;
char *tcplist = NULL;
+#if __FreeBSD_version >= 1200026
+ struct xtcpcb *tcp;
+#else
struct tcpcb *tcp;
+#endif
PyObject *py_retlist = PyList_New(0);
PyObject *py_tuple = NULL;