xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/open/open06.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker 
3*49cdfc7eSAndroid Build Coastguard Worker /*
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) International Business Machines  Corp., 2001
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker  *
11*49cdfc7eSAndroid Build Coastguard Worker  * Verify that open(2) fails with ENXIO when
12*49cdfc7eSAndroid Build Coastguard Worker  * O_NONBLOCK | O_WRONLY is set, the named file is a FIFO,
13*49cdfc7eSAndroid Build Coastguard Worker  * and no process has the FIFO open for reading.
14*49cdfc7eSAndroid Build Coastguard Worker  */
15*49cdfc7eSAndroid Build Coastguard Worker 
16*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker #define TEMP_FIFO "tmpfile"
19*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)20*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
21*49cdfc7eSAndroid Build Coastguard Worker {
22*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_MKFIFO(TEMP_FIFO, 0644);
23*49cdfc7eSAndroid Build Coastguard Worker }
24*49cdfc7eSAndroid Build Coastguard Worker 
run(void)25*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
26*49cdfc7eSAndroid Build Coastguard Worker {
27*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL2(open(TEMP_FIFO, O_NONBLOCK | O_WRONLY), ENXIO);
28*49cdfc7eSAndroid Build Coastguard Worker }
29*49cdfc7eSAndroid Build Coastguard Worker 
30*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
31*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
32*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
33*49cdfc7eSAndroid Build Coastguard Worker 	.needs_tmpdir = 1
34*49cdfc7eSAndroid Build Coastguard Worker };
35