summaryrefslogtreecommitdiff
path: root/zwgc
diff options
context:
space:
mode:
authorGravatar Greg Hudson <ghudson@mit.edu>1998-03-09 00:11:53 +0000
committerGravatar Greg Hudson <ghudson@mit.edu>1998-03-09 00:11:53 +0000
commit0f45946898d27f03b80d2860d9f0f4c7fbd2ece0 (patch)
tree566cbb6e936c0974c15c34730fc6264d39a81658 /zwgc
parentab281e90df214db257acdbd140af23950a0ac863 (diff)
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.
Diffstat (limited to 'zwgc')
-rw-r--r--zwgc/main.c18
1 files changed, 13 insertions, 5 deletions
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... */