Bug 242543

Summary: sysutils/py-psutil Process broken on 12.0+ i386
Product: Ports & Packages Reporter: Antoine Brodin <antoine>
Component: Individual Port(s)Assignee: Po-Chuan Hsieh <sunpoet>
Status: Closed FIXED    
Severity: Affects Only Me Flags: bugzilla: maintainer-feedback? (sunpoet)
Priority: ---    
Version: Latest   
Hardware: i386   
OS: Any   

Description Antoine Brodin freebsd_committer freebsd_triage 2019-12-10 13:44:29 UTC
It seems that sysutils/py-psutil Process is broken on 12.0+ i386  (this code runs fine on 11.3 i386 or on amd64)

Sample code:

root@121i386-custom:~ # python3.6
Python 3.6.9 (default, Dec 10 2019, 09:51:50)
[GCC 4.2.1 Compatible FreeBSD Clang 8.0.1 (tags/RELEASE_801/final 366581)] on freebsd12
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import psutil
>>> os.getpid()
19956
>>> psutil.pid_exists(19956)
True
>>> psutil.Process(19956)
Segmentation fault
Comment 1 Antoine Brodin freebsd_committer freebsd_triage 2019-12-10 13:53:33 UTC
More details with py-psutil built with debug on:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/psutil/__init__.py", line 447, in __init__
    self._init(pid)
  File "/usr/local/lib/python3.6/site-packages/psutil/__init__.py", line 474, in _init
    self.create_time()
  File "/usr/local/lib/python3.6/site-packages/psutil/__init__.py", line 824, in create_time
    self._create_time = self._proc.create_time()
  File "/usr/local/lib/python3.6/site-packages/psutil/_psbsd.py", line 556, in wrapper
    return fun(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/psutil/_psbsd.py", line 732, in create_time
    return self.oneshot()[kinfo_proc_map['create_time']]
  File "/usr/local/lib/python3.6/site-packages/psutil/_psbsd.py", line 556, in wrapper
    return fun(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/psutil/_common.py", line 343, in wrapper
    return fun(self)
  File "/usr/local/lib/python3.6/site-packages/psutil/_psbsd.py", line 611, in oneshot
    ret = cext.proc_oneshot_info(self.pid)
SystemError: NULL object passed to Py_BuildValue
Comment 2 Antoine Brodin freebsd_committer freebsd_triage 2019-12-10 15:51:30 UTC
This patch seems to help:

--- psutil/_psutil_bsd.c.orig   2019-11-20 08:39:49 UTC
+++ psutil/_psutil_bsd.c
@@ -271,7 +271,11 @@ psutil_proc_oneshot_info(PyObject *self, PyObject *arg

     // Return a single big tuple with all process info.
     py_retlist = Py_BuildValue(
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031
+        "(lillllllLdllllddddlllllbO)",
+#else
         "(lillllllidllllddddlllllbO)",
+#endif
 #ifdef PSUTIL_FREEBSD
         //
         (long)kp.ki_ppid,                // (long) ppid
@@ -285,7 +289,7 @@ psutil_proc_oneshot_info(PyObject *self, PyObject *arg
         (long)kp.ki_groups[0],           // (long) effective gid
         (long)kp.ki_svuid,               // (long) saved gid
         //
-        kp.ki_tdev,                      // (int) tty nr
+        kp.ki_tdev,                      // (int or long long) tty nr
         PSUTIL_TV2DOUBLE(kp.ki_start),   // (double) create time
         // ctx switches
         kp.ki_rusage.ru_nvcsw,           // (long) ctx switches (voluntary)
Comment 3 commit-hook freebsd_committer freebsd_triage 2019-12-12 13:49:12 UTC
A commit references this bug:

Author: sunpoet
Date: Thu Dec 12 13:48:33 UTC 2019
New revision: 519924
URL: https://svnweb.freebsd.org/changeset/ports/519924

Log:
  Fix Process on 12.0+ i386

  - Bump PORTREVISION for package change

  FreeBSD 12.0+ change ki_tdev from 32 bits to 64 bits.

  PR:		242543
  Submitted by:	antoine

Changes:
  head/sysutils/py-psutil/Makefile
  head/sysutils/py-psutil/files/
  head/sysutils/py-psutil/files/patch-psutil-_psutil_bsd.c
Comment 4 Po-Chuan Hsieh freebsd_committer freebsd_triage 2019-12-31 10:41:33 UTC
FYI, it has been merged upstream. Thanks!

[1] https://github.com/giampaolo/psutil/pull/1646