From owner-freebsd-current@FreeBSD.ORG Tue Apr 13 03:51:30 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 809F316A4CE for ; Tue, 13 Apr 2004 03:51:30 -0700 (PDT) Received: from hexagon.stack.nl (hexagon.stack.nl [131.155.140.144]) by mx1.FreeBSD.org (Postfix) with ESMTP id CCAA243D2F for ; Tue, 13 Apr 2004 03:51:29 -0700 (PDT) (envelope-from jilles@stack.nl) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by hexagon.stack.nl (Postfix) with ESMTP id 407BC630#904614C9D; Tue, 13 Apr 2004 12:51:28 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id 7AFF41CCAD; Tue, 13 Apr 2004 12:51:28 +0200 (CEST) Date: Tue, 13 Apr 2004 12:51:28 +0200 From: Jilles Tjoelker To: Alex Vasylenko Message-ID: <20040413105128.GA35957@stack.nl> References: <87wu4pnxs0.fsf__29819.4997165867$1081558708@strauser.com> <407B0462.9040405@omut.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <407B0462.9040405@omut.org> X-Operating-System: FreeBSD 5.2.1-RELEASE-p4 i386 User-Agent: Mutt/1.5.6i cc: Kirk Strauser cc: current@freebsd.org Subject: Re: Why the 30-second pause after executing this script? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2004 10:51:30 -0000 On Mon, Apr 12, 2004 at 05:04:34PM -0400, Alex Vasylenko wrote: > Kirk Strauser wrote: > >to attach to a jail to execute /etc/rc.shutdown. I've noticed that this > >works as expected, unless its output is being piped into another program, > >in > >which case 'sh' waits about 30 seconds after the 'exit 0' line is executed > >before closing its end of the pipe. For example: > /etc/rc.shutdown kills the _shell_ of the watchdog timer instead of the > timer itself, so the timer keeps going. Please try the patch attached. > - sleep $rcshutdown_timeout && ( > + exec sleep $rcshutdown_timeout && ( This means that the part after && is never executed, invalidating the whole purpose of the watchdog! It would be easiest if sh had a builtin similar to the alarm(3) C function, but I can think of complicated setups with trap and wait. Another option is to close the stdin/stdout/stderr in the watchdog (this doesn't seem very satisfying though): diff -u -r1.25 rc.shutdown --- etc/rc.shutdown 8 Jul 2003 02:52:14 -0000 1.25 +++ etc/rc.shutdown 12 Apr 2004 20:55:51 -0000 @@ -66,7 +66,7 @@ _rcshutdown_watchdog= if [ -n "$rcshutdown_timeout" ]; then debug "Initiating watchdog timer." - sleep $rcshutdown_timeout && ( + exec 0<>/dev/tty 1>&0 2>&1 && sleep $rcshutdown_timeout && ( _msg="$rcshutdown_timeout second watchdog" \ " timeout expired. Shutdown terminated." logger -t rc.shutdown "$_msg" Note that I haven't tested anything of this. Also note that the behaviour of 'time cmd1 | cmd2' differs quite a lot between shells. -- Jilles Tjoelker