Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-psutil for openSUSE:Factory 
checked in at 2023-08-28 17:11:20
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-psutil (Old)
 and      /work/SRC/openSUSE:Factory/.python-psutil.new.1766 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-psutil"

Mon Aug 28 17:11:20 2023 rev:74 rq:1105468 version:5.9.5

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-psutil/python-psutil.changes      
2023-05-04 17:09:39.088040685 +0200
+++ /work/SRC/openSUSE:Factory/.python-psutil.new.1766/python-psutil.changes    
2023-08-28 17:11:26.180508693 +0200
@@ -1,0 +2,6 @@
+Wed Aug 23 09:40:44 UTC 2023 - Alberto Planas Dominguez <apla...@suse.com>
+
+- Add logind_y2038.patch to use logind if systemd >= 254 is used, to
+  fix the issue of ut_tv.tv_sec and the Y2038 problem.
+
+-------------------------------------------------------------------

New:
----
  logind_y2038.patch

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-psutil.spec ++++++
--- /var/tmp/diff_new_pack.mxwZFP/_old  2023-08-28 17:11:27.468554948 +0200
+++ /var/tmp/diff_new_pack.mxwZFP/_new  2023-08-28 17:11:27.472555092 +0200
@@ -38,11 +38,15 @@
 Patch3:         skip_rlimit_tests_on_python2.patch
 # PATCH-FIX-SLE adopt change of used memory of procps
 Patch4:         mem-used-bsc1181475.patch
+# PATCH-FIX-UPSTREAM logind_y2038.patch gh#giampaolo/psutil#2300 
apla...@suse.com
+Patch5:         logind_y2038.patch
 BuildRequires:  %{python_module devel}
 BuildRequires:  %{python_module setuptools}
 BuildRequires:  fdupes
 BuildRequires:  python-rpm-macros
 Requires:       procps
+BuildRequires:  systemd
+BuildRequires:  systemd-devel
 %if %{with test}
 BuildRequires:  net-tools
 BuildRequires:  procps

++++++ logind_y2038.patch ++++++
>From 89b2d1896ffa8e5c9a8d9b89c3af0bb9027ce23b Mon Sep 17 00:00:00 2001
From: Alberto Planas <apla...@suse.com>
Date: Tue, 22 Aug 2023 15:54:09 +0200
Subject: [PATCH] Use logind instead of utmp because of Y2038

Bi-arch systems line x86-64 present the Y2038 problem, where an overflow
can be produced because some glibc compatibility decissions (see
https://github.com/thkukuk/utmpx/blob/main/Y2038.md for more
information)

This patch uses logind from systemd instead of utmp on Linux systems, if
the systemd version is support the new API (>= 254).

Signed-off-by: Alberto Planas <apla...@suse.com>
---
 INSTALL.rst            |  4 +--
 psutil/_psutil_linux.c | 81 ++++++++++++++++++++++++++++++++++++++++--
 setup.py               | 22 ++++++++++++
 3 files changed, 102 insertions(+), 5 deletions(-)

Index: psutil-5.9.5/INSTALL.rst
===================================================================
--- psutil-5.9.5.orig/INSTALL.rst
+++ psutil-5.9.5/INSTALL.rst
@@ -17,12 +17,12 @@ Linux (build)
 
 Ubuntu / Debian::
 
-    sudo apt-get install gcc python3-dev
+    sudo apt-get install gcc python3-dev libsystemd-dev
     pip install --no-binary :all: psutil
 
 RedHat / CentOS::
 
-    sudo yum install gcc python3-devel
+    sudo yum install gcc python3-devel systemd-devel
     pip install --no-binary :all: psutil
 
 Alpine::
Index: psutil-5.9.5/psutil/_psutil_linux.c
===================================================================
--- psutil-5.9.5.orig/psutil/_psutil_linux.c
+++ psutil-5.9.5/psutil/_psutil_linux.c
@@ -14,7 +14,11 @@
 #include <stdlib.h>
 #include <mntent.h>
 #include <features.h>
-#include <utmp.h>
+#ifdef SYSTEMD_LINUX
+    #include <systemd/sd-login.h>
+#else
+    #include <utmp.h>
+#endif
 #include <sched.h>
 #include <linux/version.h>
 #include <sys/syscall.h>
