plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 21 | * 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 28 | */ |
| 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" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | |
| 36 | char *TCID = "open06"; |
| 37 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | |
Wanlong Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 39 | static void setup(void); |
| 40 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 41 | |
Wanlong Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 42 | static char fname[100] = "fifo"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 44 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 46 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 47 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | |
Wanlong Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 49 | msg = parse_opts(ac, av, NULL, NULL); |
| 50 | if (msg != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 51 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | |
| 53 | setup(); |
| 54 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 56 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 57 | |
| 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 Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 64 | if (TEST_ERRNO != ENXIO) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | tst_resm(TFAIL, "Expected ENXIO got %d", TEST_ERRNO); |
Wanlong Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 66 | else |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | tst_resm(TPASS, "call returned expected ENXIO error"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | } |
Wanlong Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 69 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | cleanup(); |
Garrett Cooper | 16e6e26 | 2010-12-19 10:16:07 -0800 | [diff] [blame] | 71 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Wanlong Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 74 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 77 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | TEST_PAUSE; |
| 79 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | tst_tmpdir(); |
| 81 | |
| 82 | sprintf(fname, "%s.%d", fname, getpid()); |
| 83 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 84 | if (mknod(fname, S_IFIFO | 0644, 0) == -1) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 85 | tst_brkm(TBROK, cleanup, "mknod FAILED"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Wanlong Gao | 32b27f9 | 2013-02-04 17:11:18 +0800 | [diff] [blame] | 88 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | unlink(fname); |
| 91 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | tst_rmdir(); |
Garrett Cooper | 16e6e26 | 2010-12-19 10:16:07 -0800 | [diff] [blame] | 93 | } |