Call init_pty before signals are set up.

Signals set to SIG_IGN (such as SIGPIPE) are not reset when execve is
called, which causes programs executed by dtach to start in a different
state than what they expect. Calling init_pty first is the simplest way
to fix this bug.

Bug reported by Robert de Bath at https://bugs.debian.org/805417
This commit is contained in:
Ned T. Crigler 2015-12-01 18:46:58 -08:00
parent c794d0615c
commit 35219aa11c
1 changed files with 10 additions and 10 deletions

View File

@ -449,6 +449,16 @@ master_process(int s, char **argv, int waitattach, int statusfd)
/* Set a trap to unlink the socket when we die. */
atexit(unlink_socket);
/* Create a pty in which the process is running. */
signal(SIGCHLD, die);
if (init_pty(argv, statusfd) < 0)
{
if (statusfd != -1)
dup2(statusfd, 1);
printf("%s: init_pty: %s\n", progname, strerror(errno));
exit(1);
}
/* Set up some signals. */
signal(SIGPIPE, SIG_IGN);
signal(SIGXFSZ, SIG_IGN);
@ -457,17 +467,7 @@ master_process(int s, char **argv, int waitattach, int statusfd)
signal(SIGTTOU, SIG_IGN);
signal(SIGINT, die);
signal(SIGTERM, die);
signal(SIGCHLD, die);
/* Create a pty in which the process is running. */
if (init_pty(argv, statusfd) < 0)
{
if (statusfd != -1)
dup2(statusfd, 1);
printf("%s: init_pty: %s\n", progname, strerror(errno));
exit(1);
}
/* Close statusfd, since we don't need it anymore. */
if (statusfd != -1)
close(statusfd);