HomeFreeBSD

lam: fix using stdin more than once

Description

lam: fix using stdin more than once

Historically, lam(1) closes stdin once we've hit EOF the first time,
which would stop it from doing anything else on subsequent gatherline()
calls with another openfile. However, this doesn't seem to be strictly
necessary- the EOF flag on FILEs is quite sticky, so we can assume that
a subsequent fgetc(stdin) will flag EOF properly.

This 'fixes' the below-referenced commit in the sense that it surfaced
this problem as a fatal error, but the issue was pre-existing. If we
do lam - -, then one gatherline() will fclose(stdin) and set ip->eof
for *that* openfile, while the next one will then observe that
STDIN_FILENO has been closed and turn it into an EBADF.

Add a few tests that were easy to snipe while I'm here, but I haven't
aimed for anything close to exhaustive because I think re@ would prefer
this fix go in sooner rather than later to land in 15.0.

Minor style adjustment for the previous commit while we're here.

Reported by: cperciva
Discussed with: jrtc27
Reviewed by: des, jlduran
Fixes: 4472fd66d006 ("lam: fail on I/O errors")
MFC after: 3 days (tentative)
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D53750

Details

Provenance
kevansAuthored on Fri, Nov 14, 2:36 PM
Reviewer
rG4472fd66d006: lam: fail on I/O errors
Differential Revision
D53750: lam: fix using stdin more than once
Parents
rG0eca7fa1c96f: exterror.9 man page
Branches
Unknown
Tags
Unknown