mirror of
https://github.com/systemd/systemd.git
synced 2025-08-30 05:49:54 +03:00
barrier: fix up constructor error handling
We cannot rely on "errno" to be non-zero on failure, if we perform multiple glibc calls. That is, if the first eventfd() call fails, but the second succeeds, we cleanup the barrier but return 0. Fix this by always testing the return value immediately. This should also fix all the coverity warnings.
This commit is contained in:
@ -112,15 +112,24 @@
|
|||||||
* Returns: 0 on success, negative error code on failure.
|
* Returns: 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
int barrier_create(Barrier *b) {
|
int barrier_create(Barrier *b) {
|
||||||
|
_cleanup_(barrier_destroyp) Barrier *staging = b;
|
||||||
|
int r;
|
||||||
|
|
||||||
assert(b);
|
assert(b);
|
||||||
|
|
||||||
if ((b->me = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) < 0 ||
|
b->me = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
||||||
(b->them = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)) < 0 ||
|
if (b->me < 0)
|
||||||
pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK) < 0) {
|
|
||||||
barrier_destroy(b);
|
|
||||||
return -errno;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ struct Barrier {
|
|||||||
int barrier_create(Barrier *obj);
|
int barrier_create(Barrier *obj);
|
||||||
void barrier_destroy(Barrier *b);
|
void barrier_destroy(Barrier *b);
|
||||||
|
|
||||||
|
DEFINE_TRIVIAL_CLEANUP_FUNC(Barrier*, barrier_destroy);
|
||||||
|
|
||||||
void barrier_set_role(Barrier *b, unsigned int role);
|
void barrier_set_role(Barrier *b, unsigned int role);
|
||||||
|
|
||||||
bool barrier_place(Barrier *b);
|
bool barrier_place(Barrier *b);
|
||||||
|
Reference in New Issue
Block a user