From 2d171f980f4eef9786749367612759291fab3a15 Mon Sep 17 00:00:00 2001 From: Jakub Skokan Date: Mon, 12 Oct 2020 17:04:27 +0200 Subject: [PATCH] Reimplement lxc_wait_for_pid_status as it is no longer exported by liblxc Signed-off-by: Jakub Skokan --- ext/lxc/lxc.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/ext/lxc/lxc.c b/ext/lxc/lxc.c index 1f0b440..ce14c37 100644 --- a/ext/lxc/lxc.c +++ b/ext/lxc/lxc.c @@ -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; @@ -677,10 +675,30 @@ err: return NULL; } -static RETURN_WITHOUT_GVL_TYPE -lxc_wait_for_pid_status_without_gvl(void *pid) +static int +wait_for_pid_status(pid_t pid) { - RETURN_WITHOUT_GVL(lxc_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 +wait_for_pid_status_without_gvl(void *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) @@ -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)