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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
local os = require "os"
local l = require "luxio"
local io = require "io"
function MySigInfoCallback(signo, info)
print("MySigInfoCallback!", signo, info)
for k, v in pairs(info) do
print(k, v)
end
end
function MySIGTERMCallback(signo)
print("SIGTERM received", signo)
os.exit(os.EXIT_SUCCESS)
end
function MySIGUSR1Callback(signo)
print("SIGUSR1 received, deregistering this callback now")
sa = {["sa_handler"] = l.SIG_DFL, sa_flags = 0}
r, origsa = l.sigaction(l.SIGUSR1, sa)
if r == -1 then
io.stderr:write(("sigaction: %s\n"):format(l.strerror(origsa)))
os.exit(os.EXIT_FAILURE)
end
end
sa = {["sa_sigaction"] = MySigInfoCallback, ["sa_flags"] = l.SA_SIGINFO}
r, origsa = l.sigaction(l.SIGINT, sa)
if r == -1 then
io.stderr:write(("sigaction: %s\n"):format(l.strerror(origsa)))
os.exit(os.EXIT_FAILURE)
end
sa = {["sa_handler"] = MySIGTERMCallback}
r, origsa = l.sigaction(l.SIGTERM, sa)
if r == -1 then
io.stderr:write(("sigaction: %s\n"):format(l.strerror(origsa)))
os.exit(os.EXIT_FAILURE)
end
sa = {["sa_handler"] = MySIGUSR1Callback}
r, origsa = l.sigaction(l.SIGUSR1, sa)
if r == -1 then
io.stderr:write(("sigaction: %s\n"):format(l.strerror(origsa)))
os.exit(os.EXIT_FAILURE)
end
sa = {["sa_handler"] = l.SIG_IGN}
r, origsa = l.sigaction(l.SIGUSR2, sa)
if r == -1 then
io.stderr:write(("sigaction: %s\n"):format(l.strerror(origsa)))
os.exit(os.EXIT_FAILURE)
end
for k, v in pairs(origsa) do
print(k, v)
end
while (true) do
print("sleep!")
l.sleep(2)
end
|