File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
testcases/kernel/syscalls/flock Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 13
13
* - EBADF if the file descriptor is invalid
14
14
* - EINVAL if the argument operation does not include LOCK_SH,LOCK_EX,LOCK_UN
15
15
* - 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
16
17
*/
17
18
18
19
#include <errno.h>
@@ -31,13 +32,21 @@ static struct tcase {
31
32
{& badfd , LOCK_SH , EBADF },
32
33
{& fd , LOCK_NB , EINVAL },
33
34
{& fd , LOCK_SH | LOCK_EX , EINVAL },
35
+ {& fd , LOCK_NB | LOCK_EX , EWOULDBLOCK }
34
36
};
35
37
36
- static void verify_flock (unsigned n )
38
+ static void verify_flock (unsigned int n )
37
39
{
40
+ int fd2 = -1 ;
38
41
struct tcase * tc = & tcases [n ];
39
42
40
43
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
+
41
50
TEST (flock (* tc -> fd , tc -> operation ));
42
51
if (TST_RET == 0 ) {
43
52
tst_res (TFAIL | TTERRNO , "flock() succeeded unexpectedly" );
@@ -53,6 +62,8 @@ static void verify_flock(unsigned n)
53
62
}
54
63
55
64
SAFE_CLOSE (fd );
65
+ if (fd2 != -1 )
66
+ SAFE_CLOSE (fd2 );
56
67
}
57
68
58
69
static void setup (void )
You can’t perform that action at this time.
0 commit comments