/* Don't leak the pinfd to the container. */
close_prot_errno_disarm(handler->pinfd);
- ret = lxc_sync_wait_parent(handler, START_SYNC_STARTUP);
- if (ret < 0)
+ if (!lxc_sync_wait_parent(handler, START_SYNC_STARTUP))
goto out_warn_father;
/* Unshare CLONE_NEWNET after CLONE_NEWUSER. See
/* Tell the parent task it can begin to configure the container and wait
* for it to finish.
*/
- ret = lxc_sync_barrier_parent(handler, START_SYNC_CONFIGURE);
- if (ret < 0)
+ if (!lxc_sync_barrier_parent(handler, START_SYNC_CONFIGURE))
goto out_error;
if (handler->ns_clone_flags & CLONE_NEWNET) {
}
/* Ask father to setup cgroups and wait for him to finish. */
- ret = lxc_sync_barrier_parent(handler, START_SYNC_CGROUP);
- if (ret < 0)
+ if (!lxc_sync_barrier_parent(handler, START_SYNC_CGROUP))
goto out_error;
/* Unshare cgroup namespace after we have setup our cgroups. If we do it
}
}
- ret = lxc_sync_barrier_parent(handler, START_SYNC_CGROUP_LIMITS);
- if (ret < 0)
+ if (!lxc_sync_barrier_parent(handler, START_SYNC_CGROUP_LIMITS))
goto out_warn_father;
/* Reset the environment variables the user requested in a clear
share_ns = true;
}
- ret = lxc_sync_init(handler);
- if (ret < 0)
+ if (!lxc_sync_init(handler))
return -1;
ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0,
}
}
- ret = lxc_sync_wake_child(handler, START_SYNC_STARTUP);
- if (ret < 0)
+ if (!lxc_sync_wake_child(handler, START_SYNC_STARTUP))
goto out_delete_net;
- ret = lxc_sync_wait_child(handler, START_SYNC_CONFIGURE);
- if (ret < 0)
+ if (!lxc_sync_wait_child(handler, START_SYNC_CONFIGURE))
goto out_delete_net;
if (!cgroup_ops->setup_limits_legacy(cgroup_ops, handler->conf, false)) {
/* Tell the child to continue its initialization. We'll get
* START_SYNC_CGROUP when it is ready for us to setup cgroups.
*/
- ret = lxc_sync_barrier_child(handler, START_SYNC_POST_CONFIGURE);
- if (ret < 0)
+ if (!lxc_sync_barrier_child(handler, START_SYNC_POST_CONFIGURE))
goto out_delete_net;
if (!lxc_list_empty(&conf->limits)) {
}
}
- ret = lxc_sync_barrier_child(handler, START_SYNC_CGROUP_UNSHARE);
- if (ret < 0)
+ if (!lxc_sync_barrier_child(handler, START_SYNC_CGROUP_UNSHARE))
goto out_delete_net;
/*
* lxc_sync_barrier_child to return success, or return a different
* value, causing us to error out).
*/
- ret = lxc_sync_barrier_child(handler, START_SYNC_READY_START);
- if (ret < 0)
+ if (!lxc_sync_barrier_child(handler, START_SYNC_READY_START))
goto out_delete_net;
if (handler->ns_clone_flags & CLONE_NEWNET) {
lxc_log_define(sync, lxc);
-int sync_wait(int fd, int sequence)
+bool sync_wait(int fd, int sequence)
{
int sync = -1;
ssize_t ret;
ret = lxc_read_nointr(fd, &sync, sizeof(sync));
if (ret < 0)
- return log_error_errno(-1, errno, "Sync wait failure");
+ return log_error_errno(false, errno, "Sync wait failure");
if (!ret)
- return 0;
+ return true;
if ((size_t)ret != sizeof(sync))
- return log_error(-1, "Unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync));
+ return log_error(false, "Unexpected sync size: %zu expected %zu", (size_t)ret, sizeof(sync));
if (sync == SYNC_ERROR)
- return log_error(-1, "An error occurred in another process (expected sequence number %d)", sequence);
+ return log_error(false, "An error occurred in another process (expected sequence number %d)", sequence);
if (sync != sequence)
- return log_error(-1, "Invalid sequence number %d. Expected sequence number %d", sync, sequence);
+ return log_error(false, "Invalid sequence number %d. Expected sequence number %d", sync, sequence);
- return 0;
+ return true;
}
-int sync_wake(int fd, int sequence)
+bool sync_wake(int fd, int sequence)
{
int sync = sequence;
if (lxc_write_nointr(fd, &sync, sizeof(sync)) < 0)
- return log_error_errno(-1, errno, "Sync wake failure");
+ return log_error_errno(false, errno, "Sync wake failure");
- return 0;
+ return true;
}
-static int __sync_barrier(int fd, int sequence)
+static bool __sync_barrier(int fd, int sequence)
{
- if (sync_wake(fd, sequence))
- return -1;
+ if (!sync_wake(fd, sequence))
+ return false;
return sync_wait(fd, sequence + 1);
}
}
}
-int lxc_sync_barrier_parent(struct lxc_handler *handler, int sequence)
+bool lxc_sync_barrier_parent(struct lxc_handler *handler, int sequence)
{
TRACE("Child waking parent with sequence %s and waiting for sequence %s",
start_sync_to_string(sequence), start_sync_to_string(sequence + 1));
return __sync_barrier(handler->sync_sock[0], sequence);
}
-int lxc_sync_barrier_child(struct lxc_handler *handler, int sequence)
+bool lxc_sync_barrier_child(struct lxc_handler *handler, int sequence)
{
TRACE("Parent waking child with sequence %s and waiting with sequence %s",
start_sync_to_string(sequence), start_sync_to_string(sequence + 1));
return __sync_barrier(handler->sync_sock[1], sequence);
}
-int lxc_sync_wake_parent(struct lxc_handler *handler, int sequence)
+bool lxc_sync_wake_parent(struct lxc_handler *handler, int sequence)
{
TRACE("Child waking parent with sequence %s", start_sync_to_string(sequence));
return sync_wake(handler->sync_sock[0], sequence);
}
-int lxc_sync_wait_parent(struct lxc_handler *handler, int sequence)
+bool lxc_sync_wait_parent(struct lxc_handler *handler, int sequence)
{
TRACE("Parent waiting for child with sequence %s", start_sync_to_string(sequence));
return sync_wait(handler->sync_sock[0], sequence);
}
-int lxc_sync_wait_child(struct lxc_handler *handler, int sequence)
+bool lxc_sync_wait_child(struct lxc_handler *handler, int sequence)
{
TRACE("Child waiting for parent with sequence %s", start_sync_to_string(sequence));
return sync_wait(handler->sync_sock[1], sequence);
}
-int lxc_sync_wake_child(struct lxc_handler *handler, int sequence)
+bool lxc_sync_wake_child(struct lxc_handler *handler, int sequence)
{
TRACE("Child waking parent with sequence %s", start_sync_to_string(sequence));
return sync_wake(handler->sync_sock[1], sequence);
}
-int lxc_sync_init(struct lxc_handler *handler)
+bool lxc_sync_init(struct lxc_handler *handler)
{
int ret;
ret = socketpair(AF_LOCAL, SOCK_STREAM, 0, handler->sync_sock);
if (ret)
- return log_error_errno(-1, errno, "failed to create synchronization socketpair");
+ return log_error_errno(false, errno, "failed to create synchronization socketpair");
/* Be sure we don't inherit this after the exec */
ret = fcntl(handler->sync_sock[0], F_SETFD, FD_CLOEXEC);
if (ret < 0)
- return log_error_errno(-1, errno, "Failed to make socket close-on-exec");
+ return log_error_errno(false, errno, "Failed to make socket close-on-exec");
TRACE("Initialized synchronization infrastructure");
- return 0;
+ return true;
}
void lxc_sync_fini_child(struct lxc_handler *handler)
#ifndef __LXC_SYNC_H
#define __LXC_SYNC_H
+#include <stdbool.h>
+
#include "compiler.h"
struct lxc_handler;
ATTACH_SYNC_CGROUP = 0,
};
-__hidden extern int lxc_sync_init(struct lxc_handler *handler);
+__hidden extern bool lxc_sync_init(struct lxc_handler *handler);
__hidden extern void lxc_sync_fini(struct lxc_handler *);
__hidden extern void lxc_sync_fini_parent(struct lxc_handler *);
__hidden extern void lxc_sync_fini_child(struct lxc_handler *);
-__hidden extern int lxc_sync_wake_child(struct lxc_handler *, int);
-__hidden extern int lxc_sync_wait_child(struct lxc_handler *, int);
-__hidden extern int lxc_sync_wake_parent(struct lxc_handler *, int);
-__hidden extern int lxc_sync_wait_parent(struct lxc_handler *, int);
-__hidden extern int lxc_sync_barrier_parent(struct lxc_handler *, int);
-__hidden extern int lxc_sync_barrier_child(struct lxc_handler *, int);
-__hidden extern int sync_wait(int fd, int sequence);
-__hidden extern int sync_wake(int fd, int sequence);
+__hidden extern bool lxc_sync_wake_child(struct lxc_handler *, int);
+__hidden extern bool lxc_sync_wait_child(struct lxc_handler *, int);
+__hidden extern bool lxc_sync_wake_parent(struct lxc_handler *, int);
+__hidden extern bool lxc_sync_wait_parent(struct lxc_handler *, int);
+__hidden extern bool lxc_sync_barrier_parent(struct lxc_handler *, int);
+__hidden extern bool lxc_sync_barrier_child(struct lxc_handler *, int);
+__hidden extern bool sync_wait(int fd, int sequence);
+__hidden extern bool sync_wake(int fd, int sequence);
#endif /* __LXC_SYNC_H */