Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vasild
Copy link

@vasild vasild commented Dec 11, 2019

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
Copy link
Author

vasild commented Dec 31, 2019

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