attach: introduce sync_wait_pid() and sync_wake_pid()

parent a9f0cecf
...@@ -1027,6 +1027,16 @@ static inline void lxc_attach_terminal_close_log(struct lxc_terminal *terminal) ...@@ -1027,6 +1027,16 @@ static inline void lxc_attach_terminal_close_log(struct lxc_terminal *terminal)
close_prot_errno_disarm(terminal->log_fd); close_prot_errno_disarm(terminal->log_fd);
} }
static inline bool sync_wake_pid(int fd, pid_t pid)
{
return lxc_write_nointr(fd, &pid, sizeof(pid_t)) == sizeof(pid_t);
}
static inline bool sync_wait_pid(int fd, pid_t *pid)
{
return lxc_read_nointr(fd, pid, sizeof(pid_t)) == sizeof(pid_t);
}
int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
void *exec_payload, lxc_attach_options_t *options, void *exec_payload, lxc_attach_options_t *options,
pid_t *attached_process) pid_t *attached_process)
...@@ -1249,8 +1259,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, ...@@ -1249,8 +1259,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
lxc_attach_terminal_close_pts(&terminal); lxc_attach_terminal_close_pts(&terminal);
/* Tell grandparent the pid of the pid of the newly created child. */ /* Tell grandparent the pid of the pid of the newly created child. */
ret = lxc_write_nointr(ipc_sockets[1], &pid, sizeof(pid)); if (!sync_wake_pid(ipc_sockets[1], pid)) {
if (ret != sizeof(pid)) {
/* If this really happens here, this is very unfortunate, since /* If this really happens here, this is very unfortunate, since
* the parent will not know the pid of the attached process and * the parent will not know the pid of the attached process and
* will not be able to wait for it (and we won't either due to * will not be able to wait for it (and we won't either due to
...@@ -1331,8 +1340,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function, ...@@ -1331,8 +1340,7 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
TRACE("Told intermediate process to start initializing"); TRACE("Told intermediate process to start initializing");
/* Get pid of attached process from intermediate process. */ /* Get pid of attached process from intermediate process. */
ret = lxc_read_nointr(ipc_sockets[0], &attached_pid, sizeof(attached_pid)); if (!sync_wait_pid(ipc_sockets[0], &attached_pid))
if (ret != sizeof(attached_pid))
goto close_mainloop; goto close_mainloop;
TRACE("Received pid %d of attached process in parent pid namespace", attached_pid); TRACE("Received pid %d of attached process in parent pid namespace", attached_pid);
......
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