X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fbarrier.c;h=a0326ac697367558acdcc1eabf94881ae74df90e;hb=5806784b5c7618d2a0407effe013b8734ce6917d;hp=4a5544de27d309f0593c34d5fc4e1ccba06d0985;hpb=53290ee39d0b4a61d75df3e7ef9372380352594e;p=elogind.git diff --git a/src/shared/barrier.c b/src/shared/barrier.c index 4a5544de2..a0326ac69 100644 --- a/src/shared/barrier.c +++ b/src/shared/barrier.c @@ -21,13 +21,10 @@ #include #include -#include #include #include #include -#include #include -#include #include #include #include @@ -112,15 +109,24 @@ * Returns: 0 on success, negative error code on failure. */ int barrier_create(Barrier *b) { + _cleanup_(barrier_destroyp) Barrier *staging = b; + int r; + assert(b); - if ((b->me = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) < 0 || - (b->them = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) < 0 || - pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK) < 0) { - barrier_destroy(b); + b->me = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); + if (b->me < 0) + return -errno; + + b->them = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); + if (b->them < 0) + return -errno; + + r = pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK); + if (r < 0) return -errno; - } + staging = NULL; return 0; } @@ -169,7 +175,7 @@ void barrier_set_role(Barrier *b, unsigned int role) { assert(b); assert(role == BARRIER_PARENT || role == BARRIER_CHILD); /* make sure this is only called once */ - assert(b->pipe[1] >= 0 && b->pipe[1] >= 0); + assert(b->pipe[0] >= 0 && b->pipe[1] >= 0); if (role == BARRIER_PARENT) b->pipe[1] = safe_close(b->pipe[1]);