From owner-svn-src-all@FreeBSD.ORG Wed Dec 12 22:01:11 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 645497A2; Wed, 12 Dec 2012 22:01:11 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 436DC8FC14; Wed, 12 Dec 2012 22:01:11 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBCM1Bi4059807; Wed, 12 Dec 2012 22:01:11 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBCM1Aeh059801; Wed, 12 Dec 2012 22:01:10 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201212122201.qBCM1Aeh059801@svn.freebsd.org> From: Jilles Tjoelker Date: Wed, 12 Dec 2012 22:01:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244162 - in head: bin/sh tools/regression/bin/sh/errors X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 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: Wed, 12 Dec 2012 22:01:11 -0000 Author: jilles Date: Wed Dec 12 22:01:10 2012 New Revision: 244162 URL: http://svnweb.freebsd.org/changeset/base/244162 Log: sh: Detect and flag write errors on stdout in builtins. If there is a write error on stdout, a message will be printed (to stderr) and the exit status will be changed to 2 if it would have been 0 or 1. PR: bin/158206 Added: head/tools/regression/bin/sh/errors/write-error1.0 (contents, props changed) Modified: head/bin/sh/eval.c head/bin/sh/output.c head/bin/sh/output.h Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Wed Dec 12 20:55:30 2012 (r244161) +++ head/bin/sh/eval.c Wed Dec 12 22:01:10 2012 (r244162) @@ -1070,6 +1070,7 @@ evalcommand(union node *cmd, int flags, } handler = &jmploc; redirect(cmd->ncmd.redirect, mode); + outclearerror(out1); /* * If there is no command word, redirection errors should * not be fatal but assignment errors should. @@ -1085,6 +1086,11 @@ evalcommand(union node *cmd, int flags, builtin_flags = flags; exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv); flushall(); + if (outiserror(out1)) { + warning("write error on stdout"); + if (exitstatus == 0 || exitstatus == 1) + exitstatus = 2; + } cmddone: if (argc > 0) bltinunsetlocale(); Modified: head/bin/sh/output.c ============================================================================== --- head/bin/sh/output.c Wed Dec 12 20:55:30 2012 (r244161) +++ head/bin/sh/output.c Wed Dec 12 22:01:10 2012 (r244162) @@ -239,6 +239,20 @@ freestdout(void) } +int +outiserror(struct output *file) +{ + return (file->flags & OUTPUT_ERR); +} + + +void +outclearerror(struct output *file) +{ + file->flags &= ~OUTPUT_ERR; +} + + void outfmt(struct output *file, const char *fmt, ...) { Modified: head/bin/sh/output.h ============================================================================== --- head/bin/sh/output.h Wed Dec 12 20:55:30 2012 (r244161) +++ head/bin/sh/output.h Wed Dec 12 22:01:10 2012 (r244162) @@ -66,6 +66,8 @@ void emptyoutbuf(struct output *); void flushall(void); void flushout(struct output *); void freestdout(void); +int outiserror(struct output *); +void outclearerror(struct output *); void outfmt(struct output *, const char *, ...) __printflike(2, 3); void out1fmt(const char *, ...) __printflike(1, 2); void out2fmt_flush(const char *, ...) __printflike(1, 2); Added: head/tools/regression/bin/sh/errors/write-error1.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/errors/write-error1.0 Wed Dec 12 22:01:10 2012 (r244162) @@ -0,0 +1,3 @@ +# $FreeBSD$ + +! echo >&- 2>/dev/null