aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/lua.patch
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-06-22 20:27:36 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2020-06-22 20:27:36 -0400
commit7c47a9ca0ae48c02842a0534828fea95861f4b4c (patch)
tree128bdfd1b056a22f8f72716e8955e9ee5081f7d0 /src/lua.patch
parentd380240cb733312386a9e4f119aa02324afec417 (diff)
Fixed potential hangs on curses with `os.spawn()`.
Stop tracking and monitoring processes on exit.
Diffstat (limited to 'src/lua.patch')
-rw-r--r--src/lua.patch27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/lua.patch b/src/lua.patch
index 00c181c6..dee5a0f8 100644
--- a/src/lua.patch
+++ b/src/lua.patch
@@ -48,7 +48,7 @@ diff -r 8a23edc91533 src/luaconf.h
--- a/src/loslib.c 2017-04-19 13:29:57.000000000 -0400
-+++ b/src/loslib.c 2020-05-24 14:28:49.259487829 -0400
++++ b/src/loslib.c 2020-06-22 19:16:23.952024597 -0400
@@ -4,6 +4,15 @@
** See Copyright Notice in lua.h
*/
@@ -85,11 +85,11 @@ diff -r 8a23edc91533 src/luaconf.h
{"time", os_time},
{"tmpname", os_tmpname},
{NULL, NULL}
-@@ -404,6 +419,630 @@
+@@ -404,6 +419,643 @@
LUAMOD_API int luaopen_os (lua_State *L) {
luaL_newlib(L, syslib);
-+#if (!GTK || __APPLE__)
++#if (!GTK && !_WIN32 || __APPLE__)
+ // Need to keep track of running processes for monitoring fds and pids.
+ lua_newtable(L), lua_setfield(L, LUA_REGISTRYINDEX, "spawn_procs");
+#endif
@@ -160,14 +160,27 @@ diff -r 8a23edc91533 src/luaconf.h
+/** Process exit cleanup function. */
+static void exited(PStream *p, int status) {
++ lua_State *L = p->L;
+#if _WIN32
+ close(p->pid);
++#elif (!GTK || __APPLE__)
++ // Stop tracking and monitoring this proc.
++ lua_getfield(L, LUA_REGISTRYINDEX, "spawn_procs");
++ lua_pushnil(L);
++ while (lua_next(L, -2)) {
++ PStream *monitored_p = (PStream *)lua_touserdata(L, -2);
++ if (monitored_p->pid == p->pid) {
++ lua_pushnil(L), lua_replace(L, -2), lua_settable(L, -3); // t[proc] = nil
++ break;
++ } else lua_pop(L, 1); // value
++ }
++ lua_pop(L, 1); // spawn_procs
+#endif
+ close(p->fstdin), close(p->fstdout), close(p->fstderr);
-+ luaL_unref(p->L, LUA_REGISTRYINDEX, p->stdout_cb);
-+ luaL_unref(p->L, LUA_REGISTRYINDEX, p->stderr_cb);
-+ luaL_unref(p->L, LUA_REGISTRYINDEX, p->exit_cb);
-+ luaL_unref(p->L, LUA_REGISTRYINDEX, p->ref); // allow proc to be collected
++ luaL_unref(L, LUA_REGISTRYINDEX, p->stdout_cb);
++ luaL_unref(L, LUA_REGISTRYINDEX, p->stderr_cb);
++ luaL_unref(L, LUA_REGISTRYINDEX, p->exit_cb);
++ luaL_unref(L, LUA_REGISTRYINDEX, p->ref); // allow proc to be collected
+ p->pid = 0, p->exit_status = status;
+}
+