From owner-svn-src-all@FreeBSD.ORG Sat Mar 13 22:53:18 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40BEB106566C; Sat, 13 Mar 2010 22:53:18 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 155128FC08; Sat, 13 Mar 2010 22:53:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2DMrHK0058367; Sat, 13 Mar 2010 22:53:17 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2DMrHEe058364; Sat, 13 Mar 2010 22:53:17 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201003132253.o2DMrHEe058364@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 13 Mar 2010 22:53:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205138 - in head: bin/sh tools/regression/bin/sh/errors X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Mar 2010 22:53:18 -0000 Author: jilles Date: Sat Mar 13 22:53:17 2010 New Revision: 205138 URL: http://svn.freebsd.org/changeset/base/205138 Log: sh: Do not abort on a redirection error if there is no command word. Although simple commands without a command word (only assignments and/or redirections) are much like special builtins, POSIX and most shells seem to agree that redirection errors should not abort the shell in this case. Of course, the assignments persist and assignment errors are fatal. To get the old behaviour portably, use the ':' special builtin. To get the new behaviour portably, given that there are no assignments, use the 'true' regular builtin. Added: head/tools/regression/bin/sh/errors/redirection-error4.0 (contents, props changed) Modified: head/bin/sh/eval.c Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Sat Mar 13 22:37:07 2010 (r205137) +++ head/bin/sh/eval.c Sat Mar 13 22:53:17 2010 (r205138) @@ -680,7 +680,7 @@ evalcommand(union node *cmd, int flags, /* Variable assignment(s) without command */ cmdentry.cmdtype = CMDBUILTIN; cmdentry.u.index = BLTINCMD; - cmdentry.special = 1; + cmdentry.special = 0; } else { static const char PATH[] = "PATH="; int cmd_flags = 0, bltinonly = 0; @@ -891,6 +891,12 @@ evalcommand(union node *cmd, int flags, } handler = &jmploc; redirect(cmd->ncmd.redirect, mode); + /* + * If there is no command word, redirection errors should + * not be fatal but assignment errors should. + */ + if (argc == 0 && !(flags & EV_BACKCMD)) + cmdentry.special = 1; if (cmdentry.special) listsetvar(cmdenviron); commandname = argv[0]; Added: head/tools/regression/bin/sh/errors/redirection-error4.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/errors/redirection-error4.0 Sat Mar 13 22:53:17 2010 (r205138) @@ -0,0 +1,7 @@ +# $FreeBSD$ +# A redirection error should not abort the shell if there is no command word. +exec 2>/dev/null +