Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
lua: ensure pkg.exec does not continue in the background
Baptiste Daroussin committed 4 years ago
commit 023bb9f0f9f3adfd8b9d17471f02cdd704c3ac41
parent f95ea94
1 file changed +19 -1
modified libpkg/lua.c
@@ -130,7 +130,7 @@ luaL_checkarraystrings(lua_State *L, int arg) {
int
lua_exec(lua_State *L)
{
-
	int r;
+
	int r, pstat;
	posix_spawn_file_actions_t action;
	int stdin_pipe[2] = {-1, -1};
	pid_t pid;
@@ -160,6 +160,24 @@ lua_exec(lua_State *L)
		lua_pushinteger(L, r);
		return 3;
	}
+
	while (waitpid(pid, &pstat, 0) == -1) {
+
		if (errno != EINTR) {
+
			lua_pushnil(L);
+
			lua_pushstring(L, strerror(r));
+
			lua_pushinteger(L, r);
+
			return 3;
+
		}
+
	}
+

+
	if (WEXITSTATUS(pstat) != 0) {
+
		lua_pushnil(L);
+
		lua_pushstring(L, "Abnormal terminaison");
+
		lua_pushinteger(L, r);
+
		return 3;
+
	}
+

+
	posix_spawn_file_actions_destroy(&action);
+

	if (stdin_pipe[0] != -1)
		close(stdin_pipe[0]);
	if (stdin_pipe[1] != -1)