summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/luv/tests/test-sigchld-after-lua_close.sh
blob: e7d22d3df368c23b0e7b70b9849e393f0308bc7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
# Verifies that luv will cleanup libuv process handles correctly even if
# not done by "userspace".
# Details: https://github.com/luvit/luv/issues/193

# This test modifies one of the examples to skip libuv process cleanup,
# purposely making it leave SIGCHLD signal handler.
# 
patch -p1 << "EOF"
diff --git a/examples/talking-to-children.lua b/examples/talking-to-children.lua
index 10a53ef..6c6c53f 100644
--- a/examples/talking-to-children.lua
+++ b/examples/talking-to-children.lua
@@ -41,7 +41,3 @@ uv.read_start(stdout, onread)
 uv.read_start(stderr, onread)
 uv.write(stdin, "Hello World")
 uv.shutdown(stdin, onshutdown)
-
-uv.run()
-uv.walk(uv.close)
-uv.run()
EOF

# It also requires a patched lua standalone interpreter that sends SIGCHLD to
# itself after calling lua_close, which would have freed all memory of the libuv
# event loop associated with the lua state.
(
cd deps/lua
patch -p1 << "EOF"
diff --git a/src/lua.c b/src/lua.c
index 7a47582..4dc19d5 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -608,6 +608,7 @@ int main (int argc, char **argv) {
   result = lua_toboolean(L, -1);  /* get result */
   report(L, status);
   lua_close(L);
+  kill(0, SIGCHLD);
   return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
EOF
)

WITH_LUA_ENGINE=Lua make
./build/lua examples/talking-to-children.lua