From nobody@FreeBSD.org  Fri Nov 11 14:53:20 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C005F16A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Nov 2005 14:53:20 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7489643D4C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Nov 2005 14:53:20 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id jABErKDe006918
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Nov 2005 14:53:20 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id jABErKbq006914;
	Fri, 11 Nov 2005 14:53:20 GMT
	(envelope-from nobody)
Message-Id: <200511111453.jABErKbq006914@www.freebsd.org>
Date: Fri, 11 Nov 2005 14:53:20 GMT
From: Ed Maste <emaste@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Sh(1) aborts if builtin echo redirection fails
X-Send-Pr-Version: www-2.3

>Number:         88845
>Category:       bin
>Synopsis:       Sh(1) aborts if builtin echo redirection fails
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    stefanf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 11 15:00:25 GMT 2005
>Closed-Date:    Sat Jun 03 15:42:59 GMT 2006
>Last-Modified:  Sat Jun 03 15:42:59 GMT 2006
>Originator:     Ed Maste
>Release:        7.0-CURRENT
>Organization:
>Environment:
>Description:
A failed redirection of builtin echo from sh(1) causes sh to abort after printing the error message.  I would expect the script below to output "done" but it does not.
>How-To-Repeat:
Run this script:

#!/bin/sh
touch /tmp/foo
chmod 000 /tmp/foo
echo > /tmp/foo
echo done

>Fix:
This patch works around the problem but a better fix is needed to be POSIX compliant I'm told.

--- eval.c.orig Tue Apr  6 19:06:51 2004
+++ eval.c      Wed Nov  9 08:40:56 2005
@@ -807,7 +807,6 @@
                        memout.bufsize = 64;
                        mode |= REDIR_BACKQ;
                }
-               redirect(cmd->ncmd.redirect, mode);
                savecmdname = commandname;
                cmdenviron = varlist.list;
                e = -1;
@@ -818,6 +817,7 @@
                }
                savehandler = handler;
                handler = &jmploc;
+               redirect(cmd->ncmd.redirect, mode);
                commandname = argv[0];
                argptr = argv + 1;
                optptr = NULL;                  /* initialize nextopt */

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->stefanf 
Responsible-Changed-By: emaste 
Responsible-Changed-When: Fri Nov 11 15:01:19 GMT 2005 
Responsible-Changed-Why:  
Stefan said he'll take cere of it. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=88845 

From: Ed Maste <emaste@phaedrus.sandvine.ca>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/88845 : Sh(1) aborts if builtin echo redirection fails
Date: Mon, 27 Mar 2006 14:08:20 -0500

 Note that according to the open group shell spec[1], a redirection
 error shall exit for a special built-in[2] and shall not exit for other
 utilities.  Since echo is not a special built-in, I assume sh should
 not abort on a redirection error on echo.
 
 [1] http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_08
 [2] http://www.opengroup.org/onlinepubs/000095399/idx/sbi.html

From: Stefan Farfeleder <stefan@fafoe.narf.at>
To: bug-followup@freebsd.org
Cc: Ed Maste <emaste@phaedrus.sandvine.ca>
Subject: Re: bin/88845 : Sh(1) aborts if builtin echo redirection fails
Date: Mon, 27 Mar 2006 23:32:45 +0200

 On Mon, Mar 27, 2006 at 07:10:22PM +0000, Ed Maste wrote:
 > The following reply was made to PR bin/88845; it has been noted by GNATS.
 > 
 > From: Ed Maste <emaste@phaedrus.sandvine.ca>
 > To: bug-followup@freebsd.org
 > Cc:  
 > Subject: Re: bin/88845 : Sh(1) aborts if builtin echo redirection fails
 > Date: Mon, 27 Mar 2006 14:08:20 -0500
 > 
 >  Note that according to the open group shell spec[1], a redirection
 >  error shall exit for a special built-in[2] and shall not exit for other
 >  utilities.  Since echo is not a special built-in, I assume sh should
 >  not abort on a redirection error on echo.
 >  
 >  [1] http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_08
 >  [2] http://www.opengroup.org/onlinepubs/000095399/idx/sbi.html
 
 Right.  What needs to be done is to teach sh about the distinction
 between special built-ins and "ordinary" built-ins.  I plan to borrow
 some code from NetBSD (IIRC they use -s in builtins.def for special
 built-ins) and to treat redirection differently using that information.
 Unfortunately I haven't found time for that yet.
 
 Stefan

From: Ed Maste <emaste@phaedrus.sandvine.ca>
To: Stefan Farfeleder <stefan@fafoe.narf.at>
Cc: bug-followup@freebsd.org
Subject: Re: bin/88845 : Sh(1) aborts if builtin echo redirection fails
Date: Mon, 27 Mar 2006 16:48:14 -0500

 On Mon, Mar 27, 2006 at 11:32:45PM +0200, Stefan Farfeleder wrote:
 
 > Right.  What needs to be done is to teach sh about the distinction
 > between special built-ins and "ordinary" built-ins.  I plan to borrow
 > some code from NetBSD (IIRC they use -s in builtins.def for special
 > built-ins) and to treat redirection differently using that information.
 > Unfortunately I haven't found time for that yet.
 
 No problem, one of my coworkers just ran into this again and I couldn't
 remember the details (nor find the email I exchanged with you previously)
 so I went to look it up again.
 
 -ed
State-Changed-From-To: open->patched 
State-Changed-By: stefanf 
State-Changed-When: Sun Apr 9 12:28:45 UTC 2006 
State-Changed-Why:  
Fixed in current. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=88845 
State-Changed-From-To: patched->closed 
State-Changed-By: stefanf 
State-Changed-When: Sat Jun 3 15:42:25 UTC 2006 
State-Changed-Why:  
Just merged to RELENG_6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=88845 
>Unformatted:
