]> granicus.if.org Git - zfs/commitdiff
Fix do_link portion of ctime test
authorNikolay Borisov <n.borisov.lkml@gmail.com>
Tue, 16 Aug 2016 20:00:16 +0000 (23:00 +0300)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 16 Aug 2016 22:30:20 +0000 (15:30 -0700)
From the man page of dirname: " Both dirname() and basename()
may modify the contents of path, so it may be desirable to pass
a copy when calling one of these functions." And in fact on linux
using dirname actually changes the contents of the passed parameter as
evident from the following failure when running the ctime test:

link(/root/zfs-mount, /root/zfs-mount/link_file)

Fix this by creating a copy of the input parameter and passing that
to dirname, thus not compromising the original parameter, allowing
the creation of hard link to succeed.

Signed-off-by: Nikolay Borisov <n.borisov.lkml@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4977

tests/zfs-tests/tests/functional/ctime/ctime_001_pos.c

index 0c0615ff531cf0a85a109cd715175f52ff0216e7..e1b244ee9a5d5c2e8dfe3d447dd23a2fc6a6838b 100644 (file)
@@ -145,17 +145,19 @@ do_link(const char *pfile)
 {
        int ret = 0;
        char link_file[BUFSIZ] = { 0 };
+       char pfile_copy[BUFSIZ] = { 0 };
        char *dname;
 
        if (pfile == NULL) {
                return (-1);
        }
 
+       strcpy(pfile_copy, pfile);
        /*
         * Figure out source file directory name, and create
         * the link file in the same directory.
         */
-       dname = dirname((char *)pfile);
+       dname = dirname((char *)pfile_copy);
        (void) snprintf(link_file, BUFSIZ, "%s/%s", dname, "link_file");
 
        if (link(pfile, link_file) == -1) {