Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!amdahl!uunet!munnari!otc!metro!basser!usage!ccadfa!cancol!ross From: ross@cancol.oz (Ross Johnson) Newsgroups: comp.sources.bugs Subject: Re: "monthd" doesn't terminate Keywords: month, exit, sun os3.2 Message-ID: <116@cancol.oz> Date: 17 Nov 88 14:12:53 GMT References: <1252@leah.Albany.Edu> <115@cancol.oz> Organization: Info. Sciences, Canberra Coll. of Adv. Ed. Lines: 76 In article <115@cancol.oz>, ross@cancol.oz (Ross Johnson) writes: > In article <1252@leah.Albany.Edu>, rds95@leah.Albany.Edu (Robert Seals) writes: > > Specifically, it should go away after the user logs out, and it > > doesn't. > > > I've experienced the same thing on a Sun running OS3.2 (for cross-reference). (I think this applies to BSD systems in general but I don't know about SYS5.) This works for Sun OS3.2. Monthd knows it won't get any signal to die at logout (because monthd spawns an orphan child which gets inherited by init) so it attempts to find out at it's regular awakening if the user has logged out. For non SYS5 systems it assumes that doing a getpgrp(0) will return 0 if this is so but it isn't. Instead, I do a getpgrp(parent_pid) and look for an error return of -1. Because monthd sets parent_pid = getppid() before the fork it's the pid of the login shell - which will disappear at logout. I've removed the setpgrp() call as well. This only works if you really logout as different from using "login" (to someone else) in your current shell. The later uses the same shell process before and after (and hence the same pid) but presumably you logout eventually :-). Here's the context diff: *** monthd.c.dist Thu Nov 17 13:39:31 1988 --- monthd.c Thu Nov 17 23:10:01 1988 *************** *** 65,73 **** --- 65,75 ---- #ifdef hpux setpgrp2(0, parent_pid); #else + #ifdef SYS5 setpgrp(0, parent_pid); #endif #endif + #endif inf_loop(); } *************** *** 216,228 **** logged_out() { /* fprintf(tty, "%s: child pgrp = %d\n", prog_name, getpgrp()); */ - #if SYS5 return(getpgrp() == 0); /* pgrp is 0 after logout */ #else ! return(getpgrp(0) == 0);/* pgrp is 0 after logout */ #endif } --- 218,233 ---- logged_out() { + #if SYS5 /* fprintf(tty, "%s: child pgrp = %d\n", prog_name, getpgrp()); */ return(getpgrp() == 0); /* pgrp is 0 after logout */ #else ! /* ! fprintf(tty, "%s: -csh pgrp = %d\n", prog_name, getpgrp(parent_pid)); ! */ ! return(getpgrp(parent_pid) == -1); /* is -csh still around? */ #endif }