Closed dpino closed 8 years ago
I don't recommend doing that, as it is unclear if it is safe to write handler functions in Lua, and I had a lot of problems when writing the tests, the code may actually be disabled, I need to check (travelling at the minute).
I recommend you use signalfd to process signals (kqueue on BSD platforms) as this avoids all the issues with signal handlers and is a nicer interface. This just means you mask the signal without making a handler.
Thanks, I followed your advice. I coded the example above using signalfd
. I leave it here for reference:
local S = require("syscall")
local util = S.util
local function empty(sig)
return type(sig) == "table" and #sig == 0
end
local ss = "int"
local fd = assert(S.signalfd(ss, "nonblock"))
assert(S.sigprocmask("block", ss))
while 1 do
local sig = assert(util.signalfd_read(fd))
if not empty(sig) then
if sig[1].int then
print("Cought SIGINT")
end
end
end
I also followed this advice from Justin when implementing SnabbCo/snabbswitch#629.
I'm try to mask a signal with my own handler. Here is my code:
I run it and press Ctrl+C to emit a SIGINT signal. Here's the result:
The handler is not triggered. I coded a similar test in C. It looks like this:
This is the result:
I expected the Lua test case to work similarly to the C test case. I'm doing anything wrong? Maybe I'm not using the
signal
function correctly. My system is Ubuntu 15.04 x86_64 LuaJIT 2.0.4.