• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Ulrich Drepper <drepper@redhat.com>
4  * Copyright (c) International Business Machines  Corp., 2009
5  * Ported to LTP - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>
6  * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
7  */
8 
9 /*\
10  * [Description]
11  *
12  * Verify that inotify_init1() returns a file descriptor and sets
13  * the close-on-exec (FD_CLOEXEC) flag on the new file descriptor
14  * only when called with IN_CLOEXEC.
15  */
16 
17 #include "tst_test.h"
18 #include "lapi/syscalls.h"
19 
20 #define IN_CLOEXEC O_CLOEXEC
21 
run(void)22 static void run(void)
23 {
24 	int fd, fd_flags;
25 
26 	TST_EXP_FD(tst_syscall(__NR_inotify_init1, 0));
27 	fd = TST_RET;
28 	fd_flags = SAFE_FCNTL(fd, F_GETFD);
29 	TST_EXP_EQ_LI(fd_flags & FD_CLOEXEC, 0);
30 	SAFE_CLOSE(fd);
31 
32 	TST_EXP_FD(tst_syscall(__NR_inotify_init1, IN_CLOEXEC));
33 	fd = TST_RET;
34 	fd_flags = SAFE_FCNTL(fd, F_GETFD);
35 	TST_EXP_EQ_LI(fd_flags & FD_CLOEXEC, FD_CLOEXEC);
36 	SAFE_CLOSE(fd);
37 }
38 
39 static struct tst_test test = {
40 	.test_all = run,
41 };
42