Hello Yuri,

Could you try with the attached patch.

su is catching the TERM signals so that it can transfer them to its child.
At this point in time, su already decided that the child has to be
terminated.
So su can finish the child cleanup before closing the PAM session.

It still seems strange that systemd sends TERM signals.
This assumes that the tool has a TERM handler or has finished its cleanup
when it closes the PAM session.

Best Regards,
-- 
Nekral
diff --git a/src/su.c b/src/su.c
index 98ea6de..f119c3c 100644
--- a/src/su.c
+++ b/src/su.c
@@ -371,6 +371,12 @@ static void prepare_pam_close_session (void)
 		(void) fputs (_("Session terminated, terminating shell..."),
 		              stderr);
 		(void) kill (-pid_child, caught);
+
+		(void) signal (SIGALRM, kill_child);
+		(void) alarm (2);
+
+		(void) wait (&status);
+		(void) fputs (_(" ...terminated.\n"), stderr);
 	}
 
 	ret = pam_close_session (pamh, 0);
@@ -383,14 +389,6 @@ static void prepare_pam_close_session (void)
 	(void) pam_setcred (pamh, PAM_DELETE_CRED);
 	(void) pam_end (pamh, PAM_SUCCESS);
 
-	if (0 != caught) {
-		(void) signal (SIGALRM, kill_child);
-		(void) alarm (2);
-
-		(void) wait (&status);
-		(void) fputs (_(" ...terminated.\n"), stderr);
-	}
-
 	exit ((0 != WIFEXITED (status)) ? WEXITSTATUS (status)
 	                                : WTERMSIG (status) + 128);
 	/* Only the child returns. See above. */

Reply via email to