From 7d2332626e3d5eea8f6cddaf16f25d37e6892349 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 10 Feb 2022 07:47:47 +0100 Subject: [PATCH] dconf: Skip processes that disappeared while we inspected them (#4153) (#4182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * dconf: Skip processes that disappeared while we inspected them Fixes #4151 * Update changelogs/fragments/4151-dconf-catch-psutil-nosuchprocess.yaml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit 9567c99c9f70e9edf38a71538f6398e6c42a1fbb) Co-authored-by: Pavol Babinčák‏ --- .../fragments/4151-dconf-catch-psutil-nosuchprocess.yaml | 2 ++ plugins/modules/system/dconf.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/4151-dconf-catch-psutil-nosuchprocess.yaml diff --git a/changelogs/fragments/4151-dconf-catch-psutil-nosuchprocess.yaml b/changelogs/fragments/4151-dconf-catch-psutil-nosuchprocess.yaml new file mode 100644 index 0000000000..6856af8a28 --- /dev/null +++ b/changelogs/fragments/4151-dconf-catch-psutil-nosuchprocess.yaml @@ -0,0 +1,2 @@ +bugfixes: + - "dconf - skip processes that disappeared while we inspected them (https://github.com/ansible-collections/community.general/issues/4151)." diff --git a/plugins/modules/system/dconf.py b/plugins/modules/system/dconf.py index f7776cde6e..636ca536ee 100644 --- a/plugins/modules/system/dconf.py +++ b/plugins/modules/system/dconf.py @@ -180,9 +180,9 @@ class DBusWrapper(object): self.module.debug("Trying to detect existing D-Bus user session for user: %d" % uid) for pid in psutil.pids(): - process = psutil.Process(pid) - process_real_uid, dummy, dummy = process.uids() try: + process = psutil.Process(pid) + process_real_uid, dummy, dummy = process.uids() if process_real_uid == uid and 'DBUS_SESSION_BUS_ADDRESS' in process.environ(): dbus_session_bus_address_candidate = process.environ()['DBUS_SESSION_BUS_ADDRESS'] self.module.debug("Found D-Bus user session candidate at address: %s" % dbus_session_bus_address_candidate) @@ -198,6 +198,9 @@ class DBusWrapper(object): # This can happen with things like SSH sessions etc. except psutil.AccessDenied: pass + # Process has disappeared while inspecting it + except psutil.NoSuchProcess: + pass self.module.debug("Failed to find running D-Bus user session, will use dbus-run-session")