attach: use sync_wait()/sync_wake() where applicable

parent 946a0c6d
......@@ -42,6 +42,7 @@
#include "mount_utils.h"
#include "namespace.h"
#include "process_utils.h"
#include "sync.h"
#include "syscall_wrappers.h"
#include "terminal.h"
#include "utils.h"
......@@ -1032,7 +1033,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
{
int ret_parent = -1;
struct lxc_epoll_descr descr = {};
int ret, status;
int ret;
char *name, *lxcpath, *new_cwd;
int ipc_sockets[2];
pid_t attached_pid, pid, to_cleanup_pid;
......@@ -1176,8 +1177,8 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
}
/* Wait for the parent to have setup cgroups. */
ret = lxc_read_nointr(ipc_sockets[1], &status, sizeof(status));
if (ret != sizeof(status)) {
ret = sync_wait(ipc_sockets[1], ATTACH_SYNC_CGROUP);
if (ret) {
shutdown(ipc_sockets[1], SHUT_RDWR);
put_attach_context(ctx);
_exit(EXIT_FAILURE);
......@@ -1323,9 +1324,8 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
}
/* Let the child process know to go ahead. */
status = 0;
ret = lxc_write_nointr(ipc_sockets[0], &status, sizeof(status));
if (ret != sizeof(status))
ret = sync_wake(ipc_sockets[0], ATTACH_SYNC_CGROUP);
if (ret)
goto close_mainloop;
TRACE("Told intermediate process to start initializing");
......
......@@ -7,7 +7,11 @@
struct lxc_handler;
enum {
enum /* generic */ {
SYNC_ERROR = -1 /* Used to report errors from another process */
};
enum /* start */ {
START_SYNC_STARTUP = 0,
START_SYNC_CONFIGURE = 1,
START_SYNC_POST_CONFIGURE = 2,
......@@ -17,7 +21,10 @@ enum {
START_SYNC_READY_START = 6,
START_SYNC_RESTART = 7,
START_SYNC_POST_RESTART = 8,
SYNC_ERROR = -1 /* Used to report errors from another process */
};
enum /* attach */ {
ATTACH_SYNC_CGROUP = 0,
};
__hidden extern int lxc_sync_init(struct lxc_handler *handler);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment