From 302917ca33d7cdfac786f562986b2c669f64ad49 Mon Sep 17 00:00:00 2001 From: "Ned T. Crigler" Date: Wed, 23 Jun 2004 04:48:07 +0000 Subject: [PATCH] First attempt at proper process group handling. --- master.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/master.c b/master.c index 8a43e74..8d31651 100644 --- a/master.c +++ b/master.c @@ -201,6 +201,35 @@ control_activity(int s) *(p->pprev) = p; } +/* Send a signal to the slave side of a pseudo-terminal. */ +static void +killpty(struct pty *pty, int sig) +{ + pid_t pgrp = -1; + +#ifdef TIOCSIGNAL + if (ioctl(pty->fd, TIOCSIGNAL, sig) >= 0) + return; +#endif +#ifdef TIOCSIG + if (ioctl(pty->fd, TIOCSIG, sig) >= 0) + return; +#endif +#ifdef TIOCGPGRP +#ifdef BROKEN_MASTER + if (ioctl(pty->slave, TIOCGPGRP, &pgrp) >= 0 && pgrp != -1 && + kill(-pgrp, sig) >= 0) + return; +#endif + if (ioctl(pty->fd, TIOCGPGRP, &pgrp) >= 0 && pgrp != -1 && + kill(-pgrp, sig) >= 0) + return; +#endif + + /* Fallback using the child's pid. */ + kill(-pty->pid, sig); +} + /* Process activity from a client. */ static void client_activity(struct client *p) @@ -241,7 +270,7 @@ client_activity(struct client *p) ioctl(the_pty.fd, TIOCSWINSZ, &the_pty.ws); } else - kill(-the_pty.pid, SIGWINCH); + killpty(&the_pty, SIGWINCH); } else if (pkt.type == MSG_DETACH) p->attached = 0;