summaryrefslogtreecommitdiff
path: root/tests/test-sigtimedwait.lua
blob: 0311a505c4c99f769855ebd91a4057969240743d (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
local l = require "luxio"

function handler()
	return
end

l.sigaction(l.SIGINT, {["sa_handler"] = handler})

s = l.newsigset()
l.sigemptyset(s)
l.sigaddset(s, l.SIGINT)

info, errno = l.sigtimedwait(s, 0, 0)

if not (info == nil and errno == l.EAGAIN) then
   print("FAIL")
end

print("Wait...")
pid, errno = l.fork()
if pid == 0 then
   l.sleep(5)
   print("Press CTRL-C...")
   os.exit(0)
elseif pid == -1 then
   io.stderr:write(("fork: %s\n"):format(l.strerror(errno)))
   os.exit(2)
end

seconds = 3600
info, errno = l.sigtimedwait(s, seconds, 0)

if info ~= nil and info["si_signo"] == l.SIGINT then
   print("PASS")
else
   print(("FAIL (expected sig to be %d but it is %d)"):format(l.SIGINT, info["si_signo"]))
end