Bug 83024 - sd_readahead retries closing an fd on EINTR
Summary: sd_readahead retries closing an fd on EINTR
Status: RESOLVED WONTFIX
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-24 22:12 UTC by Steven Stewart-Gallus
Modified: 2014-10-04 15:27 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Steven Stewart-Gallus 2014-08-24 22:12:50 UTC
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;
Comment 1 Steven Stewart-Gallus 2014-08-24 22:15:58 UTC
Curiously enough, it's the open that would probably be the actual
function that one might want to retry on EINTR for (it can block
interruptibly on fifos and devices).  It probably wouldn't be a
problem in practise though.
Comment 2 Zbigniew Jedrzejewski-Szmek 2014-10-04 15:27:56 UTC
We removed readahead.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.