[446] in Zephyr_Bugs

home help back first fref pref prev next nref lref last post

[Andreas Stolcke: zephyr zwgc bug found and fixes]

daemon@ATHENA.MIT.EDU (John T Kohl)
Wed Jan 20 08:32:01 1993

Date: Wed, 20 Jan 1993 08:28:35 -0500
From: John T Kohl <jtkohl@zk3.dec.com>
To: bug-zephyr@MIT.EDU



------- Forwarded Message

To: mottsmth@snake.cs.Berkeley.EDU
Cc: root@snake.cs.Berkeley.EDU, jtkohl@cs.Berkeley.EDU
Subject: zephyr zwgc bug found and fixes
Date: Tue, 19 Jan 93 22:41:01 PST
From: Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>


I was having problems with zwgc not terminating by itself after logging out
from the snakes.  This led to lots of phantom registrations over time.

The reason was that the setpgrp/getpgrp functions in HPUX don't work like
they do in BSD.  The BSD functionality is available, but under a different
name.

Occasionally zwgc processes also don't terminate on BSD (and possibly non-BSD)
machines because they don't get send SIGHUPs when the parent process terminates.
(e.g., ultrix consistently doesn't do it when run under rlogin.)  The patch
below also fixes that by periodically checking on the controlling tty process
group.

I have tested the code on hpux, sunos, ultrix, and next machines. Please
apply the patch to your zephyr sources and reinstall zwgc to get rid
of the annoying bug mentioned above.

--Andreas

*** 1.23.1.1	1992/09/14 22:33:41
--- main.c	1993/01/20 02:02:09
***************
*** 5,11 ****
   *      Created by:     Marc Horowitz <marc@athena.mit.edu>
   *
   *      $Source: /usr/src/local/comm/zephyr/src/zwgc/RCS/main.c,v $
!  *      $Author: jtkohl $
   *
   *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
   *      For copying and distribution information, see the file
--- 5,11 ----
   *      Created by:     Marc Horowitz <marc@athena.mit.edu>
   *
   *      $Source: /usr/src/local/comm/zephyr/src/zwgc/RCS/main.c,v $
!  *      $Author: stolcke $
   *
   *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
   *      For copying and distribution information, see the file
***************
*** 13,19 ****
   */
  
  #if (!defined(lint) && !defined(SABER))
! static char rcsid_main_c[] = "$Id: main.c,v 1.23.1.1 1992/09/14 22:33:41 jtkohl Exp $";
  #endif
  
  #include <zephyr/mit-copyright.h>
--- 13,19 ----
   */
  
  #if (!defined(lint) && !defined(SABER))
! static char rcsid_main_c[] = "$Id: main.c,v 1.23.1.2 1993/01/20 02:01:50 stolcke Exp $";
  #endif
  
  #include <zephyr/mit-copyright.h>
***************
*** 36,41 ****
--- 36,47 ----
  #include "variables.h"
  #include "main.h"
  
+ #ifdef hpux
+ #ifndef SYSV
+ #define SYSV
+ #endif
+ #endif
+ 
  extern void notice_handler();
  static void setup_signals(), detach();
  
***************
*** 352,357 ****
--- 358,412 ----
      mux_end_loop_p = 1;
  }
  
+ #include <fcntl.h>
+ #ifndef SYSV
+ #include <sys/ioctl.h>
+ #endif
+ 
+ /*
+  * check that the controlling terminal is still ours.
+  */
+ static int check_tty()
+ {
+     int result;
+     int pgrp;
+     int tty = open("/dev/tty", O_RDONLY|O_NDELAY);
+     
+     if (tty < 0) {
+         return (0);
+     }
+ 
+ #ifdef SYSV
+     if ((pgrp = tcgetpgrp(tty)) < 0)
+ #else
+     if (ioctl(tty, TIOCGPGRP, &pgrp) < 0)
+ #endif
+ 	result = 0;
+     else
+ 	result = 1;
+     
+     close (tty);
+     return (result);
+ }
+ 
+ #define ALARM_INTERVAL	(10)
+ 
+ /*
+  * trigger exit if we lost our tty
+  */
+ static void signal_alarm()
+ {
+     if (!check_tty()) {
+ 	mux_end_loop_p = 1;
+ 	return;
+     }
+ 
+ #ifdef SYSV
+     signal(SIGALRM, signal_alarm);
+ #endif
+     alarm(ALARM_INTERVAL);
+ }
+ 
  #include <sys/wait.h>
  #include <sys/time.h>
  #include <sys/resource.h>
***************
*** 400,412 ****
--- 455,472 ----
  {
    /* detach from terminal and fork. */
    register int i;
+   int have_tty = check_tty();
  
    /* to try to get SIGHUP on user logout */
  #ifdef _AIX
    (void) setpgid(0, getpgrp(getppid()));
  #else
+ #ifdef hpux
+   (void) setpgrp2(0, getpgrp2(getppid()));
+ #else
    (void) setpgrp(0, getpgrp(getppid()));
  #endif
+ #endif
    /* fork off and let parent exit... */
    if (i = fork()) {
        if (i < 0) {
***************
*** 414,419 ****
--- 474,486 ----
  	  exit(1);
        }
        exit(0);
+   }
+ 
+   /* some systems don't send SIGHUP reliably when the parent exits.
+      set up a periodic check that our controlling terminal is still there */
+   if (have_tty) {
+       signal(SIGALRM, signal_alarm);
+       alarm(ALARM_INTERVAL);
    }
  }	
  


------- End Forwarded Message

home help back first fref pref prev next nref lref last post