From wosch@DE.FreeBSD.ORG  Fri May  8 01:44:14 1998
Received: from baerenklau.de.freebsd.org (baerenklau.de.freebsd.org [195.185.195.14])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id BAA15906
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 8 May 1998 01:44:12 -0700 (PDT)
          (envelope-from wosch@DE.FreeBSD.ORG)
Received: (from wosch@localhost)
	by baerenklau.de.freebsd.org (8.8.8/8.8.8) id KAA00470;
	Fri, 8 May 1998 10:44:13 +0200 (CEST)
	(envelope-from wosch)
Message-Id: <199805080844.KAA00470@baerenklau.de.freebsd.org>
Date: Fri, 8 May 1998 10:44:13 +0200 (CEST)
From: Wolfram Schneider <wosch@DE.FreeBSD.ORG>
Reply-To: wosch@DE.FreeBSD.ORG
To: FreeBSD-gnats-submit@freebsd.org
Subject: make(1): shell meta-character optimization incomplete
X-Send-Pr-Version: 3.2

>Number:         6550
>Category:       bin
>Synopsis:       make(1): shell meta-character optimization incomplete
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May  8 01:50:02 PDT 1998
>Closed-Date:    Sun May 10 12:56:00 PDT 1998
>Last-Modified:  Tue May 12 12:10:00 PDT 1998
>Originator:     Wolfram Schneider
>Release:        FreeBSD 2.2.5-STABLE i386
>Organization:
>Environment:
>Description:

Sometimes make(1) use exec("command") instead sh -c "command"
This fails for shell build-in commands like `exit'.

>How-To-Repeat:

$ cat Makefile
all:
	exit 1


$ make
exit 1
exit: not found
*** Error code 1
 
Stop.
>Fix:
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Fri May 8 13:08:14 PDT 1998 
State-Changed-Why:  
The canonical way to do this is to use /bin/false rather than 
exit.  Using exit would result in potentially confusing exit codes from make 
which would be A Bad Thing. 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: Wolfram Schneider <wosch@cs.tu-berlin.de>
Cc: wosch@DE.FreeBSD.ORG, freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/6550 
Date: Sat, 09 May 1998 08:45:17 +0200

 In message <19980508230015.42987@panke.de>, Wolfram Schneider writes:
 >On 1998-05-08 13:09:44 -0700, Poul-Henning Kamp wrote:
 >> Synopsis: make(1): shell meta-character optimization incomplete
 >> 
 >> State-Changed-From-To: open->closed
 >> State-Changed-By: phk
 >> State-Changed-When: Fri May 8 13:08:14 PDT 1998
 >> State-Changed-Why: 
 >> The canonical way to do this is to use /bin/false rather than
 >> exit.  Using exit would result in potentially confusing exit codes from make
 >> which would be A Bad Thing.
 >
 >The `potentially confusing exit code' is intentionally.
 >
 >A workaround is to use a meta char to force using sh -c, e.g.
 >the semicolon.
 >
 >	exit 3;
 
 But that doesn't affect makes own exit code, only the exit-code that make 
 detects from the action process.
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 "ttyv0" -- What UNIX calls a $20K state-of-the-art, 3D, hi-res color terminal
State-Changed-From-To: closed->open 
State-Changed-By: wosch 
State-Changed-When: Sun May 10 09:11:56 PDT 1998 
State-Changed-Why:  
The bug applies to all ash(1) builtin commands: 

alias 
bg 
command 
cd 
eval 
exec true 
export name 
fc 
fg 
getopts optstring var 
hash  
jobid 
jobs 
read 
readonly name 
set 
setvar variable value 
shift 
trap true 1 
ulimit 
umask 
unalias 
unset name 
wait 
~ 
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Sun May 10 12:56:00 PDT 1998 
State-Changed-Why:  
what made you think that it should support all of that stuff ? 

make only supports some of the primitives to gain some speed, 
it has never promised to replace your shell entirely. 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: Wolfram Schneider <wosch@cs.tu-berlin.de>
Cc: Bruce Evans <bde@zeta.org.au>, freebsd-bugs@FreeBSD.ORG, wosch@FreeBSD.ORG,
        freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/6550 
