robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) Bull S.A. 2001 |
| 4 | * Copyright (c) International Business Machines Corp., 2001 |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 14 | * the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * NAME |
| 23 | * readv03.c |
| 24 | * |
| 25 | * DESCRIPTION |
| 26 | * Testcase to check the error condition of the readv(2) system call |
| 27 | * when fd refers to a directory. |
| 28 | * |
| 29 | * CALLS |
| 30 | * readv() |
| 31 | * |
| 32 | * ALGORITHM |
| 33 | * loop if that option was specified |
| 34 | * call readv() when fd refers to a directory. |
| 35 | * check the errno value |
| 36 | * issue a PASS message if we get EISDIR - errno 21 |
| 37 | * otherwise, the tests fails |
| 38 | * issue a FAIL message |
| 39 | * call cleanup |
| 40 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 41 | * USAGE$ |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 42 | * readv03 |
| 43 | * |
| 44 | * HISTORY |
| 45 | * 05/2002 Ported by Jacky Malcles |
| 46 | * |
| 47 | * RESTRICTIONS |
| 48 | * None |
| 49 | */ |
| 50 | #include <sys/types.h> |
| 51 | #include <sys/uio.h> |
| 52 | #include <sys/fcntl.h> |
| 53 | #include <errno.h> |
| 54 | #include <string.h> |
| 55 | #include <sys/stat.h> |
| 56 | |
| 57 | #include "test.h" |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 58 | |
| 59 | #define K_1 1024 |
| 60 | #define MODES S_IRWXU |
| 61 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 62 | char buf1[K_1]; |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 63 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 64 | struct iovec rd_iovec[1] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 65 | {buf1, K_1} |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | const char *TEST_DIR = "alpha"; |
| 69 | int r_val; |
| 70 | int fd; |
| 71 | |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 72 | char *TCID = "readv03"; |
| 73 | int TST_TOTAL = 1; |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 74 | |
| 75 | void setup(); |
| 76 | void cleanup(); |
| 77 | |
robbiew | 0c7e81c | 2003-03-27 17:44:57 +0000 | [diff] [blame] | 78 | int main(int ac, char **av) |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 79 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 80 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 81 | const char *msg; |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 82 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 83 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 84 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | } |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 86 | |
| 87 | setup(); |
| 88 | |
| 89 | /* The following loop checks looping state if -i option given */ |
| 90 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 91 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 92 | /* reset tst_count in case we are looping */ |
| 93 | tst_count = 0; |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 94 | |
| 95 | if (readv(fd, rd_iovec, 1) < 0) { |
| 96 | if (errno != EISDIR) { |
| 97 | tst_resm(TFAIL, "expected errno = EISDIR, " |
| 98 | "got %d", errno); |
| 99 | } else { |
| 100 | tst_resm(TPASS, "got EISDIR"); |
| 101 | } |
| 102 | } else { |
| 103 | tst_resm(TFAIL, "Error: readv returned a positive " |
| 104 | "value"); |
| 105 | } |
| 106 | |
| 107 | } |
| 108 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 109 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 110 | |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* |
| 114 | * setup() - performs all ONE TIME setup for this test. |
| 115 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 116 | void setup(void) |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 117 | { |
| 118 | |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 119 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 120 | |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 121 | TEST_PAUSE; |
| 122 | |
| 123 | /* make a temporary directory and cd to it */ |
| 124 | tst_tmpdir(); |
| 125 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | /* |
| 127 | * create a new directory and open it |
| 128 | */ |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 129 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | if ((r_val = mkdir(TEST_DIR, MODES)) == -1) { |
| 131 | tst_brkm(TBROK, cleanup, "%s - mkdir() in main() " |
| 132 | "failed", TCID); |
| 133 | } |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 134 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 135 | if ((fd = open(TEST_DIR, O_RDONLY)) == -1) { |
| 136 | tst_brkm(TBROK, cleanup, "open of directory failed"); |
| 137 | } |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 138 | |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 143 | * completion or premature exit. |
| 144 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 145 | void cleanup(void) |
robbiew | bbc75ee | 2002-05-21 17:03:44 +0000 | [diff] [blame] | 146 | { |
| 147 | if (close(fd) < 0) { |
| 148 | tst_brkm(TBROK, cleanup, "close failed: errno = %d", errno); |
| 149 | } |
| 150 | tst_rmdir(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 151 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 152 | } |