From owner-freebsd-bugs@FreeBSD.ORG Fri Apr 3 21:40:06 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8B30E106566C for ; Fri, 3 Apr 2009 21:40:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 77BA18FC17 for ; Fri, 3 Apr 2009 21:40:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n33Le63P059891 for ; Fri, 3 Apr 2009 21:40:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n33Le6Tg059890; Fri, 3 Apr 2009 21:40:06 GMT (envelope-from gnats) Date: Fri, 3 Apr 2009 21:40:06 GMT Message-Id: <200904032140.n33Le6Tg059890@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: bin/113860: sh(1): shell is still running when using `sh -c' X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2009 21:40:07 -0000 The following reply was made to PR bin/113860; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, ed@freebsd.org, olli@lurza.secnetix.de, freebsd-hackers@freebsd.org Cc: Subject: Re: bin/113860: sh(1): shell is still running when using `sh -c' Date: Fri, 3 Apr 2009 23:39:05 +0200 I think this can be improved. Given that I've been digging in /bin/sh already... Note first that sh already has some of this functionality: % sh -c '{ echo a; sleep 10;}&'; sleep 1; ps T a PID TT STAT TIME COMMAND 94682 p9 Ss 0:00.07 zsh 94702 p9 S 0:00.00 sleep 10 94704 p9 R+ 0:00.00 ps T % This is the EV_EXIT flag to evaltree() and friends, in eval.c. To make this work for '-c', evalstring() needs some flag like EV_EXIT, and parsecmd() needs to tell evalstring() that the command it read is the last (currently, parsecmd() only reports that there is no command anymore; due to the stack-like memory management it is not really possible to read ahead a command). Putting "{\n" and "\n}" around the string could be an alternative for the latter, as any valid string would consist of one (compound) command only. The new mode for evalstring() would only be used for '-c' commands when '-s' is not given. Apart from bash, ksh93 and Solaris /usr/xpg4/bin/sh (which is basically ksh88) also treat simple commands in '-c' this way. So I think the idea is ok. I'm also slightly annoyed by seeing silly 'sh -c blah' processes hanging around, and it is not always possible or desirable to add 'exec'. On another note, the EV_EXIT mode is erroneously still used if a trap on EXIT has been set (or, maybe, any trap at all; particularly if -T is in effect). This means that such traps may not be executed. Most other shells seem to do this right. -- Jilles Tjoelker