char *old_user; /* orginal user */
pid_t child; /* fork() baby */
+ int childstatus; /* wait() status */
struct sigaction oldact[SIGNALS_IDX_COUNT]; /* original sigactions indexed by SIG*_IDX */
get_terminal_name(NULL, &su->tty_name, &su->tty_number);
}
+/*
+ * Note, this function has to be possible call more than once. If the child is
+ * already dead than it returns saved result from the previous call.
+ */
static int wait_for_child(struct su_context *su)
{
pid_t pid = (pid_t) -1;;
int status = 0;
+ if (su->child == (pid_t) -1)
+ return su->childstatus;
+
if (su->child != (pid_t) -1) {
DBG(SIG, ul_debug("waiting for child [%d]...", su->child));
for (;;) {
DBG(SIG, ul_debug("child %d is dead", su->child));
su->child = (pid_t) -1; /* Don't use the PID anymore! */
+ su->childstatus = status;
} else if (caught_signal)
status = caught_signal + 128;
else
status = 1;
- DBG(SIG, ul_debug("status=%d", status));
+ DBG(SIG, ul_debug("child status=%d", status));
return status;
}
else
status = 1;
+ DBG(SIG, ul_debug("final child status=%d", status));
+
if (caught_signal && su->child != (pid_t)-1) {
fprintf(stderr, _("\nSession terminated, killing shell..."));
kill(su->child, SIGTERM);