diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-18 20:31:32 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-18 20:31:32 +0200 |
commit | 0ad2fe76a9e0f327fc7748623228b2a7e9c24ddd (patch) | |
tree | f079154d17a1fe3803ed47cfc676430a6995fc9e | |
parent | 3fa7ad66061808369137d995306022aa7406b9b1 (diff) | |
parent | 135ce35ad95f70b8fcc0d0769d16c8fc7ee18ad4 (diff) | |
download | psutil-0ad2fe76a9e0f327fc7748623228b2a7e9c24ddd.tar.gz |
Merge branch 'master' of github.com:giampaolo/psutil
-rw-r--r-- | CREDITS | 5 | ||||
-rw-r--r-- | HISTORY.rst | 4 | ||||
-rw-r--r-- | psutil/_psutil_sunos.c | 60 | ||||
-rw-r--r-- | psutil/arch/solaris/v10/ifaddrs.c | 12 | ||||
-rw-r--r-- | psutil/arch/solaris/v10/ifaddrs.h | 2 | ||||
-rwxr-xr-x | setup.py | 5 |
6 files changed, 60 insertions, 28 deletions
@@ -40,6 +40,7 @@ Github usernames of people to CC on github when in need of help. - fbenkstein, Frank Benkstein - SunOS: - wiggin15, Arnon Yaari + - alxchk, Oleksii Shevchuk Contributors ============ @@ -478,3 +479,7 @@ I: 1057 N: Gleb Smirnoff W: https://github.com/glebius I: 1042, 1079 + +N: Oleksii Shevchuk +W: https://github.com/alxchk +I: 1077 diff --git a/HISTORY.rst b/HISTORY.rst index b1843887..bdca8f24 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -62,6 +62,10 @@ processes. - 1074_: [FreeBSD] sensors_battery() raises OSError in case of no battery. - 1075_: [Windows] net_if_addrs(): inet_ntop() return value is not checked. +- 1077_: [SunOS] net_if_addrs() shows garbage addresses on SunOS 5.10. + (patch by Oleksii Shevchuk) +- 1077_: [SunOS] net_connections() does not work on SunOS 5.10. (patch by + Oleksii Shevchuk) - 1079_: [FreeBSD] net_connections() didn't list locally connected sockets. (patch by Gleb Smirnoff) diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index 6c152eed..eba71ec5 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -9,18 +9,23 @@ * this in Cython which I later on translated in C. */ +// fix compilation issue on SunOS 5.10, see: +// https://github.com/giampaolo/psutil/issues/421 +// https://github.com/giampaolo/psutil/issues/1077 +// http://us-east.manta.joyent.com/jmc/public/opensolaris/ARChive/PSARC/2010/111/materials/s10ceval.txt +// +// Because LEGACY_MIB_SIZE defined in the same file there is no way to make autoconfiguration =\ +// -#include <Python.h> - -// fix for "Cannot use procfs in the large file compilation environment" -// error, see: -// http://sourceware.org/ml/gdb-patches/2010-11/msg00336.html -#undef _FILE_OFFSET_BITS +#define NEW_MIB_COMPLIANT 1 #define _STRUCTURED_PROC 1 -// fix compilation issue on SunOS 5.10, see: -// https://github.com/giampaolo/psutil/issues/421 -#define NEW_MIB_COMPLIANT +#include <Python.h> + +#if !defined(_LP64) && _FILE_OFFSET_BITS == 64 +# undef _FILE_OFFSET_BITS +# undef _LARGEFILE64_SOURCE +#endif #include <sys/types.h> #include <sys/stat.h> @@ -46,9 +51,6 @@ #include "_psutil_posix.h" #define PSUTIL_TV2DOUBLE(t) (((t).tv_nsec * 0.000000001) + (t).tv_sec) -#ifndef EXPER_IP_AND_ALL_IRES -#define EXPER_IP_AND_ALL_IRES (1024+4) -#endif /* @@ -960,7 +962,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { #endif char buf[512]; int i, flags, getcode, num_ent, state; - char lip[200], rip[200]; + char lip[INET6_ADDRSTRLEN], rip[INET6_ADDRSTRLEN]; int lport, rport; int processed_pid; int databuf_init = 0; @@ -986,9 +988,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { goto error; } - /* - XXX - These 2 are used in ifconfig.c but they seem unnecessary - ret = ioctl(sd, I_PUSH, "tcp"); + int ret = ioctl(sd, I_PUSH, "tcp"); if (ret == -1) { PyErr_SetFromErrno(PyExc_OSError); goto error; @@ -998,8 +998,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { PyErr_SetFromErrno(PyExc_OSError); goto error; } - */ - + // // OK, this mess is basically copied and pasted from nxsensor project // which copied and pasted it from netstat source code, mibget() // function. Also see: @@ -1009,9 +1008,14 @@ psutil_net_connections(PyObject *self, PyObject *args) { tor->OPT_length = sizeof (struct opthdr); tor->MGMT_flags = T_CURRENT; mibhdr = (struct opthdr *)&tor[1]; - mibhdr->level = EXPER_IP_AND_ALL_IRES; + mibhdr->level = MIB2_IP; mibhdr->name = 0; + +#ifdef NEW_MIB_COMPLIANT + mibhdr->len = 1; +#else mibhdr->len = 0; +#endif ctlbuf.buf = buf; ctlbuf.len = tor->OPT_offset + tor->OPT_length; @@ -1024,7 +1028,6 @@ psutil_net_connections(PyObject *self, PyObject *args) { mibhdr = (struct opthdr *)&toa[1]; ctlbuf.maxlen = sizeof (buf); - for (;;) { flags = 0; getcode = getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags); @@ -1072,7 +1075,11 @@ psutil_net_connections(PyObject *self, PyObject *args) { tp = (mib2_tcpConnEntry_t *)databuf.buf; num_ent = mibhdr->len / sizeof(mib2_tcpConnEntry_t); for (i = 0; i < num_ent; i++, tp++) { +#ifdef NEW_MIB_COMPLIANT processed_pid = tp->tcpConnCreationProcess; +#else + processed_pid = 0; +#endif if (pid != -1 && processed_pid != pid) continue; // construct local/remote addresses @@ -1113,7 +1120,11 @@ psutil_net_connections(PyObject *self, PyObject *args) { num_ent = mibhdr->len / sizeof(mib2_tcp6ConnEntry_t); for (i = 0; i < num_ent; i++, tp6++) { +#ifdef NEW_MIB_COMPLIANT processed_pid = tp6->tcp6ConnCreationProcess; +#else + processed_pid = 0; +#endif if (pid != -1 && processed_pid != pid) continue; // construct local/remote addresses @@ -1149,8 +1160,13 @@ psutil_net_connections(PyObject *self, PyObject *args) { else if (mibhdr->level == MIB2_UDP || mibhdr->level == MIB2_UDP_ENTRY) { ude = (mib2_udpEntry_t *)databuf.buf; num_ent = mibhdr->len / sizeof(mib2_udpEntry_t); + assert(num_ent * sizeof(mib2_udpEntry_t) == mibhdr->len); for (i = 0; i < num_ent; i++, ude++) { +#ifdef NEW_MIB_COMPLIANT processed_pid = ude->udpCreationProcess; +#else + processed_pid = 0; +#endif if (pid != -1 && processed_pid != pid) continue; // XXX Very ugly hack! It seems we get here only the first @@ -1186,7 +1202,11 @@ psutil_net_connections(PyObject *self, PyObject *args) { ude6 = (mib2_udp6Entry_t *)databuf.buf; num_ent = mibhdr->len / sizeof(mib2_udp6Entry_t); for (i = 0; i < num_ent; i++, ude6++) { +#ifdef NEW_MIB_COMPLIANT processed_pid = ude6->udp6CreationProcess; +#else + processed_pid = 0; +#endif if (pid != -1 && processed_pid != pid) continue; inet_ntop(AF_INET6, &ude6->udp6LocalAddress, lip, sizeof(lip)); diff --git a/psutil/arch/solaris/v10/ifaddrs.c b/psutil/arch/solaris/v10/ifaddrs.c index 2eb36a3a..aedba84e 100644 --- a/psutil/arch/solaris/v10/ifaddrs.c +++ b/psutil/arch/solaris/v10/ifaddrs.c @@ -21,10 +21,10 @@ static struct sockaddr * -sa_dup (struct sockaddr *sa1) +sa_dup (struct sockaddr_storage *sa1) { struct sockaddr *sa2; - size_t sz = sizeof(sa1); + size_t sz = sizeof(struct sockaddr_storage); sa2 = (struct sockaddr *) calloc(1,sz); memcpy(sa2,sa1,sz); return(sa2); @@ -91,11 +91,11 @@ int getifaddrs (struct ifaddrs **ifap) if (ioctl(sd, SIOCGLIFADDR, ifr, IFREQSZ) < 0) goto error; - cifa->ifa_addr = sa_dup((struct sockaddr*)&ifr->lifr_addr); + cifa->ifa_addr = sa_dup(&ifr->lifr_addr); if (ioctl(sd, SIOCGLIFNETMASK, ifr, IFREQSZ) < 0) goto error; - cifa->ifa_netmask = sa_dup((struct sockaddr*)&ifr->lifr_addr); + cifa->ifa_netmask = sa_dup(&ifr->lifr_addr); cifa->ifa_flags = 0; cifa->ifa_dstaddr = NULL; @@ -105,9 +105,9 @@ int getifaddrs (struct ifaddrs **ifap) if (ioctl(sd, SIOCGLIFDSTADDR, ifr, IFREQSZ) < 0) { if (0 == ioctl(sd, SIOCGLIFBRDADDR, ifr, IFREQSZ)) - cifa->ifa_dstaddr = sa_dup((struct sockaddr*)&ifr->lifr_addr); + cifa->ifa_dstaddr = sa_dup(&ifr->lifr_addr); } - else cifa->ifa_dstaddr = sa_dup((struct sockaddr*)&ifr->lifr_addr); + else cifa->ifa_dstaddr = sa_dup(&ifr->lifr_addr); pifa = cifa; ccp += IFREQSZ; diff --git a/psutil/arch/solaris/v10/ifaddrs.h b/psutil/arch/solaris/v10/ifaddrs.h index e1d88596..d2771193 100644 --- a/psutil/arch/solaris/v10/ifaddrs.h +++ b/psutil/arch/solaris/v10/ifaddrs.h @@ -23,4 +23,4 @@ struct ifaddrs { extern int getifaddrs(struct ifaddrs **); extern void freeifaddrs(struct ifaddrs *); -#endif
\ No newline at end of file +#endif @@ -235,7 +235,10 @@ elif SUNOS: macros.append(("PSUTIL_SUNOS", 1)) ext = Extension( 'psutil._psutil_sunos', - sources=sources + ['psutil/_psutil_sunos.c'], + sources=sources + [ + 'psutil/_psutil_sunos.c', + 'psutil/arch/solaris/v10/ifaddrs.c', + ], define_macros=macros, libraries=['kstat', 'nsl', 'socket']) |