-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.lua
More file actions
32 lines (31 loc) · 740 Bytes
/
example.lua
File metadata and controls
32 lines (31 loc) · 740 Bytes
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
-- luacheck: ignore
local sandbox = require("sandbox")
local cqueues = require("cqueues")
local fork = require("sandbox.cqueues").fork
pid, parent, child = fork()
if pid ~= 0 then -- parent, send to child queue
child:write("message\n")
local cq = cqueues.new()
local is_dead = false
cq:wrap(function()
print('waiting')
print('received:', child:read())
is_dead = true
end)
cq:loop(2)
if not is_dead then
print('terminating')
if not sandbox.kill(pid, sandbox.SIGTERM) then
print('killing')
print(sandbox.kill(pid, sandbox.SIGKILL))
end
end
else
cqueues.sleep(0) -- load auxilliary library before protecting
sandbox.protect()
print(parent:read())
for i=1, 1 do
cqueues.sleep(1)
end
parent:write("msg\n")
end