From 34e4ad1796a42da64e196f9c6965f1a073e6dd9d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 21 Jan 2024 13:11:09 +0900 Subject: [PATCH 1/2] pam: do not warn closing bus connection which is opened after the fork 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index 13b68234c9..fe58203e27 100644 --- a/src/shared/pam-util.c +++ b/src/shared/pam-util.c @@ -5,6 +5,7 @@ #include #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); } From 88b8d0827691a6c9643c6bd06e73f4ab86dba578 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 21 Jan 2024 13:14:15 +0900 Subject: [PATCH 2/2] test: check pam warning message --- src/shared/pam-util.c | 1 + test/units/end.sh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index fe58203e27..0e24af450d 100644 --- a/src/shared/pam-util.c +++ b/src/shared/pam-util.c @@ -95,6 +95,7 @@ static void pam_bus_data_destroy(pam_handle_t *handle, void *data, int error_sta PamBusData *d = data; if (FLAGS_SET(error_status, PAM_DATA_SILENT) && d->bus && bus_origin_changed(d->bus)) + /* Please adjust test/units/end.sh when updating the log message. */ 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); diff --git a/test/units/end.sh b/test/units/end.sh index dd50654f8d..230b716e2f 100755 --- a/test/units/end.sh +++ b/test/units/end.sh @@ -6,5 +6,8 @@ set -o pipefail (! journalctl -q -o short-monotonic --grep "didn't pass validation" >>/failed) +# Here, the redundant '[.]' at the end is for making not the logged self command hit the grep. +(! journalctl -q -o short-monotonic --grep 'Attempted to close sd-bus after fork whose connection is opened before the fork, this should not happen[.]' >>/failed) + systemctl poweroff --no-block exit 0