Skip to content

Commit 30f1849

Browse files
Avineshpevik
authored andcommitted
flock02: Add test for EWOULDBLOCK errno
Also fix a make check warning. Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Andrea Cervesato <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Avinesh Kumar <[email protected]> Signed-off-by: Yang Xu <[email protected]>
1 parent 605e160 commit 30f1849

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

testcases/kernel/syscalls/flock/flock02.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* - EBADF if the file descriptor is invalid
1414
* - EINVAL if the argument operation does not include LOCK_SH,LOCK_EX,LOCK_UN
1515
* - EINVAL if an invalid combination of locking modes is used i.e LOCK_SH with LOCK_EX
16+
* - EWOULDBLOCK if the file is locked and the LOCK_NB flag was selected
1617
*/
1718

1819
#include <errno.h>
@@ -31,13 +32,21 @@ static struct tcase {
3132
{&badfd, LOCK_SH, EBADF},
3233
{&fd, LOCK_NB, EINVAL},
3334
{&fd, LOCK_SH | LOCK_EX, EINVAL},
35+
{&fd, LOCK_NB | LOCK_EX, EWOULDBLOCK}
3436
};
3537

36-
static void verify_flock(unsigned n)
38+
static void verify_flock(unsigned int n)
3739
{
40+
int fd2 = -1;
3841
struct tcase *tc = &tcases[n];
3942

4043
fd = SAFE_OPEN("testfile", O_RDWR);
44+
45+
if (tc->exp_err == EWOULDBLOCK) {
46+
fd2 = SAFE_OPEN("testfile", O_RDWR);
47+
flock(fd2, LOCK_EX);
48+
}
49+
4150
TEST(flock(*tc->fd, tc->operation));
4251
if (TST_RET == 0) {
4352
tst_res(TFAIL | TTERRNO, "flock() succeeded unexpectedly");
@@ -53,6 +62,8 @@ static void verify_flock(unsigned n)
5362
}
5463

5564
SAFE_CLOSE(fd);
65+
if (fd2 != -1)
66+
SAFE_CLOSE(fd2);
5667
}
5768

5869
static void setup(void)

0 commit comments

Comments
 (0)