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