Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Sep 2017 18:26:00 -0700
From:      Ngie Cooper <yaneurabeya@gmail.com>
To:        Conrad Meyer <cem@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r323123 - in head/usr.bin/tail: . tests
Message-ID:  <F920D5F0-7DCA-4913-B527-ED6E68F1B214@gmail.com>
In-Reply-To: <201709012237.v81Mbnp3049853@repo.freebsd.org>
References:  <201709012237.v81Mbnp3049853@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

> On Sep 1, 2017, at 15:37, Conrad Meyer <cem@FreeBSD.org> wrote:
>=20
> Author: cem
> Date: Fri Sep  1 22:37:49 2017
> New Revision: 323123
> URL: https://svnweb.freebsd.org/changeset/base/323123
>=20
> Log:
>  tail(1): Do not print bogus errno string
>=20
>  In the case where write(2) does not return -1, it does not initialize err=
no.
>  This can happen when a broken pipe causes a short write.
>=20
>  I attempted to adapt the submitted test case to ATF but could not figure o=
ut
>  how to make the test run in the ATF environment.  So the aborted test is
>  left disabled, in case someone would like to run it manually or fix it.
>=20
>  PR:        221976
>  Submitted by:    <martin AT lispworks.com> (earlier version)
>  Sponsored by:    Dell EMC Isilon
>=20
> Modified:
>  head/usr.bin/tail/extern.h
>  head/usr.bin/tail/tests/tail_test.sh
>=20
> Modified: head/usr.bin/tail/extern.h
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
> --- head/usr.bin/tail/extern.h    Fri Sep  1 22:04:45 2017    (r323122)
> +++ head/usr.bin/tail/extern.h    Fri Sep  1 22:37:49 2017    (r323123)
> @@ -32,9 +32,15 @@
>  */
>=20
> #define    WR(p, size) do { \
> -    if (write(STDOUT_FILENO, p, size) !=3D (ssize_t)size) \
> -        oerr(); \
> -    } while(0)
> +    ssize_t res; \
> +    res =3D write(STDOUT_FILENO, p, size); \
> +    if (res !=3D (ssize_t)size) { \
> +        if (res =3D=3D -1) \
> +            oerr(); \
> +        else \
> +            errx(1, "stdout"); \
> +    } \
> +} while (0)
>=20
> #define TAILMAPLEN (4<<20)
>=20
>=20
> Modified: head/usr.bin/tail/tests/tail_test.sh
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
> --- head/usr.bin/tail/tests/tail_test.sh    Fri Sep  1 22:04:45 2017    (r=
323122)
> +++ head/usr.bin/tail/tests/tail_test.sh    Fri Sep  1 22:37:49 2017    (r=
323123)
> @@ -215,7 +215,20 @@ longfile_rn2500_body()
>    atf_check cmp expectfile outpipe
> }
>=20
> +atf_test_case broken_pipe
> +broken_pipe_head()
> +{
> +    atf_set "descr" "Do not print bogus errno based output on short write=
s"
> +}
> +broken_pipe_body()
> +{
> +    atf_expect_fail "Can't seem to get testcase to work in test environme=
nt.  Reproduces easily in interactive shell."
>=20
> +    seq -f '%128g' 1 1000 > ints
> +    atf_check -s exit:1 -o ignore -e "inline:tail: stdout" tail -n 856 in=
ts | awk '{ exit }'

Use need to use -x to run the command through the shell, e.g.

atf_check ... -x 'tail 856 ints| awk "{exit}"'

What the original pattern does is pipes atf_check to awk--which probably isn=
't what you want.

Seems like it could be written to not use a temporary file too.. I'll have t=
o think about this.

-Ngie=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F920D5F0-7DCA-4913-B527-ED6E68F1B214>