From: Christian Brauner Date: Fri, 29 Jan 2021 12:42:47 +0000 (+0100) Subject: attach: use sync_wait()/sync_wake() where applicable X-Git-Tag: lxc-5.0.0~313^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9f0cecfc5f20079d6146deefd0ff380f61c6bd0;p=thirdparty%2Flxc.git attach: use sync_wait()/sync_wake() where applicable Signed-off-by: Christian Brauner --- diff --git a/src/lxc/attach.c b/src/lxc/attach.c index 46cd2405c..58060b442 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -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"); diff --git a/src/lxc/sync.h b/src/lxc/sync.h index 35a942b39..f81cb1e90 100644 --- a/src/lxc/sync.h +++ b/src/lxc/sync.h @@ -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);