]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: use sync_wait()/sync_wake() where applicable
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 12:42:47 +0000 (13:42 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 29 Jan 2021 12:43:25 +0000 (13:43 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c
src/lxc/sync.h

index 46cd2405cce977430443af502fd302ff14ecd9eb..58060b44234ba29545763187aa04321a9908b4cc 100644 (file)
@@ -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");
index 35a942b39b8ec3511edcccb7346665707785c7c3..f81cb1e904715d6db94e99cd195641ebfffbccf8 100644 (file)
@@ -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);