Skip to content

Fix read_all() and write_all() to always set errno on failure#86

Open
vasild wants to merge 2 commits into
rustyrussell:masterfrom
vasild:fix-read_write_all-errno
Open

Fix read_all() and write_all() to always set errno on failure#86
vasild wants to merge 2 commits into
rustyrussell:masterfrom
vasild:fix-read_write_all-errno

Conversation

@vasild

@vasild vasild commented Dec 11, 2019

Copy link
Copy Markdown

Make sure errno is always set if false is to be returned. Also retry if write(2) returns 0.

read(2) will return 0 to designate end-of-file and in this case it will
not set errno, but read_all() will return false, leaving errno as it
were before the call.

An EOF is not an error for read(2) itself, but read_all() is supposed to
read exactly the requested number of bytes (not less), so set errno to
EBADMSG "Bad message" in this case.
write(2) could return 0 (no bytes written), but that is not an error
condition, write(2) will not set errno, and the operation should be
retried.

This patch, in addition to making a retry on 0, also ensures that errno
is always set whenever false is returned from write_all().
@vasild

vasild commented Dec 31, 2019

Copy link
Copy Markdown
Author

About the failing travis tests: I can reproduce some hangs (maybe the same as in travis, maybe not) even without this patch, using 39b46a0 (latest master). Just compile and run make check or directly:

$ tools/ccanlint/ccanlint -s --deps-fail-ignore ccan/talloc/

or

$ tools/ccanlint/ccanlint -s --deps-fail-ignore ccan/failtest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant