fsx: Fix -P errors
authorAndreas Gruenbacher <agruenba@redhat.com>
Wed, 21 Feb 2018 10:55:20 +0000 (11:55 +0100)
committerEryu Guan <eguan@redhat.com>
Thu, 22 Feb 2018 07:44:30 +0000 (15:44 +0800)
When -P is used, report the correct *.fsxgood filename in
report_failure and fix the default *.fsxops filename.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
ltp/fsx.c

index 9c358f27bd925eddc3b85bf2a4cb4668b8ce75e2..ac9e929180e280318d1a993aa0e174dc96b530de 100644 (file)
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -121,6 +121,7 @@ char        *bname;                         /* basename of our test file */
 char   *logdev;                        /* -i flag */
 char   *logid;                         /* -j flag */
 char   dname[1024];                    /* -P flag */
+char   goodfile[1024];
 int    dirpath = 0;                    /* -P flag */
 int    fd;                             /* fd for our test file */
 
@@ -510,8 +511,8 @@ report_failure(int status)
                if (good_buf) {
                        save_buffer(good_buf, file_size, fsxgoodfd);
                        prt("Correct content saved for comparison\n");
-                       prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
-                           fname, fname);
+                       prt("(maybe hexdump \"%s\" vs \"%s\")\n",
+                           fname, goodfile);
                }
                close(fsxgoodfd);
        }
@@ -1864,12 +1865,10 @@ main(int argc, char **argv)
 {
        int     i, style, ch;
        char    *endp, *tmp;
-       char goodfile[1024];
        char logfile[1024];
        struct stat statbuf;
        int o_flags = O_RDWR|O_CREAT|O_TRUNC;
 
-       goodfile[0] = 0;
        logfile[0] = 0;
        dname[0] = 0;
 
@@ -2027,10 +2026,6 @@ main(int argc, char **argv)
                        strncpy(dname, optarg, sizeof(dname));
                        strcat(dname, "/");
                        dirpath = strlen(dname);
-
-                       strncpy(goodfile, dname, sizeof(goodfile));
-                       strncpy(logfile, dname, sizeof(logfile));
-                       strncpy(opsfile, dname, sizeof(logfile));
                        break;
                 case 'R':
                         mapped_reads = 0;
@@ -2124,24 +2119,28 @@ main(int argc, char **argv)
                }
        }
 #endif
-       strncat(goodfile, dirpath ? bname : fname, 256);
-       strcat (goodfile, ".fsxgood");
+
+       if (dirpath) {
+               snprintf(goodfile, sizeof(goodfile), "%s%s.fsxgood", dname, bname);
+               snprintf(logfile, sizeof(logfile), "%s%s.fsxlog", dname, bname);
+               if (!*opsfile)
+                       snprintf(opsfile, sizeof(opsfile), "%s%s.fsxops", dname, bname);
+       } else {
+               snprintf(goodfile, sizeof(goodfile), "%s.fsxgood", fname);
+               snprintf(logfile, sizeof(logfile), "%s.fsxlog", fname);
+               if (!*opsfile)
+                       snprintf(opsfile, sizeof(opsfile), "%s.fsxops", fname);
+       }
        fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
        if (fsxgoodfd < 0) {
                prterr(goodfile);
                exit(92);
        }
-       strncat(logfile, dirpath ? bname : fname, 256);
-       strcat (logfile, ".fsxlog");
        fsxlogf = fopen(logfile, "w");
        if (fsxlogf == NULL) {
                prterr(logfile);
                exit(93);
        }
-       if (!*opsfile) {
-               strncat(opsfile, dirpath ? bname : fname, 256);
-               strcat(opsfile, ".fsxops");
-       }
        unlink(opsfile);
 
        if (replayops) {