Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!bu.edu!mirror!kiyun From: kiyun@mirror.tmc.com (KiYun Roe) Newsgroups: comp.unix.shell Subject: Re: Getting HUPed Message-ID: <53901@mirror.tmc.com> Date: 25 Mar 91 22:49:06 GMT References: <53767@mirror.tmc.com> Reply-To: kiyun@mirror.UUCP (KiYun Roe) Distribution: na Organization: Mirror Systems. Cambridge, Mass. Lines: 39 Thanks to everyone who tried to help me with my problem. I determined that the problem was in a call to isatty(0) inside /bin/rm. To recap, I have a bunch of shell scripts that start off something like this: #! /bin/sh type=`expr $0 : '.*x\(.*\)\.sh'` exec > x$type.log 2>&1 trap "rm -f /tmp/p$$.* ; exit" 0 1 2 13 15 If I start one of these off in the background and log back on, I find that it has gone into an infinite SIGHUP loop. Apparently, what is happening is that /bin/rm calls isatty(0) which leads to a SIGHUP, which the shell traps, which calls /bin/rm, etc. I'm guessing at this, but I compiled a version of rm without the isatty(0) call and the script worked fine. (BTW, /bin/rm calls isatty to automatically set the -f option if the input isn't a terminal. I don't know if that's standard or unique to Pyramid Unix.) Some of you suggested that executing exit inside a trap handler would cause an infinite loop. Well, it doesn't on my machine, and I can't see how it would generate Hangup messages which was the most perplexing part of my problem. However, I would be interested in knowing if it really does cause an infinite exit loop under a different version of Unix. Anyway, here's the prolog I'm using for this particular class of scripts now: #! /bin/sh type=`expr $0 : '.*x\(.*\)\.sh'` exec > x$type.log 2>&1 trap "exec rm -f /usr/tmp/p$$.* < /dev/null" 0 1 2 13 15 I hope the exec will take care of any infinite loops, and redirecting stdin to /dev/null should keep rm out of trouble.