From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 3 21:39:20 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ABFCD1065672; Fri, 3 Apr 2009 21:39:20 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx0.stack.nl (mj0.stack.nl [IPv6:2001:610:1108:5010::187]) by mx1.freebsd.org (Postfix) with ESMTP id 6C13C8FC16; Fri, 3 Apr 2009 21:39:20 +0000 (UTC) (envelope-from jilles@stack.nl) Received: by mx0.stack.nl (Postfix, from userid 65534) id C30DB2B36C0; Fri, 3 Apr 2009 23:39:19 +0200 (CEST) X-Spam-DCC: : X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on meestal-mk5.stack.nl X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,FAKE_REPLY_C, NO_RELAYS autolearn=no version=3.2.3 X-Spam-Relay-Country: Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx0.stack.nl (Postfix) with ESMTP id D20A42B35DD; Fri, 3 Apr 2009 23:39:17 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 2F955228A2; Fri, 3 Apr 2009 23:39:05 +0200 (CEST) Date: Fri, 3 Apr 2009 23:39:05 +0200 From: Jilles Tjoelker To: bug-followup@FreeBSD.org, ed@freebsd.org, olli@lurza.secnetix.de, freebsd-hackers@freebsd.org Message-ID: <20090403213905.GA21297@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: FreeBSD 7.1-PRERELEASE i386 User-Agent: Mutt/1.5.18 (2008-05-17) Cc: Subject: Re: bin/113860: sh(1): shell is still running when using `sh -c' X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2009 21:39:20 -0000 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