From: Erik van der Kouwe Date: Wed, 9 Dec 2009 07:59:08 +0000 (+0000) Subject: Use subdirectory t43 for tests X-Git-Tag: v3.1.6~160 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/host.html?a=commitdiff_plain;h=54c05bc2bdac46fc0f55862c1e7b01b6bf4cda23;p=minix.git Use subdirectory t43 for tests --- diff --git a/test/Makefile b/test/Makefile index f68e4dee6..8002d590a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -8,7 +8,7 @@ OBJ= test1 test2 test3 test4 test5 test6 test7 test8 test9 \ test21 test22 test23 test25 test26 test27 test28 test29 \ test30 test31 test32 test34 test35 test36 test37 test38 \ test39 t10a t11a t11b test40 t40a t40b t40c t40d t40e t40f test41 \ - test42 + test42 test44 BIGOBJ= test20 test24 ROOTOBJ= test11 test33 test43 @@ -30,7 +30,7 @@ $(ROOTOBJ): clean: cd select && make clean -rm -rf *.o *.s *.bak test? test?? t10a t11a t11b \ - t40a t40b t40c t40d t40e t40f DIR* + t40a t40b t40c t40d t40e t40f t43 DIR* test1: test1.c test2: test2.c diff --git a/test/test43.c b/test/test43.c index 35e07fdd8..6e9ade486 100644 --- a/test/test43.c +++ b/test/test43.c @@ -205,8 +205,9 @@ static void check_realpath_recurse(const char *path, int depth) if (closedir(dir) < 0) ERR; } -#define PATH_DEPTH 3 -#define L(x) "/t43_link_" #x ".tmp" +#define PATH_DEPTH 4 +#define PATH_BASE "/t43" +#define L(x) PATH_BASE "/link_" #x ".tmp" static char basepath[PATH_MAX + 1]; @@ -237,15 +238,54 @@ static char *addbasepath(char *buffer, const char *path) return buffer; } -static void cleanup(int silent) +static void cleanup(const char *path) { - char buffer[PATH_MAX + 1]; + DIR *dir; + struct dirent *dirent; + char pathsub[PATH_MAX + 1]; + struct stat statbuf; + + /* determine file type, avoid following links */ + if (lstat(path, &statbuf) < 0) + { + if (errno != ENOENT) ERR; + return; + } + + /* only recursively process directories (NOT symlinks!) */ + if ((statbuf.st_mode & S_IFMT) != S_IFDIR) + { + if (unlink(path) < 0) ERR; + return; + } + + /* loop through subdirectories (excluding . and ..) */ + if (!(dir = opendir(path))) + { + ERR; + return; + } + while (dirent = readdir(dir)) + { + /* ignore current and parent directories */ + if (strcmp(dirent->d_name, ".") == 0 || + strcmp(dirent->d_name, "..") == 0) + continue; + + /* build path */ + if (!pathncat(pathsub, sizeof(pathsub), path, dirent->d_name)) + { + ERR; + continue; + } + + /* delete path */ + cleanup(pathsub); + } + if (closedir(dir) < 0) ERR; - if (unlink(addbasepath(buffer, L(1))) < 0 && !silent) ERR; - if (unlink(addbasepath(buffer, L(2))) < 0 && !silent) ERR; - if (unlink(addbasepath(buffer, L(3))) < 0 && !silent) ERR; - if (unlink(addbasepath(buffer, L(4))) < 0 && !silent) ERR; - if (unlink(addbasepath(buffer, L(5))) < 0 && !silent) ERR; + /* remove the (now empty) directory itself */ + if (rmdir(path) < 0) ERR; } int main(int argc, char **argv) @@ -257,9 +297,10 @@ int main(int argc, char **argv) fflush(stdout); executable = argv[0]; getcwd(basepath, sizeof(basepath)); - cleanup(1); + cleanup(addbasepath(buffer1, PATH_BASE)); /* prepare some symlinks to make it more difficult */ + if (mkdir(addbasepath(buffer1, PATH_BASE), S_IRWXU) < 0) ERR; if (symlink("/", addbasepath(buffer1, L(1))) < 0) ERR; if (symlink(basepath, addbasepath(buffer1, L(2))) < 0) ERR; @@ -275,7 +316,7 @@ int main(int argc, char **argv) check_realpath_step_by_step(addbasepath(buffer1, L(5)), ELOOP); /* delete the symlinks */ - cleanup(0); + cleanup(addbasepath(buffer1, PATH_BASE)); /* done */ quit();