Whamcloud - gitweb
b=19919 support relative path in llapi_search_fsname()
authoryangsheng <Sheng.Yang@Sun.COM>
Fri, 19 Mar 2010 06:49:24 +0000 (14:49 +0800)
committerJohann Lombardi <johann@sun.com>
Fri, 19 Mar 2010 11:21:24 +0000 (12:21 +0100)
i=adilger
i=johann

Use realpath() to provide absolute pathname.

lustre/utils/liblustreapi.c

index c8ae1d3..4e3360b 100644 (file)
@@ -607,8 +607,19 @@ int llapi_search_mounts(const char *pathname, int index, char *mntdir,
 
 int llapi_search_fsname(const char *pathname, char *fsname)
 {
+        char *path = (char*)pathname, buf[PATH_MAX + 1];
+
+        if (pathname[0] != '/') { /* Need a absolute path */
+                memset(buf, '\0', sizeof(buf));
+                if (realpath(pathname, buf) == NULL) {
+                        llapi_err(LLAPI_MSG_ERROR, "pathname '%s' cannot expand",
+                                  pathname);
+                        return -EINVAL;
+                }
+                path = buf;
+        }
         return get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL,
-                             (char *)pathname, -1);
+                             path, -1);
 }
 
 /* return the first file matching this pattern */