From owner-freebsd-questions@FreeBSD.ORG Fri Sep 5 11:14:40 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B8DAE16A4BF for ; Fri, 5 Sep 2003 11:14:40 -0700 (PDT) Received: from aeimail.aei.ca (aeimail.aei.ca [206.123.6.14]) by mx1.FreeBSD.org (Postfix) with ESMTP id B05854401A for ; Fri, 5 Sep 2003 11:14:39 -0700 (PDT) (envelope-from anarcat@anarcat.ath.cx) Received: from shall.anarcat.ath.cx (34na5mxqhoahw5zr@dsl-133-58.aei.ca [66.36.133.58]) by aeimail.aei.ca (8.11.6/8.10.1) with ESMTP id h85IEci03938 for ; Fri, 5 Sep 2003 14:14:38 -0400 (EDT) Received: from oder.anarcat.ath.cx (oder.anarcat.ath.cx [192.168.0.32]) by shall.anarcat.ath.cx (Postfix) with SMTP id 7E6602C; Fri, 5 Sep 2003 14:14:36 -0400 (EDT) Received: by oder.anarcat.ath.cx (sSMTP sendmail emulation); Fri, 5 Sep 2003 14:14:36 -0400 Date: Fri, 5 Sep 2003 14:14:36 -0400 From: The Anarcat To: FreeBSD Questions Message-ID: <20030905181436.GF514@inso.ath.cx> Mail-Followup-To: The Anarcat , FreeBSD Questions Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="N8ia4yKhAKKETby7" Content-Disposition: inline User-Agent: Mutt/1.5.4i cc: anarcat@anarcat.ath.cx Subject: bug in sh or misinterpretation? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Sep 2003 18:14:40 -0000 --N8ia4yKhAKKETby7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable [please CC, I don't follow -questions] Hello! I've been struggling with an odd quirk in sh(1). Here is my sample code: --- 8< cut here 8< --- cleanup () { echo "cleaning up $pid" kill $pid } ( echo "in subshell" tail -f /etc/motd & pid=3D$! trap cleanup 1 2 15 wait $pid || echo "command failed" ) & wait --- 8< cut here 8< --- The idea is to be able *in the subshell* to cleanup a backgrounded command. The result is unexpected: anarcat@shall[~/src/local/bin/worldtools]% sh test_trap.sh=20 in subshell FreeBSD 4.8-STABLE (SHALL) #0: Wed Aug 13 16:46:04 EDT 2003 Welcome to Shall, multi-purpose file/mail/web/ftp server. ^C anarcat@shall[~/src/local/bin/worldtools]% ps PID TT STAT TIME COMMAND 14162 p1 Ss 0:03,95 -zsh (zsh) 16918 p1 S 0:00,00 sh test_trap.sh 16919 p1 S 0:00,00 sh test_trap.sh 16920 p1 S 0:00,01 tail -f /etc/motd 16922 p1 R+ 0:00,00 ps i.e. the subshell doesn't call the trap!! I've searched long and large manuals, I even tried debugging (i'm about to build sh with debugging symbols now): the subshell *really* receives the signal, it just ignores it. The sh manpage says that: When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The trap command has = no effect on signals that were ignored on entry to the shell. Well, it looks like calling trap in the subshell doesn't work. For reference, in bash and zsh behave correctly: anarcat@shall[~/src/local/bin/worldtools]% zsh test_trap.sh=20 in subshell FreeBSD 4.8-STABLE (SHALL) #0: Wed Aug 13 16:46:04 EDT 2003 Welcome to Shall, multi-purpose file/mail/web/ftp server. ^Ccleaning up 16947 anarcat@shall[~/src/local/bin/worldtools]% command failed Is it me? Or do I head for GNATS? :) A. --=20 There has been only one Christian. They caught him and crucified him -- early. - Mark Twain --N8ia4yKhAKKETby7 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQE/WNKMttcWHAnWiGcRAm7ZAJ4nBVa6JI5twAD52HX4DcdrynPumQCgk07W 3wkdSpZ3iVYnAsjH6aROp04= =1yzv -----END PGP SIGNATURE----- --N8ia4yKhAKKETby7--