Skip to content

Commit

Permalink
fix #1042: psutil won't compile on FreeBSD 12; applied patch by @glebius
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed May 14, 2017
1 parent 010e0c0 commit 06ded74
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions psutil/arch/bsd/freebsd_socks.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,34 @@ 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;

oxig = xig = (struct xinpgen *)buf;
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 ||
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 06ded74

Please sign in to comment.