Date: Sun, 26 Jun 2011 19:02:26 -0400 From: jhell <jhell@DataIX.net> To: Jilles Tjoelker <jilles@stack.nl> Cc: freebsd-bugs@freebsd.org Subject: Re: bin/158206: sh(1) doesn't properly return IO errors to conditionals in a script Message-ID: <20110626230226.GB38064@DataIX.net> In-Reply-To: <201106261050.p5QAo2RZ001411@freefall.freebsd.org> References: <201106261050.p5QAo2RZ001411@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <jilles@stack.nl> > 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 <jilles@stack.nl> > 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110626230226.GB38064>