Skip to content

Commit

Permalink
Reimplement lxc_wait_for_pid_status as it is no longer exported by li…
Browse files Browse the repository at this point in the history
…blxc

Signed-off-by: Jakub Skokan <[email protected]>
  • Loading branch information
aither64 committed Oct 15, 2020
1 parent 60e87d4 commit 2d171f9
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions ext/lxc/lxc.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
#define RELEASING_GVL2(func, arg, killfunc, killarg) func(arg)
#endif

extern int lxc_wait_for_pid_status(pid_t pid);

static VALUE Container;
static VALUE Error;

Expand Down Expand Up @@ -677,10 +675,30 @@ lxc_attach_parse_options(VALUE rb_opts)
return NULL;
}

static int
wait_for_pid_status(pid_t pid)
{
int status, ret;

again:
ret = waitpid(pid, &status, 0);
if (ret == -1) {
if (errno == EINTR)
goto again;

return -1;
}

if (ret != pid)
goto again;

return status;
}

static RETURN_WITHOUT_GVL_TYPE
lxc_wait_for_pid_status_without_gvl(void *pid)
wait_for_pid_status_without_gvl(void *pid)
{
RETURN_WITHOUT_GVL(lxc_wait_for_pid_status(*(pid_t*)pid));
RETURN_WITHOUT_GVL(wait_for_pid_status(*(pid_t*)pid));
}

#if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) || defined(HAVE_RB_THREAD_BLOCKING_REGION)
Expand Down Expand Up @@ -748,7 +766,7 @@ container_attach(int argc, VALUE *argv, VALUE self)
goto out;

if (wait) {
ret = RELEASING_GVL2(lxc_wait_for_pid_status_without_gvl, &pid,
ret = RELEASING_GVL2(wait_for_pid_status_without_gvl, &pid,
kill_pid_without_gvl, &pid);
/* handle case where attach fails */
if (WIFEXITED(ret) && WEXITSTATUS(ret) == 255)
Expand Down

0 comments on commit 2d171f9

Please sign in to comment.