summaryrefslogtreecommitdiff
path: root/tests/test-fcntl-lock-2.lua
blob: 3a6dbd1b75a38bf0490ee889ed18540f71f6a391 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local l = require "luxio"

local fd, r, errno

fd, errno = l.open("test-lock-file", l.O_RDWR)
assert(fd >= 0)

t = {
   l_type = l.F_WRLCK,
   l_whence = l.SEEK_SET,
   l_start = 0,
   l_len = 4096
}

r, errno = l.fcntl(fd, l.F_GETLK, t)
print("fnctl: r,errno:", r, errno)
print("held by pid, waiting for unlock", t.l_pid)

t.l_type = l.F_WRLCK
r, errno = l.fcntl(fd, l.F_SETLKW, t)
print("fnctl: r,errno:", r, errno)