From 0f45946898d27f03b80d2860d9f0f4c7fbd2ece0 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 9 Mar 1998 00:11:53 +0000 Subject: Do a better job of joining the session leader's process group. Acknowledge in the comment that this doesn't always get us a HUP. --- zwgc/main.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'zwgc') diff --git a/zwgc/main.c b/zwgc/main.c index 1b842cb..0733a23 100644 --- a/zwgc/main.c +++ b/zwgc/main.c @@ -441,11 +441,19 @@ static void detach() /* detach from terminal and fork. */ register int i; - /* to try to get SIGHUP on user logout */ -#if defined(_POSIX_VERSION) && !defined(ultrix) - (void) setpgid(0, tcgetpgrp(1)); -#else - (void) setpgrp(0, getpgrp(getppid())); + /* Attempt to join the process group of the session leader. This + * will get us a HUP if the session leader is in the foreground at + * logout time (which is often the case) or if the shell is running + * under telnetd or xterm (both of which HUP the process group of + * their child process). If we have getsid(), that's the best way + * of finding the session leader; otherwise use the process group of + * the parent process, which is a good guess. */ +#if defined(HAVE_GETSID) + setpgid(0, getsid(0)); +#elif defined(HAVE_GETPGID) + setpgid(0, getpgid(getppid())); +#elif !defined(GETPGRP_VOID) + setpgid(0, getpgrp(getppid())); #endif /* fork off and let parent exit... */ -- cgit v1.2.3