]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pam: do not warn closing bus connection which is opened after the fork
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 21 Jan 2024 04:11:09 +0000 (13:11 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 Feb 2024 08:59:39 +0000 (17:59 +0900)
In pam_systemd.so and pam_systemd_home.so, we open a bus connection on
session close, which is called after fork. Closing the connection is
harmless, and should not warn about that.

This suppresses the following log message:
===
(sd-pam)[127]: PAM Attempted to close sd-bus after fork, this should not happen.
===

src/shared/pam-util.c

index 13b68234c9bf5b838b66d5a5d3758b2395a7968d..fe58203e2739ea14d1a806d2c4170897f7de47f4 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 
 #include "alloc-util.h"
+#include "bus-internal.h"
 #include "errno-util.h"
 #include "format-util.h"
 #include "macro.h"
@@ -88,8 +89,13 @@ static void pam_bus_data_destroy(pam_handle_t *handle, void *data, int error_sta
          * internally anyway. That said, we still generate a warning message, since this really shouldn't
          * happen. */
 
-        if (error_status & PAM_DATA_SILENT)
-                pam_syslog(handle, LOG_DEBUG, "Attempted to close sd-bus after fork, this should not happen.");
+        if (!data)
+                return;
+
+        PamBusData *d = data;
+        if (FLAGS_SET(error_status, PAM_DATA_SILENT) &&
+            d->bus && bus_origin_changed(d->bus))
+                pam_syslog(handle, LOG_DEBUG, "Attempted to close sd-bus after fork whose connection is opened before the fork, this should not happen.");
 
         pam_bus_data_free(data);
 }