Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 1 | /********************************************************** |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 3 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 7 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 11 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 18 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 22 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 31 | *********************************************************/ |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 32 | |
| 33 | /********************************************************** |
| 34 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 35 | * OS Testing - Silicon Graphics, Inc. |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 36 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 37 | * FUNCTION NAME : tst_tmpdir, tst_rmdir |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 38 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 39 | * FUNCTION TITLE : Create/remove a testing temp dir |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 40 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 41 | * SYNOPSIS: |
| 42 | * void tst_tmpdir(); |
| 43 | * void tst_rmdir(); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 44 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 45 | * AUTHOR : Dave Fenner |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 46 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 47 | * INITIAL RELEASE : UNICOS 8.0 |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 48 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 49 | * DESCRIPTION |
| 50 | * tst_tmpdir() is used to create a unique, temporary testing |
| 51 | * directory, and make it the current working directory. |
| 52 | * tst_rmdir() is used to remove the directory created by |
| 53 | * tst_tmpdir(). |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 54 | * |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 55 | * RETURN VALUE |
| 56 | * Neither tst_tmpdir() or tst_rmdir() has a return value. |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 57 | * |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 58 | *********************************************************/ |
Xiao Yang | 8f8ff10 | 2017-02-14 11:09:29 +0800 | [diff] [blame] | 59 | #define _GNU_SOURCE |
Stanislav Kholmanskikh | 5702765 | 2015-05-26 13:21:10 +0300 | [diff] [blame] | 60 | #include <sys/mman.h> |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 61 | #include <sys/types.h> |
| 62 | #include <sys/stat.h> |
Garrett Cooper | b1c7c6b | 2010-12-20 07:09:47 -0800 | [diff] [blame] | 63 | #include <assert.h> |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 64 | #include <errno.h> |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 65 | #include <libgen.h> |
| 66 | #include <stdio.h> |
| 67 | #include <stdlib.h> |
| 68 | #include <string.h> |
| 69 | #include <unistd.h> |
Cyril Hrubis | fc0c72a | 2017-02-13 15:35:09 +0100 | [diff] [blame] | 70 | #include <dirent.h> |
| 71 | #include <fcntl.h> |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 72 | |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 73 | #include "test.h" |
Cyril Hrubis | b0832a7 | 2017-10-03 13:41:18 +0200 | [diff] [blame] | 74 | #include "safe_macros.h" |
Cyril Hrubis | ed69cd5 | 2013-06-24 17:51:00 +0200 | [diff] [blame] | 75 | #include "ltp_priv.h" |
Stanislav Kholmanskikh | 5702765 | 2015-05-26 13:21:10 +0300 | [diff] [blame] | 76 | #include "lapi/futex.h" |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Define some useful macros. |
| 80 | */ |
Garrett Cooper | 1f3c236 | 2010-12-16 22:05:45 -0800 | [diff] [blame] | 81 | #define DIR_MODE (S_IRWXU|S_IRWXG|S_IRWXO) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 82 | |
| 83 | #ifndef PATH_MAX |
| 84 | #ifdef MAXPATHLEN |
Garrett Cooper | 1f3c236 | 2010-12-16 22:05:45 -0800 | [diff] [blame] | 85 | #define PATH_MAX MAXPATHLEN |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 86 | #else |
Garrett Cooper | 1f3c236 | 2010-12-16 22:05:45 -0800 | [diff] [blame] | 87 | #define PATH_MAX 1024 |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 88 | #endif |
| 89 | #endif |
| 90 | |
| 91 | /* |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 92 | * Define global variables. |
| 93 | */ |
Garrett Cooper | db97680 | 2010-12-16 15:56:25 -0800 | [diff] [blame] | 94 | extern char *TCID; /* defined/initialized in main() */ |
| 95 | static char *TESTDIR = NULL; /* the directory created */ |
| 96 | |
Cyril Hrubis | 69c2ab0 | 2012-12-12 17:22:29 +0100 | [diff] [blame] | 97 | static char test_start_work_dir[PATH_MAX]; |
| 98 | |
Stanislav Kholmanskikh | 5702765 | 2015-05-26 13:21:10 +0300 | [diff] [blame] | 99 | /* lib/tst_checkpoint.c */ |
| 100 | extern futex_t *tst_futexes; |
Cyril Hrubis | 69c2ab0 | 2012-12-12 17:22:29 +0100 | [diff] [blame] | 101 | |
Cyril Hrubis | ab8388c | 2012-11-28 15:42:17 +0100 | [diff] [blame] | 102 | int tst_tmpdir_created(void) |
| 103 | { |
| 104 | return TESTDIR != NULL; |
| 105 | } |
| 106 | |
Cyril Hrubis | 9c31ad2 | 2014-05-14 17:15:39 +0200 | [diff] [blame] | 107 | char *tst_get_tmpdir(void) |
Garrett Cooper | db97680 | 2010-12-16 15:56:25 -0800 | [diff] [blame] | 108 | { |
Cyril Hrubis | d101cab | 2017-02-14 11:48:46 +0100 | [diff] [blame] | 109 | if (TESTDIR == NULL) { |
Garrett Cooper | b1c7c6b | 2010-12-20 07:09:47 -0800 | [diff] [blame] | 110 | tst_brkm(TBROK, NULL, "you must call tst_tmpdir() first"); |
Cyril Hrubis | d101cab | 2017-02-14 11:48:46 +0100 | [diff] [blame] | 111 | return NULL; |
| 112 | } |
| 113 | |
Garrett Cooper | db97680 | 2010-12-16 15:56:25 -0800 | [diff] [blame] | 114 | return strdup(TESTDIR); |
| 115 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 116 | |
Cyril Hrubis | 69c2ab0 | 2012-12-12 17:22:29 +0100 | [diff] [blame] | 117 | const char *tst_get_startwd(void) |
| 118 | { |
| 119 | return test_start_work_dir; |
| 120 | } |
| 121 | |
Cyril Hrubis | fc0c72a | 2017-02-13 15:35:09 +0100 | [diff] [blame] | 122 | static int rmobj(char *obj, char **errmsg) |
| 123 | { |
| 124 | int ret_val = 0; |
| 125 | DIR *dir; |
| 126 | struct dirent *dir_ent; |
| 127 | char dirobj[PATH_MAX]; |
| 128 | struct stat statbuf; |
| 129 | static char err_msg[1024]; |
| 130 | int fd; |
| 131 | |
| 132 | fd = open(obj, O_DIRECTORY | O_NOFOLLOW); |
| 133 | if (fd != -1) { |
| 134 | close(fd); |
| 135 | |
| 136 | /* Do NOT perform the request if the directory is "/" */ |
| 137 | if (!strcmp(obj, "/")) { |
| 138 | if (errmsg != NULL) { |
| 139 | sprintf(err_msg, "Cannot remove /"); |
| 140 | *errmsg = err_msg; |
| 141 | } |
| 142 | return -1; |
| 143 | } |
| 144 | |
| 145 | /* Open the directory to get access to what is in it */ |
| 146 | if ((dir = opendir(obj)) == NULL) { |
| 147 | if (rmdir(obj) != 0) { |
| 148 | if (errmsg != NULL) { |
| 149 | sprintf(err_msg, |
| 150 | "rmdir(%s) failed; errno=%d: %s", |
| 151 | obj, errno, tst_strerrno(errno)); |
| 152 | *errmsg = err_msg; |
| 153 | } |
| 154 | return -1; |
| 155 | } else { |
| 156 | return 0; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /* Loop through the entries in the directory, removing each one */ |
| 161 | for (dir_ent = (struct dirent *)readdir(dir); |
| 162 | dir_ent != NULL; dir_ent = (struct dirent *)readdir(dir)) { |
| 163 | |
| 164 | /* Don't remove "." or ".." */ |
| 165 | if (!strcmp(dir_ent->d_name, ".") |
| 166 | || !strcmp(dir_ent->d_name, "..")) |
| 167 | continue; |
| 168 | |
| 169 | /* Recursively call this routine to remove the current entry */ |
| 170 | sprintf(dirobj, "%s/%s", obj, dir_ent->d_name); |
| 171 | if (rmobj(dirobj, errmsg) != 0) |
| 172 | ret_val = -1; |
| 173 | } |
| 174 | |
| 175 | closedir(dir); |
| 176 | |
| 177 | /* If there were problems removing an entry, don't attempt to |
| 178 | remove the directory itself */ |
| 179 | if (ret_val == -1) |
| 180 | return -1; |
| 181 | |
| 182 | /* Get the link count, now that all the entries have been removed */ |
| 183 | if (lstat(obj, &statbuf) < 0) { |
| 184 | if (errmsg != NULL) { |
| 185 | sprintf(err_msg, |
| 186 | "lstat(%s) failed; errno=%d: %s", obj, |
| 187 | errno, tst_strerrno(errno)); |
| 188 | *errmsg = err_msg; |
| 189 | } |
| 190 | return -1; |
| 191 | } |
| 192 | |
| 193 | /* Remove the directory itself */ |
| 194 | if (statbuf.st_nlink >= 3) { |
| 195 | /* The directory is linked; unlink() must be used */ |
| 196 | if (unlink(obj) < 0) { |
| 197 | if (errmsg != NULL) { |
| 198 | sprintf(err_msg, |
| 199 | "unlink(%s) failed; errno=%d: %s", |
| 200 | obj, errno, tst_strerrno(errno)); |
| 201 | *errmsg = err_msg; |
| 202 | } |
| 203 | return -1; |
| 204 | } |
| 205 | } else { |
| 206 | /* The directory is not linked; remove() can be used */ |
| 207 | if (remove(obj) < 0) { |
| 208 | if (errmsg != NULL) { |
| 209 | sprintf(err_msg, |
| 210 | "remove(%s) failed; errno=%d: %s", |
| 211 | obj, errno, tst_strerrno(errno)); |
| 212 | *errmsg = err_msg; |
| 213 | } |
| 214 | return -1; |
| 215 | } |
| 216 | } |
| 217 | } else { |
| 218 | if (unlink(obj) < 0) { |
| 219 | if (errmsg != NULL) { |
| 220 | sprintf(err_msg, |
| 221 | "unlink(%s) failed; errno=%d: %s", obj, |
| 222 | errno, tst_strerrno(errno)); |
| 223 | *errmsg = err_msg; |
| 224 | } |
| 225 | return -1; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 232 | void tst_tmpdir(void) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 233 | { |
Garrett Cooper | db97680 | 2010-12-16 15:56:25 -0800 | [diff] [blame] | 234 | char template[PATH_MAX]; |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 235 | char *env_tmpdir; |
| 236 | char *errmsg, *c; |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 237 | |
Garrett Cooper | db97680 | 2010-12-16 15:56:25 -0800 | [diff] [blame] | 238 | /* |
Marios Makris | c128c45 | 2012-08-09 20:36:50 +0300 | [diff] [blame] | 239 | * Create a template for the temporary directory. Use the |
| 240 | * environment variable TMPDIR if it is available, otherwise |
| 241 | * use our default TEMPDIR. |
nstraz | ffe35e2 | 2001-03-13 16:33:54 +0000 | [diff] [blame] | 242 | */ |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 243 | env_tmpdir = getenv("TMPDIR"); |
| 244 | if (env_tmpdir) { |
| 245 | c = strchr(env_tmpdir, '/'); |
| 246 | /* |
| 247 | * Now we force environment variable TMPDIR to be an absolute |
| 248 | * pathname, which dose not make much sense, but it will |
| 249 | * greatly simplify code in tst_rmdir(). |
| 250 | */ |
| 251 | if (c != env_tmpdir) { |
Alexey Kodanev | 15634ea | 2016-06-20 17:53:03 +0300 | [diff] [blame] | 252 | tst_brkm(TBROK, NULL, "You must specify an absolute " |
| 253 | "pathname for environment variable TMPDIR"); |
Cyril Hrubis | d101cab | 2017-02-14 11:48:46 +0100 | [diff] [blame] | 254 | return; |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 255 | } |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 256 | snprintf(template, PATH_MAX, "%s/%.3sXXXXXX", env_tmpdir, TCID); |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 257 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 258 | snprintf(template, PATH_MAX, "%s/%.3sXXXXXX", TEMPDIR, TCID); |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 259 | } |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 260 | |
Marios Makris | c128c45 | 2012-08-09 20:36:50 +0300 | [diff] [blame] | 261 | /* Make the temporary directory in one shot using mkdtemp. */ |
Cyril Hrubis | d101cab | 2017-02-14 11:48:46 +0100 | [diff] [blame] | 262 | if (mkdtemp(template) == NULL) { |
Alexey Kodanev | 15634ea | 2016-06-20 17:53:03 +0300 | [diff] [blame] | 263 | tst_brkm(TBROK | TERRNO, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 264 | "%s: mkdtemp(%s) failed", __func__, template); |
Cyril Hrubis | d101cab | 2017-02-14 11:48:46 +0100 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
| 268 | if ((TESTDIR = strdup(template)) == NULL) { |
Alexey Kodanev | 15634ea | 2016-06-20 17:53:03 +0300 | [diff] [blame] | 269 | tst_brkm(TBROK | TERRNO, NULL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 270 | "%s: strdup(%s) failed", __func__, template); |
Cyril Hrubis | d101cab | 2017-02-14 11:48:46 +0100 | [diff] [blame] | 271 | return; |
| 272 | } |
nstraz | ffe35e2 | 2001-03-13 16:33:54 +0000 | [diff] [blame] | 273 | |
Cyril Hrubis | 3b11765 | 2017-10-03 13:42:10 +0200 | [diff] [blame] | 274 | SAFE_CHOWN(NULL, TESTDIR, -1, getgid()); |
Cyril Hrubis | d101cab | 2017-02-14 11:48:46 +0100 | [diff] [blame] | 275 | |
Cyril Hrubis | b0832a7 | 2017-10-03 13:41:18 +0200 | [diff] [blame] | 276 | SAFE_CHMOD(NULL, TESTDIR, DIR_MODE); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 277 | |
Cyril Hrubis | 69c2ab0 | 2012-12-12 17:22:29 +0100 | [diff] [blame] | 278 | if (getcwd(test_start_work_dir, sizeof(test_start_work_dir)) == NULL) { |
| 279 | tst_resm(TINFO, "Failed to record test working dir"); |
| 280 | test_start_work_dir[0] = '\0'; |
| 281 | } |
| 282 | |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 283 | /* |
| 284 | * Change to the temporary directory. If the chdir() fails, issue |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 285 | * TBROK messages for all test cases, attempt to remove the |
nstraz | ffe35e2 | 2001-03-13 16:33:54 +0000 | [diff] [blame] | 286 | * directory (if it was created), and exit. If the removal also |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 287 | * fails, also issue a TWARN message. |
nstraz | ffe35e2 | 2001-03-13 16:33:54 +0000 | [diff] [blame] | 288 | */ |
Garrett Cooper | 903910d | 2010-11-23 09:27:44 -0800 | [diff] [blame] | 289 | if (chdir(TESTDIR) == -1) { |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 290 | tst_resm(TERRNO, "%s: chdir(%s) failed", __func__, TESTDIR); |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 291 | |
nstraz | ffe35e2 | 2001-03-13 16:33:54 +0000 | [diff] [blame] | 292 | /* Try to remove the directory */ |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 293 | if (rmobj(TESTDIR, &errmsg) == -1) { |
Marios Makris | c128c45 | 2012-08-09 20:36:50 +0300 | [diff] [blame] | 294 | tst_resm(TWARN, "%s: rmobj(%s) failed: %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 295 | __func__, TESTDIR, errmsg); |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 296 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 297 | |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 298 | tst_exit(); |
nstraz | ffe35e2 | 2001-03-13 16:33:54 +0000 | [diff] [blame] | 299 | } |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 300 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 301 | |
subrata_modak | 88c166c | 2009-06-09 16:01:20 +0000 | [diff] [blame] | 302 | void tst_rmdir(void) |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 303 | { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 304 | char *errmsg; |
vapier | 45a8ba0 | 2009-07-20 10:59:32 +0000 | [diff] [blame] | 305 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 306 | /* |
| 307 | * Check that TESTDIR is not NULL. |
| 308 | */ |
| 309 | if (TESTDIR == NULL) { |
Garrett Cooper | db97680 | 2010-12-16 15:56:25 -0800 | [diff] [blame] | 310 | tst_resm(TWARN, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 311 | "%s: TESTDIR was NULL; no removal attempted", |
| 312 | __func__); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 313 | return; |
| 314 | } |
alaffin | cc2e555 | 2000-07-27 17:13:18 +0000 | [diff] [blame] | 315 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 316 | /* |
Stanislav Kholmanskikh | 5702765 | 2015-05-26 13:21:10 +0300 | [diff] [blame] | 317 | * Unmap the backend file. |
| 318 | * This is needed to overcome the NFS "silly rename" feature. |
| 319 | */ |
Stanislav Kholmanskikh | 401d0cb | 2015-05-28 11:58:10 +0300 | [diff] [blame] | 320 | if (tst_futexes) { |
| 321 | msync((void *)tst_futexes, getpagesize(), MS_SYNC); |
Stanislav Kholmanskikh | 5702765 | 2015-05-26 13:21:10 +0300 | [diff] [blame] | 322 | munmap((void *)tst_futexes, getpagesize()); |
Stanislav Kholmanskikh | 401d0cb | 2015-05-28 11:58:10 +0300 | [diff] [blame] | 323 | } |
Stanislav Kholmanskikh | 5702765 | 2015-05-26 13:21:10 +0300 | [diff] [blame] | 324 | |
| 325 | /* |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 326 | * Attempt to remove the "TESTDIR" directory, using rmobj(). |
| 327 | */ |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 328 | if (rmobj(TESTDIR, &errmsg) == -1) { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 329 | tst_resm(TWARN, "%s: rmobj(%s) failed: %s", |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 330 | __func__, TESTDIR, errmsg); |
Xiaoguang Wang | 33a4adf | 2014-07-30 12:09:40 +0800 | [diff] [blame] | 331 | } |
Marios Makris | 60b1baa | 2012-08-09 20:36:46 +0300 | [diff] [blame] | 332 | } |