Date: Sun, 10 May 1998 22:05:36 +0200

 In message <19980510204452.35461@panke.de>, Wolfram Schneider writes:
 >On 1998-05-11 02:49:33 +1000, Bruce Evans wrote:
 >> >Synopsis: make(1): shell meta-character optimization incomplete
 >> >The bug applies to all ash(1) builtin commands:
 >> 
 >> This shows why it isn't really a bug.  `make' can't be expected
 >> to know about all shell builtins, especially nonstandard ones.
 >> The bug is that `make' doesn't have a POSIX-conformant mode in
 >> which it always execs the shell.  No one would use this mode :-).
 >
 >gmake(1) handle some common builtin commands, e.g. exit and umask.
 >
 
 Then use gmake.
 
 I've closed the PR again.
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 "ttyv0" -- What UNIX calls a $20K state-of-the-art, 3D, hi-res color terminal

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: Wolfram Schneider <wosch@cs.tu-berlin.de>
Cc: wosch@FreeBSD.ORG, freebsd-bugs@FreeBSD.ORG,
        freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/6550 
Date: Mon, 11 May 1998 10:36:33 +0200

 In message <19980510223247.09270@panke.de>, Wolfram Schneider writes:
 >On 1998-05-10 12:57:25 -0700, Poul-Henning Kamp wrote:
 >> Synopsis: make(1): shell meta-character optimization incomplete
 >> 
 >> State-Changed-From-To: open->closed
 >
 >*grumble* 
 >
 >Our make is broken, period! Why did you closed the PR?
 >Please fix the bugs or reopen the PR again! 
 
 Our make is not broken (at least in this particular respect.)
 
 There is not really any reason (apart from speed) for implementing
 the shell commands, consequently it cannot be said to be broken
 because it doesn't.
 
 If you want it to support more builtins, something which I am not
 as such against, while on the other hand I don't see any reason to
 do it, the very least you can do is to submit a patch.
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 "ttyv0" -- What UNIX calls a $20K state-of-the-art, 3D, hi-res color terminal

From: Wolfram Schneider <wosch@cs.tu-berlin.de>
To: Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc: wosch@FreeBSD.ORG, freebsd-bugs@FreeBSD.ORG,
        freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/6550
Date: Mon, 11 May 1998 12:07:19 +0200

 On 1998-05-11 10:36:33 +0200, Poul-Henning Kamp wrote:
 > In message <19980510223247.09270@panke.de>, Wolfram Schneider writes:
 > >On 1998-05-10 12:57:25 -0700, Poul-Henning Kamp wrote:
 > >> Synopsis: make(1): shell meta-character optimization incomplete
 > >> 
 > >> State-Changed-From-To: open-closed
 > >
 > >*grumble* 
 > >
 > >Our make is broken, period! Why did you closed the PR?
 > >Please fix the bugs or reopen the PR again! 
 > 
 > Our make is not broken (at least in this particular respect.)
 
 It is broken.
 
 
 > There is not really any reason (apart from speed) for implementing
 > the shell commands, consequently it cannot be said to be broken
 > because it doesn't.
 
 You did not understand the problem ;-(
 
 The current algorithm  is
 
 	if (no_meta_characters(command))
 		exec(command)
 	else
 		/bin/sh -c "command"
 
 where it should be
 
 	if (no_meta_characters(command) && no_shell_builtin(command))
 		exec(command)
 	else
 		/bin/sh -c "command"
 
 
 > If you want it to support more builtins, something which I am not
 > as such against, while on the other hand I don't see any reason to
 > do it, the very least you can do is to submit a patch.
 
 I got now a patch from Theo de Raadt. I will check if the
 patch works.
 
 -- 
 Wolfram Schneider <wosch@freebsd.org> http://www.freebsd.org/~wosch/

From: woods@zeus.leitch.com (Greg A. Woods)
To: freebsd-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: bin/6550
Date: Tue, 12 May 1998 14:55:58 -0400 (EDT)

 [ On Sun, May 10, 1998 at 12:57:25 (-0700), Poul-Henning Kamp wrote: ]
 > Subject: Re: bin/6550
 >
 > Synopsis: make(1): shell meta-character optimization incomplete
 > 
 > State-Changed-From-To: open-closed
 > State-Changed-By: phk
 > State-Changed-When: Sun May 10 12:56:00 PDT 1998
 > State-Changed-Why: 
 > what made you think that it should support all of that stuff ?
 > 
 > make only supports some of the primitives to gain some speed,
 > it has never promised to replace your shell entirely.
 
 If you want FreeBSD's make to be standards compliant then perhaps the
 following statement will be of help:
 
     Commands will be executed by passing the command line to the command
     interpreter in the same manner as if the string were the argument to
     the XSH specification system() function.
 
 This is from:
 
 	http://www.opengroup.org/onlinepubs/7908799/xcu/make.html
 
 (You might have to go via http://www.UNIX-systems.org/online.html to get
 there though because of the copyright restricitons.)
 
 I think POSIX.2 is slightly more specific about skipping the use of
 system() where possible, though perhaps only in the rationale sections.
 Indeed this was the case in P1003.2 Draft 11.2:
 
  6.2.7.2  Makefile Execution
 
  Command lines shall be processed one at a time by writing the command
  line to the standard output (unless one of the conditions listed below     1
  under ``@'' suppresses the writing) and executing the command(s) in the    1
  line.  A <tab> character may precede the command to standard output.
  Commands shall be executed by passing the command line to the command
  interpreter in the same manner as if the string were the argument to the
  function in 7.1.1 [such as the system() function in the C binding].
 
 (7.1.1 is, of course, "Execute Shell Command")
 
 The relevant part of the rationale from that draft reads:
 
  Some implementations do not use system() for all command lines, as
  required by the POSIX.2 portable makefile format; as a performance
  enhancement, they select lines without shell metacharacters for direct
  execution by execve().  There is no requirement that system() be used
  specifically, but merely that the same results be achieved.  The
  metacharacters typically used to bypass the direct execve() execution
  have been any of:
 
        =  |  ^  (  )  ;  &  <  >  *  ?  [  ]  :  $  `  '  "  \  \n
 
  The default in some advanced versions of make is to group all the command
  lines for a target and execute them using a single shell invocation; the
  System V method is to pass each line individually to a separate shell.
  The single-shell method has the advantages in performance and the lack of
  a requirement for many continued lines.  However, converting to this
  newer method has caused portability problems with many historical
  makefiles, so the behavior with the POSIX makefile is specified to be the
  same as System V's.  It is suggested that the special target .ONESHELL be
  used as an implementation extension to achieve the single-shell grouping
  for a target or group of targets.
 
 -- 
 							Greg A. Woods
 
 +1 416 443-1734      VE3TCP      <gwoods@acm.org>      <robohack!woods>
 Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>

From: woods@zeus.leitch.com (Greg A. Woods@planix.com (Greg A. Woods))
To: freebsd-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: bin/6550
Date: Tue, 12 May 1998 15:06:49 -0400 (EDT)

 [ On Mon, May 11, 1998 at 04:00:03 (-0700), Wolfram Schneider wrote: ]
 > Subject: Re: bin/6550
 >
 >  The current algorithm  is
 >  
 >  	if (no_meta_characters(command))
 >  		exec(command)
 >  	else
 >  		/bin/sh -c "command"
 >  
 >  where it should be
 >  
 >  	if (no_meta_characters(command) && no_shell_builtin(command))
 >  		exec(command)
 >  	else
 >  		/bin/sh -c "command"
 
 Given the POSIX.2 Draft and the OpenGroup XPG specifications, this would
 better be expressed as:
 
  	if (no_meta_characters(command) && no_POSIX_shell_builtins(command))
  		exec(command)
  	else
 		system(command)
 
 -- 
 							Greg A. Woods
 
 +1 416 443-1734      VE3TCP      <gwoods@acm.org>      <robohack!woods>
 Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>
>Unformatted:
