Whamcloud - gitweb
Branch b1_8
[fs/lustre-release.git] / lustre / tests / fsx.c
index 6cf43ee..dafa888 100644 (file)
@@ -438,21 +438,21 @@ assign_fd_policy(char *policy)
        }
 }
 
-int 
+int
 get_fd(void)
 {
        struct test_file *tf = get_tf();
        return tf->fd;
 }
 
-static const char *basename(const char *path)
+static const char *my_basename(const char *path)
 {
        char *c = strrchr(path, '/');
 
        return c ? c++ : path;
 }
 
-void 
+void
 open_test_files(char **argv, int argc)
 {
        struct test_file *tf;
@@ -529,8 +529,15 @@ check_trunc_hack(void)
        struct stat statbuf;
        int fd = get_fd();
 
-       ftruncate(fd, (off_t)0);
-       ftruncate(fd, (off_t)100000);
+        /* should not ignore ftruncate(2)'s return value */
+        if (ftruncate(fd, (off_t)0) < 0) {
+                prterr("trunc_hack: ftruncate(0)");
+                exit(1);
+        }
+        if (ftruncate(fd, (off_t)100000) < 0) {
+                prterr("trunc_hack: ftruncate(100000)");
+                exit(1);
+        }
        if (fstat(fd, &statbuf)) {
                prterr("trunc_hack: fstat");
                statbuf.st_size = -1;
@@ -539,7 +546,10 @@ check_trunc_hack(void)
                prt("no extend on truncate! not posix!\n");
                exit(130);
        }
-       ftruncate(fd, 0);
+        if (ftruncate(fd, 0) < 0) {
+                prterr("trunc_hack: ftruncate(0) (2nd call)");
+                exit(1);
+        }
 }
 
 static char *tf_buf = NULL;
@@ -1334,14 +1344,14 @@ main(int argc, char **argv)
 
        open_test_files(argv, argc);
 
-       strncat(goodfile, dirpath ? basename(fname) : fname, 256);
+       strncat(goodfile, dirpath ? my_basename(fname) : fname, 256);
        strcat (goodfile, ".fsxgood");
        fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
        if (fsxgoodfd < 0) {
                prterr(goodfile);
                exit(92);
        }
-       strncat(logfile, dirpath ? basename(fname) : fname, 256);
+       strncat(logfile, dirpath ? my_basename(fname) : fname, 256);
        strcat (logfile, ".fsxlog");
        fsxlogf = fopen(logfile, "w");
        if (fsxlogf == NULL) {