POSIX requires us to print an error message and exit non-zero if
writing to stdout fails. This can only happen if sflag is unset.
MFC after: 3 days
Sponsored by: Klara, Inc.
Paths
| Differential D47020 Authored by des on Oct 8 2024, 10:02 PM.
Details
Summary POSIX requires us to print an error message and exit non-zero if MFC after: 3 days
Diff Detail
Event TimelineHerald added a subscriber: imp. · View Herald TranscriptOct 8 2024, 10:02 PM2024-10-08 22:02:34 (UTC+0) Harbormaster completed remote builds in B59855: Diff 144505.Oct 8 2024, 10:02 PM2024-10-08 22:02:36 (UTC+0) des added a parent revision: D47019: cmp: Style and type issues..Oct 8 2024, 10:02 PM2024-10-08 22:02:37 (UTC+0) Comment Actions
But almost all of them are exiting with a non-zero status. Don't you just need to handle those that exit with status 0? Comment Actions
Strictly speaking, yes- other errors should take precedence over a flush error, even if we could have encountered the flush error first but didn't bother error checking all of the writes to stdout. Comment Actions DIFF_EXIT is non-zero but not an error. Unless -s was specified, it is preceded by a message to stdout, and POSIX requires us to not only exit non-zero but also print an error message to stderr if writing to stdout fails. I suppose this would be clearer if I rewrote cmp to return non-error results back to main so there was only a single non-error exit point, and then try to fflush(stdout) iff !sflag, rather than use atexit(). des edited the summary of this revision. (Show Details)Oct 9 2024, 9:59 AM2024-10-09 09:59:07 (UTC+0) Harbormaster completed remote builds in B59861: Diff 144521.Oct 9 2024, 9:59 AM2024-10-09 09:59:46 (UTC+0) Harbormaster completed remote builds in B59864: Diff 144524.Oct 9 2024, 10:17 AM2024-10-09 10:17:17 (UTC+0) This revision is now accepted and ready to land.Oct 9 2024, 12:03 PM2024-10-09 12:03:10 (UTC+0) Closed by commit rG3c37828ee187: cmp: Check the status of stdout. (authored by des). · Explain WhyOct 9 2024, 12:12 PM2024-10-09 12:12:14 (UTC+0) This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 144532 usr.bin/cmp/cmp.c
usr.bin/cmp/extern.h
usr.bin/cmp/link.c
usr.bin/cmp/misc.c
|
"care must be taken to export any given file system in only one of the instances" sounds more natural to me.