From e0099485ab6fc3fa20a7f6f132365518b700d423 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Thu, 8 Jul 2021 11:22:56 +0800 Subject: [PATCH] kill process when pipe is closed --- src/api/process.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/api/process.c b/src/api/process.c index 6442d0d2..0dce6908 100644 --- a/src/api/process.c +++ b/src/api/process.c @@ -223,8 +223,16 @@ static int g_read(lua_State* L, int stream) luaL_addsize(&b, out); luaL_pushresult(&b); - if (out == REPROC_EPIPE) + if (out == REPROC_EPIPE) { + int ret = reproc_stop(self->process, (reproc_stop_actions) { + { REPROC_STOP_KILL, 0 }, + { REPROC_STOP_KILL, 0 }, + { REPROC_STOP_TERMINATE, 0 } + }); + self->running = false; + self->returncode = ret; ASSERT_REPROC_ERRNO(L, out); + } return 1; } @@ -300,8 +308,8 @@ static int f_terminate(lua_State* L) ASSERT_REPROC_ERRNO(L, out); poll_process(self, 0); - lua_pushboolean(L, 1); + return 1; } @@ -313,8 +321,8 @@ static int f_kill(lua_State* L) ASSERT_REPROC_ERRNO(L, out); poll_process(self, 0); - lua_pushboolean(L, 1); + return 1; }