[systemd-bugs] [Bug 83024] New: sd_readahead retries closing an fd on EINTR
bugzilla-daemon at freedesktop.org
bugzilla-daemon at freedesktop.org
Sun Aug 24 15:12:50 PDT 2014
https://bugs.freedesktop.org/show_bug.cgi?id=83024
Priority: medium
Bug ID: 83024
Assignee: systemd-bugs at lists.freedesktop.org
Summary: sd_readahead retries closing an fd on EINTR
QA Contact: systemd-bugs at lists.freedesktop.org
Severity: normal
Classification: Unclassified
OS: All
Reporter: sstewartgallus00 at mylangara.bc.ca
Hardware: Other
Status: NEW
Version: unspecified
Component: general
Product: systemd
The code in the touch function of sd-readahead.c:
for (;;) {
if (close(fd) >= 0)
break;
if (errno != EINTR)
return -errno;
}
The ultra-paranoid ultra portable correct code:
/*
* The state of a file descriptor after close gives an EINTR error
* is unspecified by POSIX so this function avoids the problem by
* simply blocking all signals.
*/
int errnum;
sigset_t sigset;
/* First use the signal set for the full set */
sigfillset(&sigset);
pthread_sigmask(SIG_BLOCK, &sigset, &sigset);
/* Then reuse the signal set for the old set */
if (-1 == close(fd)) {
errnum = errno;
assert(errnum != 0);
} else {
errnum = 0;
}
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
return errnum;
The system specific but mostly standard code you probably want:
int errnum;
if (-1 == close(fd)) {
errnum = errno;
assert(errnum != 0);
/* On Linux and probably most platforms EINTR can't happen or
* would close the file succesfully anyways. */
if (EINTR == errnum) {
errnum = 0;
}
} else {
errnum = 0;
}
return errnum;
--
You are receiving this mail because:
You are the QA Contact for the bug.
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-bugs/attachments/20140824/477e89e0/attachment.html>
More information about the systemd-bugs
mailing list