From owner-freebsd-bugs@FreeBSD.ORG Sun Jun 26 23:02:33 2011 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B889F1065676 for ; Sun, 26 Jun 2011 23:02:33 +0000 (UTC) (envelope-from jhellenthal@gmail.com) Received: from mail-iy0-f182.google.com (mail-iy0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id 712388FC0C for ; Sun, 26 Jun 2011 23:02:33 +0000 (UTC) Received: by iyb11 with SMTP id 11so5131294iyb.13 for ; Sun, 26 Jun 2011 16:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to; bh=CgsMOSf1KdIQFmvbrdtpVBUjSN0/IP1zJUtWHywRQ/g=; b=YyMDPXayDWQwMiBMqREUWrFccsA2DFR/H6hiDe8dZskDWmxWqH4MqKvKgAoASJZ3nH Q0aW1TId/3D+6IX/JiKE5GZZYDmO8bBhy4wXEcv/wkVNDrcRbhOkO54tIzWQKFdWlDV0 Y0bTLmEz/KxsK8dK6PFxE4fHS5EGGkfFy7yjw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to; b=TEztv8bAGu1qyriNZVRvmsTkyl5ibbF/vgEU1OjXq3fxiasxGLdk/+kJZLQll+Cxw9 knyckrkW4WXXm0BVSUdo4hwtnq73948DbHu8JmRMHVamsc4hnWcNhBsZ84N3gqdRE9rK RslM3ZZ4Qk1nIuBjFUBe9uk1aJ2A8b8HzVRqQ= Received: by 10.42.209.199 with SMTP id gh7mr5766022icb.480.1309129352626; Sun, 26 Jun 2011 16:02:32 -0700 (PDT) Received: from disbatch.dataix.local (adsl-99-190-86-179.dsl.klmzmi.sbcglobal.net [99.190.86.179]) by mx.google.com with ESMTPS id a9sm4791142icy.18.2011.06.26.16.02.30 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 26 Jun 2011 16:02:31 -0700 (PDT) Sender: "J. Hellenthal" Received: from disbatch.dataix.local (localhost [127.0.0.1]) by disbatch.dataix.local (8.14.5/8.14.5) with ESMTP id p5QN2SF4048760 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 26 Jun 2011 19:02:28 -0400 (EDT) (envelope-from jhell@DataIX.net) Received: (from jhell@localhost) by disbatch.dataix.local (8.14.5/8.14.5/Submit) id p5QN2Qhj048759; Sun, 26 Jun 2011 19:02:26 -0400 (EDT) (envelope-from jhell@DataIX.net) Date: Sun, 26 Jun 2011 19:02:26 -0400 From: jhell To: Jilles Tjoelker Message-ID: <20110626230226.GB38064@DataIX.net> References: <201106261050.p5QAo2RZ001411@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZGiS0Q5IWpPtfppv" Content-Disposition: inline In-Reply-To: <201106261050.p5QAo2RZ001411@freefall.freebsd.org> Cc: freebsd-bugs@freebsd.org Subject: Re: bin/158206: sh(1) doesn't properly return IO errors to conditionals in a script X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jun 2011 23:02:33 -0000 --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jun 26, 2011 at 10:50:02AM +0000, Jilles Tjoelker wrote: > The following reply was made to PR bin/158206; it has been noted by GNATS. >=20 > From: Jilles Tjoelker > To: bug-followup@FreeBSD.org, culrich@csnstores.com > Cc: =20 > Subject: Re: bin/158206: sh(1) doesn't properly return IO errors to > conditionals in a script > Date: Sun, 26 Jun 2011 12:41:00 +0200 >=20 > Thank you for your bug report. > =20 > The below patch should fix the problem. It applies to 9-current only. It > could be changed to apply to 8-stable but I will not commit this change > to 8-stable anyway. It is even a bit late for 9.x, one week into code > slush. > =20 > commit 22f46c6d493531fc8df124675598edbfb9eb8130 > Author: Jilles Tjoelker > Date: Sun Jun 26 12:25:07 2011 +0200 > =20 > sh: Detect and flag write errors on stdout in builtins. > =20 > PR: bin/158206 > =20 > diff --git a/bin/sh/eval.c b/bin/sh/eval.c > index d5da7d3..8330094 100644 > --- a/bin/sh/eval.c > +++ b/bin/sh/eval.c > @@ -1000,6 +1000,7 @@ evalcommand(union node *cmd, int flags, struct bac= kcmd *backcmd) > } > handler =3D &jmploc; > redirect(cmd->ncmd.redirect, mode); > + outclearerror(out1); > /* > * If there is no command word, redirection errors should > * not be fatal but assignment errors should. > @@ -1015,6 +1016,11 @@ evalcommand(union node *cmd, int flags, struct ba= ckcmd *backcmd) > builtin_flags =3D flags; > exitstatus =3D (*builtinfunc[cmdentry.u.index])(argc, argv); > flushall(); > + if (outiserror(out1)) { > + warning("write error on stdout"); > + if (exitstatus =3D=3D 0 || exitstatus =3D=3D 1) > + exitstatus =3D 2; > + } > cmddone: > if (argc > 0) > bltinunsetlocale(); > diff --git a/bin/sh/output.c b/bin/sh/output.c > index b4dab51..d26adce 100644 > --- a/bin/sh/output.c > +++ b/bin/sh/output.c > @@ -239,6 +239,20 @@ freestdout(void) > } > =20 > =20 > +int > +outiserror(struct output *file) > +{ > + return (file->flags & OUTPUT_ERR); > +} > + > + > +void > +outclearerror(struct output *file) > +{ > + file->flags &=3D ~OUTPUT_ERR; > +} > + > + > void > outfmt(struct output *file, const char *fmt, ...) > { > diff --git a/bin/sh/output.h b/bin/sh/output.h > index 5e3b048..51974d8 100644 > --- a/bin/sh/output.h > +++ b/bin/sh/output.h > @@ -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); > diff --git a/tools/regression/bin/sh/errors/write-error1.0 b/tools/regre= ssion/bin/sh/errors/write-error1.0 > new file mode 100644 > index 0000000..fcb52e7 > --- /dev/null > +++ b/tools/regression/bin/sh/errors/write-error1.0 > @@ -0,0 +1,3 @@ > +# $FreeBSD$ > + > +! echo >&- 2>/dev/null > =20 If someone really wants this on 8/stable feel free to knock off an email reply to this message and Ill see what I can come up with and post a URL reply back with the patch once complete. --ZGiS0Q5IWpPtfppv Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (FreeBSD) Comment: http://bit.ly/0x89D8547E iQEcBAEBAgAGBQJOB7p/AAoJEJBXh4mJ2FR+g4IH/jk/wdrsYiaCcRGUWAmGXXLV Kt0o94jidSFlAJyjZBynkPVmu4Yc4R+w3jQBX5eshDeDEkvOJubZn7G4Dt3oOS8L 2dod59y9ukMVTs8N/9rejKkcLGXd9VE0Dac7v+FShe6re3boZov3qpyItzE9NCec FyCbQPDFX72HwaUjHrw0/vbIx7hkvhdnFA0LJ3keeAA8CozG0fFx9mP0dq4OVbv5 xbT+VfxvQhN0HRrxXa0AICqsYbqm0+MdPemBCi07Kam/BV4a76ClzDqo4kQ1Nbq4 +KOllB7fRoVOITbe9Q2KmZYxBfSTgMA6uQWhkQQoM1yYjRKCzOkZW2+Frju6mBA= =Zr58 -----END PGP SIGNATURE----- --ZGiS0Q5IWpPtfppv--