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 | /* |
| 21 | * Test Name: stat03 |
| 22 | * |
| 23 | * Test Description: |
| 24 | * Verify that, |
| 25 | * 1) stat(2) returns -1 and sets errno to EACCES if search permission is |
| 26 | * denied on a component of the path prefix. |
| 27 | * 2) stat(2) returns -1 and sets errno to ENOENT if the specified file |
| 28 | * does not exists or empty string. |
| 29 | * 3) stat(2) returns -1 and sets errno to EFAULT if pathname points |
| 30 | * outside user's accessible address space. |
| 31 | * 4) stat(2) returns -1 and sets errno to ENAMETOOLONG if the pathname |
| 32 | * component is too long. |
| 33 | * 5) stat(2) returns -1 and sets errno to ENOTDIR if the directory |
| 34 | * component in pathname is not a directory. |
| 35 | * |
| 36 | * Expected Result: |
| 37 | * stat() should fail with return value -1 and set expected errno. |
| 38 | * |
| 39 | * Algorithm: |
| 40 | * Setup: |
| 41 | * Setup signal handling. |
| 42 | * Create temporary directory. |
| 43 | * Pause for SIGUSR1 if option specified. |
| 44 | * |
| 45 | * Test: |
| 46 | * Loop if the proper options are given. |
| 47 | * Execute system call |
| 48 | * Check return code, if system call failed (return=-1) |
| 49 | * if errno set == expected errno |
| 50 | * Issue sys call fails with expected return value and errno. |
| 51 | * Otherwise, |
| 52 | * Issue sys call fails with unexpected errno. |
| 53 | * Otherwise, |
| 54 | * Issue sys call returns unexpected value. |
| 55 | * |
| 56 | * Cleanup: |
| 57 | * Print errno log and/or timing stats if options given |
| 58 | * Delete the temporary directory(s)/file(s) created. |
| 59 | * |
| 60 | * Usage: <for command-line> |
| 61 | * stat03 [-c n] [-e] [-i n] [-I x] [-p x] [-t] |
| 62 | * where, -c n : Run n copies concurrently. |
| 63 | * -e : Turn on errno logging. |
| 64 | * -i n : Execute test n times. |
| 65 | * -I x : Execute test for x seconds. |
| 66 | * -P x : Pause for x seconds between iterations. |
| 67 | * -t : Turn on syscall timing. |
| 68 | * |
| 69 | * History |
| 70 | * 07/2001 John George |
| 71 | * -Ported |
| 72 | * |
| 73 | * Restrictions: |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | * |
| 75 | */ |
| 76 | |
| 77 | #include <stdio.h> |
| 78 | #include <stdlib.h> |
| 79 | #include <unistd.h> |
| 80 | #include <fcntl.h> |
| 81 | #include <errno.h> |
| 82 | #include <string.h> |
| 83 | #include <signal.h> |
| 84 | #include <sys/types.h> |
| 85 | #include <sys/stat.h> |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 86 | #include <sys/mman.h> |
robbiew | b1c11a1 | 2001-08-28 15:47:02 +0000 | [diff] [blame] | 87 | #include <pwd.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
| 89 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | |
| 91 | #define MODE_RWX S_IRWXU | S_IRWXG | S_IRWXO |
| 92 | #define FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH |
| 93 | #define DIR_TEMP "testdir_1" |
| 94 | #define TEST_FILE1 "testdir_1/tfile_1" |
| 95 | #define TEST_FILE2 "t_file/tfile_2" |
| 96 | |
| 97 | int no_setup(); |
| 98 | int setup1(); /* setup function to test chmod for EACCES */ |
| 99 | int setup2(); /* setup function to test chmod for ENOTDIR */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 100 | int longpath_setup(); /* setup function to test chmod for ENAMETOOLONG */ |
robbiew | b1c11a1 | 2001-08-28 15:47:02 +0000 | [diff] [blame] | 101 | char nobody_uid[] = "nobody"; |
| 102 | struct passwd *ltpuser; |
| 103 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | char Longpathname[PATH_MAX + 2]; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | char High_address_node[64]; |
| 106 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | struct test_case_t { /* test case struct. to hold ref. test cond's */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | char *pathname; |
| 109 | char *desc; |
| 110 | int exp_errno; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | int (*setupfunc) (); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | } Test_cases[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | { |
| 114 | TEST_FILE1, "No Search permissions to process", EACCES, setup1}, |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 115 | #if !defined(UCLINUX) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 116 | { |
| 117 | High_address_node, "Address beyond address space", EFAULT, no_setup}, |
| 118 | { |
| 119 | (char *)-1, "Negative address", EFAULT, no_setup}, |
vapier | b5ed1f6 | 2006-08-24 04:16:32 +0000 | [diff] [blame] | 120 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | { |
| 122 | Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, { |
| 123 | "", "Pathname is empty", ENOENT, no_setup}, { |
| 124 | TEST_FILE2, "Path contains regular file", ENOTDIR, setup2}, { |
| 125 | NULL, NULL, 0, no_setup} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 128 | char *TCID = "stat03"; |
Cyril Hrubis | b863a0b | 2014-09-24 13:15:29 +0200 | [diff] [blame] | 129 | int TST_TOTAL = ARRAY_SIZE(Test_cases); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 130 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | char *bad_addr = 0; |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 132 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | void setup(); /* Main setup function for the tests */ |
| 134 | void cleanup(); /* cleanup function for the test */ |
| 135 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 137 | { |
| 138 | struct stat stat_buf; /* stat structure buffer */ |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 139 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 140 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 141 | char *file_name; /* ptr. for file name whose mode is modified */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 142 | char *test_desc; /* test specific error message */ |
| 143 | int ind; /* counter to test different test conditions */ |
| 144 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 145 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 146 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * Invoke setup function to call individual test setup functions |
| 150 | * to simulate test conditions. |
| 151 | */ |
| 152 | setup(); |
| 153 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 154 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 155 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 156 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 157 | |
| 158 | for (ind = 0; Test_cases[ind].desc != NULL; ind++) { |
| 159 | file_name = Test_cases[ind].pathname; |
| 160 | test_desc = Test_cases[ind].desc; |
| 161 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 162 | #if !defined(UCLINUX) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 163 | if (file_name == High_address_node) { |
| 164 | file_name = (char *)get_high_address(); |
| 165 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 166 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * Call stat(2) to test different test conditions. |
| 170 | * verify that it fails with -1 return value and |
| 171 | * sets appropriate errno. |
| 172 | */ |
| 173 | TEST(stat(file_name, &stat_buf)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 174 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 175 | /* Check return code from stat(2) */ |
| 176 | if (TEST_RETURN == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 177 | if (TEST_ERRNO == Test_cases[ind].exp_errno) { |
| 178 | tst_resm(TPASS, |
| 179 | "stat() fails, %s, errno:%d", |
| 180 | test_desc, TEST_ERRNO); |
| 181 | } else { |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 182 | tst_resm(TFAIL, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 183 | "stat() fails, %s, errno:%d, expected errno:%d", |
| 184 | test_desc, TEST_ERRNO, |
| 185 | Test_cases[ind].exp_errno); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 186 | } |
| 187 | } else { |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 188 | tst_resm(TFAIL, |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 189 | "stat(2) returned %ld, expected -1, errno:%d", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 190 | TEST_RETURN, |
| 191 | Test_cases[ind].exp_errno); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 192 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 193 | } |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 194 | tst_count++; /* incr TEST_LOOP counter */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 195 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 196 | |
| 197 | /* |
| 198 | * Invoke cleanup() to delete the test directory/file(s) created |
| 199 | * in the setup(). |
| 200 | */ |
| 201 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 202 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 203 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 204 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 205 | |
| 206 | /* |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 207 | * void |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 208 | * setup(void) - performs all ONE TIME setup for this test. |
| 209 | * Exit the test program on receipt of unexpected signals. |
| 210 | * Create a temporary directory and change directory to it. |
| 211 | * Invoke individual test setup functions according to the order |
| 212 | * set in struct. definition. |
| 213 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 214 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 215 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 216 | int ind; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 217 | |
Nicolas Joly | d4ceb37 | 2014-06-22 17:03:57 +0200 | [diff] [blame] | 218 | tst_require_root(NULL); |
| 219 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 220 | /* Capture unexpected signals */ |
| 221 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 222 | |
robbiew | b1c11a1 | 2001-08-28 15:47:02 +0000 | [diff] [blame] | 223 | /* Switch to nobody user for correct error code collection */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 224 | ltpuser = getpwnam(nobody_uid); |
| 225 | if (setuid(ltpuser->pw_uid) == -1) { |
| 226 | tst_resm(TINFO, "setuid failed to " |
| 227 | "to set the effective uid to %d", ltpuser->pw_uid); |
| 228 | perror("setuid"); |
| 229 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 230 | |
| 231 | /* Pause if that option was specified |
| 232 | * TEST_PAUSE contains the code to fork the test with the -i option. |
| 233 | * You want to make sure you do this before you create your temporary |
| 234 | * directory. |
| 235 | */ |
| 236 | TEST_PAUSE; |
| 237 | |
| 238 | /* Make a temp dir and cd to it */ |
| 239 | tst_tmpdir(); |
| 240 | |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 241 | #if !defined(UCLINUX) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 242 | bad_addr = mmap(0, 1, PROT_NONE, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 243 | MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); |
vapier | 0722a2b | 2006-05-12 15:44:11 +0000 | [diff] [blame] | 244 | if (bad_addr == MAP_FAILED) { |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 245 | tst_brkm(TBROK, cleanup, "mmap failed"); |
| 246 | } |
| 247 | Test_cases[2].pathname = bad_addr; |
mreed10 | 81534c3 | 2006-08-03 05:21:24 +0000 | [diff] [blame] | 248 | #endif |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 249 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 250 | /* call individual setup functions */ |
| 251 | for (ind = 0; Test_cases[ind].desc != NULL; ind++) { |
| 252 | Test_cases[ind].setupfunc(); |
| 253 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 254 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 255 | |
| 256 | /* |
| 257 | * int |
| 258 | * no_setup() - Some test conditions for stat(2) do not any setup. |
| 259 | * Hence, this function just returns 0. |
| 260 | * This function simply returns 0. |
| 261 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 262 | int no_setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 263 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 264 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 265 | } |
| 266 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 267 | /* |
| 268 | * int |
| 269 | * setup1() - setup function for a test condition for which stat(2) |
| 270 | * returns -1 and sets errno to EACCES. |
| 271 | * Create a test directory under temporary directory and create a test file |
| 272 | * under this directory with mode "0666" permissions. |
| 273 | * Modify the mode permissions on test directory such that process will not |
| 274 | * have search permissions on test directory. |
| 275 | * |
| 276 | * The function returns 0. |
| 277 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 278 | int setup1(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 279 | { |
| 280 | int fd; /* file handle for testfile */ |
| 281 | |
| 282 | /* Creat a test directory */ |
| 283 | if (mkdir(DIR_TEMP, MODE_RWX) < 0) { |
| 284 | tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 285 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 286 | |
| 287 | /* Creat a test file under above test directory */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 288 | if ((fd = open(TEST_FILE1, O_RDWR | O_CREAT, 0666)) == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 289 | tst_brkm(TBROK, cleanup, |
| 290 | "open(%s, O_RDWR|O_CREAT, 0666) failed, errno=%d : %s", |
| 291 | TEST_FILE1, errno, strerror(errno)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 292 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 293 | /* Close the test file */ |
| 294 | if (close(fd) == -1) { |
| 295 | tst_brkm(TBROK, cleanup, |
| 296 | "close(%s) Failed, errno=%d : %s", |
| 297 | TEST_FILE1, errno, strerror(errno)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 298 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 299 | |
| 300 | /* Modify mode permissions on test directory */ |
| 301 | if (chmod(DIR_TEMP, FILE_MODE) < 0) { |
| 302 | tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", DIR_TEMP); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 303 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * int |
| 309 | * setup2() - setup function for a test condition for which stat(2) |
| 310 | * returns -1 and sets errno to ENOTDIR. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 311 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 312 | * Create a test file under temporary directory so that test tries to |
| 313 | * change mode of a testfile "tfile_2" under "t_file" which happens to be |
| 314 | * another regular file. |
| 315 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 316 | int setup2(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 317 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 318 | int fd; /* File handle for test file */ |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 319 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 320 | /* Creat a test file under temporary directory */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 321 | if ((fd = open("t_file", O_RDWR | O_CREAT, MODE_RWX)) == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 322 | tst_brkm(TBROK, cleanup, |
| 323 | "open(2) on t_file failed, errno=%d : %s", |
| 324 | errno, strerror(errno)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 325 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 326 | /* Close the test file created above */ |
| 327 | if (close(fd) == -1) { |
| 328 | tst_brkm(TBROK, cleanup, |
| 329 | "close(t_file) Failed, errno=%d : %s", |
| 330 | errno, strerror(errno)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 331 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * int |
| 337 | * longpath_setup() - setup to create a node with a name length exceeding |
| 338 | * the MAX. length of PATH_MAX. |
| 339 | * This function retruns 0. |
| 340 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 341 | int longpath_setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 342 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 343 | int ind; /* counter variable */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 344 | |
| 345 | for (ind = 0; ind <= (PATH_MAX + 1); ind++) { |
| 346 | Longpathname[ind] = 'a'; |
| 347 | } |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | /* |
| 352 | * void |
| 353 | * cleanup() - Performs all ONE TIME cleanup for this test at |
| 354 | * completion or premature exit. |
| 355 | * Print test timing stats and errno log if test executed with options. |
| 356 | * Remove temporary directory and sub-directories/files under it |
| 357 | * created during setup(). |
| 358 | * Exit the test program with normal exit code. |
| 359 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 360 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 361 | { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 362 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 363 | /* Restore mode permissions on test directory created in setup2() */ |
| 364 | if (chmod(DIR_TEMP, MODE_RWX) < 0) { |
| 365 | tst_brkm(TFAIL, NULL, "chmod(2) of %s failed", DIR_TEMP); |
| 366 | } |
| 367 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 368 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 369 | } |