xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/eventfd2/eventfd2_01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Ulrich Drepper <[email protected]>
4  * Copyright (c) International Business Machines  Corp., 2009
5  * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
6  */
7 
8 /*\
9  * [Description]
10  *
11  * This test verifies that eventfd2 correctly set FD_CLOEXEC flag on file when
12  * EFD_CLOEXEC flag is used.
13  */
14 
15 #include <fcntl.h>
16 #include <sys/eventfd.h>
17 #include "tst_test.h"
18 #include "eventfd2.h"
19 
run(void)20 static void run(void)
21 {
22 	int fd, flags;
23 
24 	fd = eventfd2(1, 0);
25 	flags = SAFE_FCNTL(fd, F_GETFD);
26 	TST_EXP_EXPR(!(flags & FD_CLOEXEC), "FD_CLOEXEC is not set");
27 	SAFE_CLOSE(fd);
28 
29 	fd = eventfd2(1, EFD_CLOEXEC);
30 	flags = SAFE_FCNTL(fd, F_GETFD);
31 	TST_EXP_EXPR((flags & FD_CLOEXEC), "FD_CLOEXEC is set");
32 	SAFE_CLOSE(fd);
33 }
34 
35 static struct tst_test test = {
36 	.test_all = run,
37 };
38