summaryrefslogtreecommitdiff
path: root/tests/test-sigprocmask.lua
blob: 490672be565011bfc89d7e28accab6a602d087fe (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local l = require "luxio"

set = l.newsigset()

r, errno = l.sigemptyset(set)
if r == -1 then
   io.stderr:write(("sigemptyset: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end

print("Empty set", set)

r, errno = l.sigfillset(set)
if r == -1 then
   io.stderr:write(("sigfillset: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end

print("Full set", set)

r, errno = l.sigismember(set, l.SIGINT)
if r == -1 then
   io.stderr:write(("sigismember: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end

print("SIGINT is member of set?", r == 1 and "yes" or "no")

print("sigdelset(set, SIGINT)...")
r, errno = l.sigdelset(set, l.SIGINT)
if r == -1 then
   io.stderr:write(("sigdelset: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end

r, errno = l.sigismember(set, l.SIGINT)
if r == -1 then
   io.stderr:write(("sigismember: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end

print("SIGINT is member of set?", r == 1 and "yes" or "no")

print("l.sigemptyset(set)...")
r, errno = l.sigemptyset(set)
if r == -1 then
   io.stderr:write(("sigemptyset: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end

print("Empty set", set)


to_block = {["SIGINT"] = l.SIGINT, ["SIGUSR1"] = l.SIGUSR1}

for signame, signo in pairs(to_block) do
   print(("sigaddset(set, %s)..."):format(signame))
   r, errno = l.sigaddset(set, signo)
   if r == -1 then
      io.stderr:write(("sigaddset: %s\n"):format(l.strerror(errno)))
      os.exit(os.EXIT_FAILURE)
   end

   r, errno = l.sigismember(set, signo)
   if r == -1 then
      io.stderr:write(("sigismember: %s\n"):format(l.strerror(errno)))
      os.exit(os.EXIT_FAILURE)
   end

   print(("%s is member of set?"):format(signame), r == 1 and "yes" or "no")
end

origset, errno = l.sigprocmask(0, nil)
if origset == nil then
   io.stderr:write(("sigprocmask: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end
print("Got the current signal set", origset)

print("set", set)
origset, errno = l.sigprocmask(l.SIG_BLOCK, set)
if origset == nil then
   io.stderr:write(("sigprocmask: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end
print("origset", origset)

i = 1
while (i <= 5) do
   print(i)
   l.sleep(2)
   i = i + 1
end

print("restoring original signal mask...")

origset, errno = l.sigprocmask(l.SIG_SETMASK, origset)
if origset == nil then
   io.stderr:write(("sigprocmask: %s\n"):format(l.strerror(errno)))
   os.exit(os.EXIT_FAILURE)
end

print("done")
print("origset", origset)

while (true) do
   l.sleep(2)
   print("sleep")
end