summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvser1 <etienne@voucoux.fr>2019-12-17 14:54:55 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2019-12-17 14:54:55 +0100
commit5deeca9e7a104105e17cc16ad4f79b1c5cdca29e (patch)
tree5d7c0fb9c41a28bb876abb4db25806cea0fc0739
parent0e1c78671b0ea0328bc87ea77081ef52e30b1d06 (diff)
downloadpsutil-5deeca9e7a104105e17cc16ad4f79b1c5cdca29e.tar.gz
[Solaris] Fix #1637 (#1638)
-rw-r--r--CREDITS4
-rw-r--r--HISTORY.rst5
-rw-r--r--psutil/_psutil_sunos.c19
-rw-r--r--psutil/arch/solaris/environ.c1
-rwxr-xr-xsetup.py19
5 files changed, 41 insertions, 7 deletions
diff --git a/CREDITS b/CREDITS
index 330f4f99..40ef4e34 100644
--- a/CREDITS
+++ b/CREDITS
@@ -631,9 +631,9 @@ N: Erwan Le Pape
W: https://github.com/erwan-le-pape
I: 1570
-N: vser1
+N: Étienne Servais
W: https://github.com/vser1
-I: 1607
+I: 1607, 1637
N: Bernát Gábor
W: https://github.com/gaborbernat
diff --git a/HISTORY.rst b/HISTORY.rst
index c81ed6f4..bdd681a4 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,6 +1,11 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*
+**Bug fixes**
+
+- 1637_: [SunOS] Add partial support for old SunOS 5.10 Update 0 to 3.
+ (patch by Étienne Servais)
+
5.6.7
=====
diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c
index 31d6f364..bcfb448f 100644
--- a/psutil/_psutil_sunos.c
+++ b/psutil/_psutil_sunos.c
@@ -12,12 +12,8 @@
/* 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 =\
*/
-#define NEW_MIB_COMPLIANT 1
#define _STRUCTURED_PROC 1
#include <Python.h>
@@ -44,6 +40,14 @@
#include <sys/tihdr.h>
#include <stropts.h>
#include <inet/tcp.h>
+#ifndef NEW_MIB_COMPLIANT
+/*
+ * Solaris introduced NEW_MIB_COMPLIANT macro with Update 4.
+ * See https://github.com/giampaolo/psutil/issues/421
+ * Prior to Update 4, one has to include mib2 by hand.
+ */
+#include <inet/mib2.h>
+#endif
#include <arpa/inet.h>
#include <net/if.h>
#include <math.h> // fabs()
@@ -1747,7 +1751,14 @@ void init_psutil_sunos(void)
PyModule_AddIntConstant(module, "SSTOP", SSTOP);
PyModule_AddIntConstant(module, "SIDL", SIDL);
PyModule_AddIntConstant(module, "SONPROC", SONPROC);
+#ifdef SWAIT
PyModule_AddIntConstant(module, "SWAIT", SWAIT);
+#else
+ /* sys/proc.h started defining SWAIT somewhere
+ * after Update 3 and prior to Update 5 included.
+ */
+ PyModule_AddIntConstant(module, "SWAIT", 0);
+#endif
PyModule_AddIntConstant(module, "PRNODEV", PRNODEV); // for process tty
diff --git a/psutil/arch/solaris/environ.c b/psutil/arch/solaris/environ.c
index 1af4c129..eb0fa2ab 100644
--- a/psutil/arch/solaris/environ.c
+++ b/psutil/arch/solaris/environ.c
@@ -6,7 +6,6 @@
* Functions specific for Process.environ().
*/
-#define NEW_MIB_COMPLIANT 1
#define _STRUCTURED_PROC 1
#include <Python.h>
diff --git a/setup.py b/setup.py
index 99818ad5..d2f2d75f 100755
--- a/setup.py
+++ b/setup.py
@@ -14,6 +14,7 @@ import shutil
import sys
import tempfile
import warnings
+import re
with warnings.catch_warnings():
warnings.simplefilter("ignore")
@@ -266,10 +267,28 @@ if POSIX:
define_macros=macros,
sources=sources)
if SUNOS:
+ def get_sunos_update():
+ # See https://serverfault.com/q/524883
+ # for an explanation of Solaris /etc/release
+ with open('/etc/release') as f:
+ update = re.search(r'(?<=s10s_u)[0-9]{1,2}', f.readline())
+ if update is None:
+ return 0
+ else:
+ return int(update.group(0))
+
posix_extension.libraries.append('socket')
if platform.release() == '5.10':
+ # Detect Solaris 5.10, update >= 4, see:
+ # https://github.com/giampaolo/psutil/pull/1638
+ if get_sunos_update() >= 4:
+ # MIB compliancy starts with SunOS 5.10 Update 4:
+ posix_extension.define_macros.append(('NEW_MIB_COMPLIANT', 1))
posix_extension.sources.append('psutil/arch/solaris/v10/ifaddrs.c')
posix_extension.define_macros.append(('PSUTIL_SUNOS10', 1))
+ else:
+ # Other releases are by default considered to be new mib compliant.
+ posix_extension.define_macros.append(('NEW_MIB_COMPLIANT', 1))
elif AIX:
posix_extension.sources.append('psutil/arch/aix/ifaddrs.c')