pam_close_session is not called when shutting down the system
Hello I found a problem where pam_close_session is not called when gdm closes a session under certain circumstances. This problem does not happen when logging out, only when shutting down the system. This may not happen if there is some action to delay shutdown in systemd-inhibit
pam_close_session should be called by the gdm-session-worker process, but gdm-session-worker is unexpectedly terminated by SIGHUP of shutdown.target.
During shutting down the system, shutdown.target is started by systemd. shutdown.target stops session-@.scope. session-@.scope have user processes including gdm-session-worker, and gdm-session-worker is terminated by the termination signal sent by session-@.scope.
Because session-@.scope's sendSIGHUP=true, session-@.scope sends SIGTERM and SIGHUP to gdm-session-worker as the termination signal. gdm-session-worker has no handler for SIGHUP and exits immediately, which prevents pam_close_session from being called
This phenomenon was reproduced when I just installed Ubuntu 22.04 LTS