blob: 0b3fde5b267ed2ac14d9e4e2ebdfcce8e9a58507 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
plars865695b2001-08-27 22:15:12 +000021 * DESCRIPTION
22 * Testcase to check open(2) sets errno to ENXIO correctly.
23 *
24 * ALGORITHM
25 * Create a named pipe using mknod(2). Attempt to
26 * open(2) the pipe for writing. The open(2) should
27 * fail with ENXIO.
plars865695b2001-08-27 22:15:12 +000028 */
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <fcntl.h>
32#include <errno.h>
33#include <unistd.h>
34#include "test.h"
plars865695b2001-08-27 22:15:12 +000035
36char *TCID = "open06";
37int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000038
Wanlong Gao32b27f92013-02-04 17:11:18 +080039static void setup(void);
40static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000041
Wanlong Gao32b27f92013-02-04 17:11:18 +080042static char fname[100] = "fifo";
plars865695b2001-08-27 22:15:12 +000043
plars74948ad2002-11-14 16:16:14 +000044int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000045{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020046 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020047 const char *msg;
plars865695b2001-08-27 22:15:12 +000048
Wanlong Gao32b27f92013-02-04 17:11:18 +080049 msg = parse_opts(ac, av, NULL, NULL);
50 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080051 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000052
53 setup();
54
plars865695b2001-08-27 22:15:12 +000055 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080056 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000057
58 TEST(open(fname, O_NONBLOCK | O_WRONLY));
59 if (TEST_RETURN != -1) {
60 tst_resm(TFAIL, "open(2) succeeded unexpectedly");
61 continue;
62 }
63
Wanlong Gao32b27f92013-02-04 17:11:18 +080064 if (TEST_ERRNO != ENXIO)
plars865695b2001-08-27 22:15:12 +000065 tst_resm(TFAIL, "Expected ENXIO got %d", TEST_ERRNO);
Wanlong Gao32b27f92013-02-04 17:11:18 +080066 else
plars865695b2001-08-27 22:15:12 +000067 tst_resm(TPASS, "call returned expected ENXIO error");
plars865695b2001-08-27 22:15:12 +000068 }
Wanlong Gao32b27f92013-02-04 17:11:18 +080069
plars865695b2001-08-27 22:15:12 +000070 cleanup();
Garrett Cooper16e6e262010-12-19 10:16:07 -080071 tst_exit();
plars865695b2001-08-27 22:15:12 +000072}
73
Wanlong Gao32b27f92013-02-04 17:11:18 +080074static void setup(void)
plars865695b2001-08-27 22:15:12 +000075{
plars865695b2001-08-27 22:15:12 +000076 tst_sig(NOFORK, DEF_HANDLER, cleanup);
77
plars865695b2001-08-27 22:15:12 +000078 TEST_PAUSE;
79
plars865695b2001-08-27 22:15:12 +000080 tst_tmpdir();
81
82 sprintf(fname, "%s.%d", fname, getpid());
83
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 if (mknod(fname, S_IFIFO | 0644, 0) == -1)
plars865695b2001-08-27 22:15:12 +000085 tst_brkm(TBROK, cleanup, "mknod FAILED");
plars865695b2001-08-27 22:15:12 +000086}
87
Wanlong Gao32b27f92013-02-04 17:11:18 +080088static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000089{
plars865695b2001-08-27 22:15:12 +000090 unlink(fname);
91
plars865695b2001-08-27 22:15:12 +000092 tst_rmdir();
Garrett Cooper16e6e262010-12-19 10:16:07 -080093}