Skip to content

Commit

Permalink
tty: handle SIGHUP when allocating a tty (#104)
Browse files Browse the repository at this point in the history
When a session is hung up and a tty is allocated SIGHUP will be sent
to all processes in the session group.  Since we were ignoring SIGHUP
this led to bst processes hanging around.

Add signal handling for SIGHUP to close the tty master.  This will lead
to cleanup of the child session.

Fixes: 1047634
  • Loading branch information
mstory21 authored Dec 18, 2024
1 parent 4fb17a9 commit ff53083
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ int enter(struct entry_settings *opts)
sigfillset(&mask);

if (opts->tty) {
/* tty_parent_setup handles SIGWINCH to resize the pty */
/* tty_parent_setup handles SIGWINCH to resize the pty and SIGHUP to close the pty master */
sigdelset(&mask, SIGWINCH);
sigdelset(&mask, SIGHUP);
tty_parent_setup(&opts->ttyopts, epollfd, socket_fdpass[SOCKET_PARENT]);
}
sig_setup(epollfd, &mask, outer_helper.pid, sig_handler);
Expand Down
15 changes: 13 additions & 2 deletions tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,18 @@ static int tty_handle_sig(int epollfd, const struct epoll_event *ev, int fd, pid
siginfo_t siginfo;
sig_read(fd, &siginfo);

assert(siginfo.si_signo == SIGWINCH && "tty_handle_sig can only handle SIGWINCH");
tty_set_winsize();
assert((siginfo.si_signo == SIGWINCH || siginfo.si_signo == SIGHUP) && "tty_handle_sig can only handle SIGWINCH and SIGHUP");
switch (siginfo.si_signo) {
case SIGWINCH:
tty_set_winsize();
break;
case SIGHUP:
if (info.termfd > 0) {
close(info.termfd);
info.termfd = -1;
}
break;
}
return EPOLL_HANDLER_CONTINUE;
}

Expand Down Expand Up @@ -398,6 +408,7 @@ void tty_parent_setup(struct tty_opts *opts, int epollfd, int socket)
sigset_t sigmask;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGWINCH);
sigaddset(&sigmask, SIGHUP);

int sigfd = signalfd(-1, &sigmask, 0);
if (sigfd == -1) {
Expand Down

0 comments on commit ff53083

Please sign in to comment.