diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-02 14:24:59 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2011-08-02 14:24:59 +0000 |
commit | 6fed43eabc0e78606cf80439c536a00be18fd743 (patch) | |
tree | f74fea0e1e6b46a7acea595ad70131a6b25f34df /testsuites/fstests/support/fstest_support.c | |
parent | 2011-08-02 Ricardo Aguirre <el.mastin@ymail.com> (diff) | |
download | rtems-6fed43eabc0e78606cf80439c536a00be18fd743.tar.bz2 |
2011-08-02 Xiang Cui <medivhc@gmail.com>
* configure.ac, fserror/test.c, fslink/test.c, fspermission/test.c,
fsrdwr/init.c, fssymlink/test.c, fstime/test.c,
mdosfs_support/fs_config.h, mdosfs_support/fs_support.c,
mimfs_support/fs_support.c, mrfs_support/fs_config.h,
support/fstest.h, support/fstest_support.c,
support/ramdisk_support.c, support/ramdisk_support.h: Perform first
phase of clean up.
Diffstat (limited to 'testsuites/fstests/support/fstest_support.c')
-rw-r--r-- | testsuites/fstests/support/fstest_support.c | 98 |
1 files changed, 48 insertions, 50 deletions
diff --git a/testsuites/fstests/support/fstest_support.c b/testsuites/fstests/support/fstest_support.c index 4202a1040f..6c678891f7 100644 --- a/testsuites/fstests/support/fstest_support.c +++ b/testsuites/fstests/support/fstest_support.c @@ -8,14 +8,13 @@ * * $Id Exp $ */ - -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include <string.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> +#include <stdio.h> +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/types.h> #include "rtems.h" @@ -24,57 +23,57 @@ #include "fstest.h" -#define TEMP_DIR "waterbuffalo" +#define TEMP_DIR "waterbuffalo" -/* Break out of a chroot() environment in C */ +/* Break out of a chroot() environment in C */ void break_out_of_chroot(void) { - int dir_fd; /* File descriptor to directory */ - struct stat sbuf; /* The stat() buffer */ + int dir_fd; /* File descriptor to directory */ + struct stat sbuf; /* The stat() buffer */ chdir("/"); - if (stat(TEMP_DIR,&sbuf)<0) { - if (errno==ENOENT) { - if (mkdir(TEMP_DIR,0755)<0) { - fprintf(stderr,"Failed to create %s - %s\n", TEMP_DIR, - strerror(errno)); - exit(1); - } - } else { - fprintf(stderr,"Failed to stat %s - %s\n", TEMP_DIR, - strerror(errno)); - exit(1); - } - } else if (!S_ISDIR(sbuf.st_mode)) { - fprintf(stderr,"Error - %s is not a directory!\n",TEMP_DIR); - exit(1); - } - - if ((dir_fd=open(".",O_RDONLY))<0) { - fprintf(stderr,"Failed to open \".\" for reading - %s\n", strerror(errno)); - exit(1); - } - - if (chroot(TEMP_DIR)<0) { - fprintf(stderr,"Failed to chroot to %s - %s\n",TEMP_DIR, - strerror(errno)); - exit(1); - } - - if (fchdir(dir_fd)<0) { - fprintf(stderr,"Failed to fchdir - %s\n", - strerror(errno)); - exit(1); - } - close(dir_fd); - chdir(".."); - chroot("."); + if (stat(TEMP_DIR,&sbuf)<0) { + if (errno==ENOENT) { + if (mkdir(TEMP_DIR,0755)<0) { + fprintf(stderr,"Failed to create %s - %s\n", TEMP_DIR, + strerror(errno)); + exit(1); + } + } else { + fprintf(stderr,"Failed to stat %s - %s\n", TEMP_DIR, + strerror(errno)); + exit(1); + } + } else if (!S_ISDIR(sbuf.st_mode)) { + fprintf(stderr,"Error - %s is not a directory!\n",TEMP_DIR); + exit(1); + } + + if ((dir_fd=open(".",O_RDONLY))<0) { + fprintf(stderr,"Failed to open ""." + " for reading - %s\n", strerror(errno)); + exit(1); + } + + if (chroot(TEMP_DIR)<0) { + fprintf(stderr,"Failed to chroot to %s - %s\n",TEMP_DIR, + strerror(errno)); + exit(1); + } + + if (fchdir(dir_fd)<0) { + fprintf(stderr,"Failed to fchdir - %s\n", + strerror(errno)); + exit(1); + } + close(dir_fd); + chdir(".."); + chroot("."); } - /* * Main entry point of every filesystem test */ @@ -103,5 +102,4 @@ rtems_task Init( puts( "*** END OF FILE SYSTEM TEST ( " FILESYSTEM " ) ***" ); rtems_test_exit(0); - } |