@@ -363,42 +367,102 @@ psutil_proc_cpu_affinity_set(PyObject *s
  */
 static PyObject *
 psutil_users(PyObject *self, PyObject *args) {
+#ifdef SYSTEMD_LINUX
+    char **sessions_list = NULL;
+#else
     struct utmp *ut;
+#endif
     PyObject *py_retlist = PyList_New(0);
     PyObject *py_tuple = NULL;
     PyObject *py_username = NULL;
     PyObject *py_tty = NULL;
     PyObject *py_hostname = NULL;
     PyObject *py_user_proc = NULL;
+    double tstamp = 0.0;
+    pid_t pid = 0;
 
     if (py_retlist == NULL)
         return NULL;
+#ifdef SYSTEMD_LINUX
+    int sessions = sd_get_sessions(&sessions_list);
+    for (int i = 0; i < sessions; i++) {
+        const char *session_id = sessions_list[i];
+#else
     setutent();
     while (NULL != (ut = getutent())) {
+#endif
         py_tuple = NULL;
         py_user_proc = NULL;
+    #ifdef SYSTEMD_LINUX
+        py_user_proc = Py_True;
+    #else
         if (ut->ut_type == USER_PROCESS)
             py_user_proc = Py_True;
         else
             py_user_proc = Py_False;
+    #endif
+
+    #ifdef SYSTEMD_LINUX
+        char *username = NULL;
+        if (sd_session_get_username(session_id, &username) < 0)
+            goto error;
+        py_username = PyUnicode_DecodeFSDefault(username);
+        free(username);
+    #else
         py_username = PyUnicode_DecodeFSDefault(ut->ut_user);
+    #endif
         if (! py_username)
             goto error;
+
+    #ifdef SYSTEMD_LINUX
+        char *tty = NULL;
+        if (sd_session_get_tty(session_id, &tty) < 0) {
+            py_tty = PyUnicode_DecodeFSDefault("n/a");
+        } else {
+            py_tty = PyUnicode_DecodeFSDefault(tty);
+            free(tty);
+        }
+    #else
         py_tty = PyUnicode_DecodeFSDefault(ut->ut_line);
+    #endif
         if (! py_tty)
             goto error;
+    #ifdef SYSTEMD_LINUX
+        char *hostname = NULL;
+        if (sd_session_get_remote_host(session_id, &hostname) < 0)
+            goto error;
+        py_hostname = PyUnicode_DecodeFSDefault(hostname);
+        free(hostname);
+    #else
         py_hostname = PyUnicode_DecodeFSDefault(ut->ut_host);
+    #endif
         if (! py_hostname)
             goto error;
 
+    #ifdef SYSTEMD_LINUX
+        uint64_t usec = 0;
+        if (sd_session_get_start_time(session_id, &usec) < 0)
+           goto error;
+        tstamp = (double)usec / 1000000.0;
+    #else
+        tstamp = (double)ut->ut_tv.tv_sec;
+    #endif
+
+    #ifdef SYSTEMD_LINUX
+        if (sd_session_get_leader(session_id, &pid) < 0)
+           goto error;
+    #else
+        pid = ut->ut_pid;
+    #endif
+
         py_tuple = Py_BuildValue(
             "OOOdO" _Py_PARSE_PID,
             py_username,              // username
             py_tty,                   // tty
             py_hostname,              // hostname
-            (double)ut->ut_tv.tv_sec,  // tstamp
+            tstamp,                   // tstamp
             py_user_proc,             // (bool) user process
-            ut->ut_pid                // process id
+            pid                       // process id
         );
         if (! py_tuple)
             goto error;
@@ -408,8 +472,15 @@ psutil_users(PyObject *self, PyObject *a
         Py_CLEAR(py_tty);
         Py_CLEAR(py_hostname);
         Py_CLEAR(py_tuple);
+    #ifdef SYSTEMD_LINUX
+        free (sessions_list[i]);
+    #endif
     }
+#ifdef SYSTEMD_LINUX
+    free(sessions_list);
+#else
     endutent();
+#endif
     return py_retlist;
 
 error:
@@ -418,7 +489,11 @@ error:
     Py_XDECREF(py_hostname);
     Py_XDECREF(py_tuple);
     Py_DECREF(py_retlist);
+#ifdef SYSTEMD_LINUX
+    free(sessions_list);
+#else
     endutent();
+#endif
     return NULL;
 }
 
Index: psutil-5.9.5/setup.py
===================================================================
--- psutil-5.9.5.orig/setup.py
+++ psutil-5.9.5/setup.py
@@ -184,6 +184,20 @@ def unix_can_compile(c_code):
         shutil.rmtree(tempdir)
 
 
+def get_systemd_version():
+    r = subprocess.run(["systemctl", "--version"], capture_output=True)
+    if r.returncode != 0:
+        return 0
+    out = r.stdout.split()
+    if len(out) < 2:
+        return 0
+    version = out[1]
+    try:
+        return int(version)
+    except ValueError:
+        return 0
+
+
 if WINDOWS:
     def get_winver():
         maj, min = sys.getwindowsversion()[0:2]
@@ -302,10 +316,18 @@ elif LINUX:
     if not unix_can_compile("#include <linux/ethtool.h>"):
         macros.append(("PSUTIL_ETHTOOL_MISSING_TYPES", 1))
 
+    libraries = []
+    # Systemd >= 254 can replace utmp. See:
+    # https://github.com/thkukuk/utmpx/blob/main/utmp-to-logind.md
+    if get_systemd_version() >= 254:
+        macros.append(("SYSTEMD_LINUX", 1))
+        libraries.append("systemd")
+
     macros.append(("PSUTIL_LINUX", 1))
     ext = Extension(
         'psutil._psutil_linux',
         sources=sources + ['psutil/_psutil_linux.c'],
+        libraries=libraries,
         define_macros=macros,
         **py_limited_api)
 

++++++ skip_rlimit_tests_on_python2.patch ++++++
--- /var/tmp/diff_new_pack.mxwZFP/_old  2023-08-28 17:11:27.520556815 +0200
+++ /var/tmp/diff_new_pack.mxwZFP/_new  2023-08-28 17:11:27.524556960 +0200
@@ -2,9 +2,11 @@
  psutil/tests/test_process.py |    6 ++++++
  1 file changed, 6 insertions(+)
 
---- a/psutil/tests/test_process.py
-+++ b/psutil/tests/test_process.py
-@@ -416,6 +416,7 @@ class TestProcess(PsutilTestCase):
+Index: psutil-5.9.5/psutil/tests/test_process.py
+===================================================================
+--- psutil-5.9.5.orig/psutil/tests/test_process.py
++++ psutil-5.9.5/psutil/tests/test_process.py
+@@ -419,6 +419,7 @@ class TestProcess(PsutilTestCase):
              p.ionice(init)
  
      @unittest.skipIf(not HAS_RLIMIT, "not supported")
@@ -12,7 +14,7 @@
      def test_rlimit_get(self):
          import resource
          p = psutil.Process(os.getpid())
-@@ -439,6 +440,7 @@ class TestProcess(PsutilTestCase):
+@@ -442,6 +443,7 @@ class TestProcess(PsutilTestCase):
                  self.assertGreaterEqual(ret[1], -1)
  
      @unittest.skipIf(not HAS_RLIMIT, "not supported")
@@ -20,7 +22,7 @@
      def test_rlimit_set(self):
          p = self.spawn_psproc()
          p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))
-@@ -452,6 +454,7 @@ class TestProcess(PsutilTestCase):
+@@ -455,6 +457,7 @@ class TestProcess(PsutilTestCase):
              p.rlimit(psutil.RLIMIT_NOFILE, (5, 5, 5))
  
      @unittest.skipIf(not HAS_RLIMIT, "not supported")
@@ -28,7 +30,7 @@
      def test_rlimit(self):
          p = psutil.Process()
          testfn = self.get_testfn()
-@@ -472,6 +475,7 @@ class TestProcess(PsutilTestCase):
+@@ -475,6 +478,7 @@ class TestProcess(PsutilTestCase):
              self.assertEqual(p.rlimit(psutil.RLIMIT_FSIZE), (soft, hard))
  
      @unittest.skipIf(not HAS_RLIMIT, "not supported")
@@ -36,7 +38,7 @@
      def test_rlimit_infinity(self):
          # First set a limit, then re-set it by specifying INFINITY
          # and assume we overridden the previous limit.
-@@ -487,6 +491,7 @@ class TestProcess(PsutilTestCase):
+@@ -490,6 +494,7 @@ class TestProcess(PsutilTestCase):
              self.assertEqual(p.rlimit(psutil.RLIMIT_FSIZE), (soft, hard))
  
      @unittest.skipIf(not HAS_RLIMIT, "not supported")
@@ -44,7 +46,7 @@
      def test_rlimit_infinity_value(self):
          # RLIMIT_FSIZE should be RLIM_INFINITY, which will be a really
          # big number on a platform with large file support.  On these
-@@ -1276,6 +1281,7 @@ class TestProcess(PsutilTestCase):
+@@ -1320,6 +1325,7 @@ class TestProcess(PsutilTestCase):
              self.assertEqual(normcase(p.exe()), normcase(PYTHON_EXE))
  
      @unittest.skipIf(not POSIX, 'POSIX only')

Reply via email to