diff --git a/logind_y2038.patch b/logind_y2038.patch deleted file mode 100644 index 6904e3b..0000000 --- a/logind_y2038.patch +++ /dev/null @@ -1,302 +0,0 @@ -From 89b2d1896ffa8e5c9a8d9b89c3af0bb9027ce23b Mon Sep 17 00:00:00 2001 -From: Alberto Planas -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 - -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,6 +14,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -358,11 +359,180 @@ psutil_proc_cpu_affinity_set(PyObject *s - #endif /* PSUTIL_HAVE_CPU_AFFINITY */ - - -+// Systemd function signatures that will be loaded dynamically. -+int (*sd_booted)(void); -+int (*sd_get_sessions)(char ***); -+int (*sd_session_get_leader)(const char *, pid_t *); -+int (*sd_session_get_remote_host)(const char *,char **); -+int (*sd_session_get_start_time)(const char *, uint64_t *); -+int (*sd_session_get_tty)(const char *, char **); -+int (*sd_session_get_username)(const char *, char **); -+ -+// Handle for the libsystemd library -+void *HANDLE = NULL; -+ -+ -+#define dlsym_check(__h, __fn, __name) do { \ -+ __fn = dlsym(__h, #__fn); \ -+ if (dlerror() != NULL || __fn == NULL) { \ -+ psutil_debug("missing '%s' fun", __name); \ -+ dlclose(__h); \ -+ return NULL; \ -+ } \ -+} while (0) -+ -+ -+static void * -+load_systemd() { -+ void *handle = NULL; -+ -+ if (HANDLE != NULL) -+ return HANDLE; -+ -+ handle = dlopen("libsystemd.so.0", RTLD_LAZY); -+ if (dlerror() != NULL || handle == NULL) { -+ psutil_debug("can't open libsystemd.so.0"); -+ return NULL; -+ } -+ -+ dlsym_check(handle, sd_booted, "sd_booted"); -+ dlsym_check(handle, sd_get_sessions, "sd_get_sessions"); -+ dlsym_check(handle, sd_session_get_leader, "sd_session_get_leader"); -+ dlsym_check(handle, sd_session_get_remote_host, "sd_session_get_remote_host"); -+ dlsym_check(handle, sd_session_get_start_time, "sd_session_get_start_time"); -+ dlsym_check(handle, sd_session_get_tty, "sd_session_get_tty"); -+ dlsym_check(handle, sd_session_get_username, "sd_session_get_username"); -+ -+ if (! sd_booted()) { -+ psutil_debug("systemd not booted"); -+ dlclose(handle); -+ return NULL; -+ } -+ -+ HANDLE = handle; -+ return HANDLE; -+} -+ -+static void -+set_systemd_errno(const char *syscall, int neg_errno) { -+ PyObject *exc; -+ int pos_errno; -+ char fullmsg[1024]; -+ -+ pos_errno = abs(neg_errno); -+ snprintf(fullmsg, 1024, "%s (originated from %s)", strerror(pos_errno), syscall); -+ exc = PyObject_CallFunction(PyExc_OSError, "(is)", pos_errno, fullmsg); -+ PyErr_SetObject(PyExc_OSError, exc); -+ Py_XDECREF(exc); -+} -+ -+ - /* - * Return currently connected users as a list of tuples. - */ - static PyObject * --psutil_users(PyObject *self, PyObject *args) { -+psutil_users_systemd(PyObject *self, PyObject *args) { -+ int ret; -+ char **sessions_list = NULL; -+ 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; -+ void *handle = load_systemd(); -+ -+ if (! handle) -+ Py_RETURN_NONE; -+ -+ if (py_retlist == NULL) -+ goto error; -+ int sessions = sd_get_sessions(&sessions_list); -+ for (int i = 0; i < sessions; i++) { -+ const char *session_id = sessions_list[i]; -+ py_tuple = NULL; -+ py_user_proc = NULL; -+ py_user_proc = Py_True; -+ -+ char *username = NULL; -+ if ((ret = sd_session_get_username(session_id, &username)) < 0) { -+ set_systemd_errno("sd_session_get_username", ret); -+ goto error; -+ } -+ py_username = PyUnicode_DecodeFSDefault(username); -+ free(username); -+ if (! py_username) -+ goto error; -+ -+ char *tty = NULL; -+ if (sd_session_get_tty(session_id, &tty) < 0) { -+ py_tty = PyUnicode_DecodeFSDefault(""); -+ } else { -+ py_tty = PyUnicode_DecodeFSDefault(tty); -+ free(tty); -+ } -+ if (! py_tty) -+ goto error; -+ char *hostname = NULL; -+ if (sd_session_get_remote_host(session_id, &hostname) < 0) { -+ py_hostname = PyUnicode_DecodeFSDefault(""); -+ } -+ else { -+ py_hostname = PyUnicode_DecodeFSDefault(hostname); -+ free(hostname); -+ } -+ if (! py_hostname) -+ goto error; -+ -+ uint64_t usec = 0; -+ if ((ret = sd_session_get_start_time(session_id, &usec)) < 0) { -+ set_systemd_errno("sd_session_get_start_time", ret); -+ goto error; -+ } -+ tstamp = (double)usec / 1000000.0; -+ -+ if ((ret = sd_session_get_leader(session_id, &pid)) < 0) { -+ set_systemd_errno("sd_session_get_leader", ret); -+ goto error; -+ } -+ -+ py_tuple = Py_BuildValue( -+ "OOOdO" _Py_PARSE_PID, -+ py_username, // username -+ py_tty, // tty -+ py_hostname, // hostname -+ tstamp, // tstamp -+ py_user_proc, // (bool) user process -+ pid // process id -+ ); -+ if (! py_tuple) -+ goto error; -+ if (PyList_Append(py_retlist, py_tuple)) -+ goto error; -+ Py_CLEAR(py_username); -+ Py_CLEAR(py_tty); -+ Py_CLEAR(py_hostname); -+ Py_CLEAR(py_tuple); -+ free(sessions_list[i]); -+ } -+ free(sessions_list); -+ return py_retlist; -+ -+error: -+ Py_XDECREF(py_username); -+ Py_XDECREF(py_tty); -+ Py_XDECREF(py_hostname); -+ Py_XDECREF(py_tuple); -+ Py_DECREF(py_retlist); -+ if (sessions_list) -+ free(sessions_list); -+ return NULL; -+} -+ -+static PyObject * -+psutil_users_utmp(PyObject *self, PyObject *args) { - struct utmp *ut; - PyObject *py_retlist = PyList_New(0); - PyObject *py_tuple = NULL; -@@ -512,7 +682,8 @@ static PyMethodDef mod_methods[] = { - #endif - // --- system related functions - {"disk_partitions", psutil_disk_partitions, METH_VARARGS}, -- {"users", psutil_users, METH_VARARGS}, -+ {"users_systemd", psutil_users_systemd, METH_VARARGS}, -+ {"users_utmp", psutil_users_utmp, METH_VARARGS}, - {"net_if_duplex_speed", psutil_net_if_duplex_speed, METH_VARARGS}, - - // --- linux specific -Index: psutil-5.9.5/psutil/_pslinux.py -=================================================================== ---- psutil-5.9.5.orig/psutil/_pslinux.py -+++ psutil-5.9.5/psutil/_pslinux.py -@@ -1550,7 +1550,9 @@ def sensors_battery(): - def users(): - """Return currently connected users as a list of namedtuples.""" - retlist = [] -- rawlist = cext.users() -+ rawlist = cext.users_systemd() -+ if rawlist is None: -+ rawlist = cext.users_utmp() - for item in rawlist: - user, tty, hostname, tstamp, user_process, pid = item - # note: the underlying C function includes entries about -Index: psutil-5.9.5/psutil/tests/test_linux.py -=================================================================== ---- psutil-5.9.5.orig/psutil/tests/test_linux.py -+++ psutil-5.9.5/psutil/tests/test_linux.py -@@ -1519,25 +1519,27 @@ class TestMisc(PsutilTestCase): - psutil._pslinux.boot_time) - assert m.called - -- def test_users_mocked(self): -+ def test_users_utmp_mocked(self): - # Make sure ':0' and ':0.0' (returned by C ext) are converted - # to 'localhost'. -- with mock.patch('psutil._pslinux.cext.users', -- return_value=[('giampaolo', 'pts/2', ':0', -- 1436573184.0, True, 2)]) as m: -- self.assertEqual(psutil.users()[0].host, 'localhost') -- assert m.called -- with mock.patch('psutil._pslinux.cext.users', -- return_value=[('giampaolo', 'pts/2', ':0.0', -- 1436573184.0, True, 2)]) as m: -- self.assertEqual(psutil.users()[0].host, 'localhost') -- assert m.called -- # ...otherwise it should be returned as-is -- with mock.patch('psutil._pslinux.cext.users', -- return_value=[('giampaolo', 'pts/2', 'foo', -- 1436573184.0, True, 2)]) as m: -- self.assertEqual(psutil.users()[0].host, 'foo') -- assert m.called -+ with mock.patch('psutil._pslinux.cext.users_systemd', -+ return_value=None): -+ with mock.patch('psutil._pslinux.cext.users_utmp', -+ return_value=[('giampaolo', 'pts/2', ':0', -+ 1436573184.0, True, 2)]) as m: -+ self.assertEqual(psutil.users()[0].host, 'localhost') -+ assert m.called -+ with mock.patch('psutil._pslinux.cext.users_utmp', -+ return_value=[('giampaolo', 'pts/2', ':0.0', -+ 1436573184.0, True, 2)]) as m: -+ self.assertEqual(psutil.users()[0].host, 'localhost') -+ assert m.called -+ # ...otherwise it should be returned as-is -+ with mock.patch('psutil._pslinux.cext.users_utmp', -+ return_value=[('giampaolo', 'pts/2', 'foo', -+ 1436573184.0, True, 2)]) as m: -+ self.assertEqual(psutil.users()[0].host, 'foo') -+ assert m.called - - def test_procfs_path(self): - tdir = self.get_testfn() -Index: psutil-5.9.5/psutil/tests/test_memleaks.py -=================================================================== ---- psutil-5.9.5.orig/psutil/tests/test_memleaks.py -+++ psutil-5.9.5/psutil/tests/test_memleaks.py -@@ -486,6 +486,14 @@ class TestModuleFunctionsLeaks(TestMemor - name = next(psutil.win_service_iter()).name() - self.execute(lambda: cext.winservice_query_descr(name)) - -+ if LINUX: -+ -+ def test_users_systemd(self): -+ self.execute(cext.users_systemd) -+ -+ def test_users_utmp(self): -+ self.execute(cext.users_utmp) -+ - - if __name__ == '__main__': - from psutil.tests.runner import run_from_name diff --git a/psutil-5.9.6.tar.gz b/psutil-5.9.6.tar.gz deleted file mode 100644 index 6b06d90..0000000 --- a/psutil-5.9.6.tar.gz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e4b92ddcd7dd4cdd3f900180ea1e104932c7bce234fb88976e2a3b296441225a -size 496866 diff --git a/psutil-5.9.7.tar.gz b/psutil-5.9.7.tar.gz new file mode 100644 index 0000000..a8438e6 --- /dev/null +++ b/psutil-5.9.7.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f02134e82cfb5d089fddf20bb2e03fd5cd52395321d1c8458a9e58500ff417c +size 498429 diff --git a/python-psutil.changes b/python-psutil.changes index 8f459b9..fa2a2b3 100644 --- a/python-psutil.changes +++ b/python-psutil.changes @@ -1,3 +1,14 @@ +------------------------------------------------------------------- +Wed Dec 27 13:53:57 UTC 2023 - Dirk Müller + +- update to 5.9.7: + * 2324_: enforce Ruff rule `raw-string-in-exception`, which + helps providing clearer tracebacks when exceptions are + raised by psutil. + * 2325_, [PyPy]: psutil did not compile on PyPy due to missing + `PyErr_SetExcFromWindowsErrWithFilenameObject` cPython API. +- drop logind_y2038.patch (upstream) + ------------------------------------------------------------------- Wed Nov 15 20:38:35 UTC 2023 - Benoît Monin @@ -70,7 +81,7 @@ Wed May 3 09:04:54 UTC 2023 - Dirk Müller or `UserWarning` is raised. * there are cases where `Process.cwd()`_ cannot be determined (e.g. directory no longer exists), in which case - we returned either ``None`` or an empty string. + we returned either ``None`` or an empty string. This was consolidated and we now return ``""`` on all platforms. * [UNIX]: if process is a zombie, and we can only @@ -1030,7 +1041,7 @@ Tue Nov 8 21:15:33 UTC 2016 - toddrme2178@gmail.com fail without raising an exception. + 933: [Windows] memory leak in cpu_stats() and WindowsService.description(). - + ------------------------------------------------------------------- Sat Nov 5 16:22:59 UTC 2016 - michael@stroeder.com @@ -1044,18 +1055,18 @@ Tue Oct 25 18:13:08 UTC 2016 - michael@stroeder.com * 927: Popen.__del__() may cause maximum recursion depth error. - Update to version 4.4.0: Enhancements - * 887: [Linux] virtual_memory()'s 'available' and 'used' - values are more precise and match "free" cmdline utility. - "available" also takes into account LCX containers + * 887: [Linux] virtual_memory()'s 'available' and 'used' + values are more precise and match "free" cmdline utility. + "available" also takes into account LCX containers preventing "available" to overflow "total". - * 891: procinfo.py script has been updated and provides a + * 891: procinfo.py script has been updated and provides a lot more info. Bug fixes - * 825: [Linux] cpu_affinity; fix possible double close and + * 825: [Linux] cpu_affinity; fix possible double close and use of unopened socket. - * 885: ValueError is raised if a negative integer is passed + * 885: ValueError is raised if a negative integer is passed to cpu_percent() functions. - * 892: [Linux] Process.cpu_affinity([-1]) raise SystemError + * 892: [Linux] Process.cpu_affinity([-1]) raise SystemError with no error set; now ValueError is raised. ------------------------------------------------------------------- @@ -1064,15 +1075,15 @@ Sat Sep 24 12:36:35 UTC 2016 - michael@stroeder.com - update to version 4.3.1: * #881: "make install" now works also when using a virtual env. * #854: Process.as_dict() raises ValueError if passed an erroneous attrs name. - * #857: [SunOS] Process cpu_times(), cpu_percent(), threads() amd - memory_maps() may raise RuntimeError if attempting to query a 64bit + * #857: [SunOS] Process cpu_times(), cpu_percent(), threads() amd + memory_maps() may raise RuntimeError if attempting to query a 64bit process with a 32bit python. "Null" values are returned as a fallback. - * #858: Process.as_dict() should not return memory_info_ex() because it's + * #858: Process.as_dict() should not return memory_info_ex() because it's deprecated. * #863: [Windows] memory_map truncates addresses above 32 bits - * #866: [Windows] win_service_iter() and services in general are not able + * #866: [Windows] win_service_iter() and services in general are not able to handle unicode service names / descriptions. - * #869: [Windows] Process.wait() may raise TimeoutExpired with wrong + * #869: [Windows] Process.wait() may raise TimeoutExpired with wrong timeout unit (ms instead of sec). * #870: [Windows] Handle leak inside psutil_get_process_data. @@ -1371,7 +1382,7 @@ Mon Feb 2 22:16:07 UTC 2015 - michael@stroeder.com - Update to 2.2.1: - Fixed #572 - ValueError: ambiguos inode with multiple PIDs references + ValueError: ambiguos inode with multiple PIDs references ------------------------------------------------------------------- Tue Jan 6 23:46:40 UTC 2015 - michael@stroeder.com @@ -1580,7 +1591,7 @@ Sat Oct 6 23:01:56 UTC 2012 - os-dev@jacraig.com Fri May 25 04:29:28 UTC 2012 - highwaystar.ru@gmail.com - python3 package added -- minor spec improvement +- minor spec improvement ------------------------------------------------------------------- Tue Apr 24 07:44:19 UTC 2012 - saschpe@suse.de @@ -1597,5 +1608,5 @@ Fri Mar 23 09:44:42 UTC 2012 - saschpe@suse.de ------------------------------------------------------------------- Mon Mar 19 22:00:43 UTC 2012 - cfarrell@suse.com -- First import +- First import diff --git a/python-psutil.spec b/python-psutil.spec index 20e53ca..f53dc4b 100644 --- a/python-psutil.spec +++ b/python-psutil.spec @@ -23,7 +23,7 @@ %endif %{?sle15_python_module_pythons} Name: python-psutil -Version: 5.9.6 +Version: 5.9.7 Release: 0 Summary: A process utilities module for Python License: BSD-3-Clause @@ -36,8 +36,6 @@ Patch2: skip_failing_tests.patch 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 aplanas@suse.com -Patch5: logind_y2038.patch BuildRequires: %{python_module devel} BuildRequires: %{python_module pip} BuildRequires: %{python_module setuptools} @@ -60,8 +58,7 @@ BuildRequires: procps A graphical interface that lets you easily analyze and introspect unaltered running Python processes. %prep -%setup -q -n psutil-%{version} -%autopatch -p1 +%autosetup -p1 -n psutil-%{version} %build %pyproject_wheel