]> git.proxmox.com Git - mirror_lxc.git/commitdiff
Make use of realpath
authordlezcano <dlezcano>
Mon, 16 Feb 2009 10:14:34 +0000 (10:14 +0000)
committerdlezcano <dlezcano>
Mon, 16 Feb 2009 10:14:34 +0000 (10:14 +0000)
From: Daniel Lezcano <daniel.lezcano@free.fr>

The realpath function is more convenient to build the absolute path of
the rootfs.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/lxc_conf.c

index f19f69585107fd97ba112f434d78ac2be1b7a599..872d05f14adabe2b4921f98b9b1d0f57e806ef04 100644 (file)
@@ -455,17 +455,15 @@ static int configure_rootfs(const char *name, const char *rootfs)
        char path[MAXPATHLEN];
        char absrootfs[MAXPATHLEN];
        char fstab[MAXPATHLEN];
        char path[MAXPATHLEN];
        char absrootfs[MAXPATHLEN];
        char fstab[MAXPATHLEN];
-       char *pwd;
-       int ret;
        FILE *f;
        FILE *f;
+       int ret;
 
 
-       snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name);
-
-       pwd = get_current_dir_name();
-
-       snprintf(absrootfs, MAXPATHLEN, "%s/%s", pwd, rootfs);
+       if (!realpath(rootfs, absrootfs)) {
+               lxc_log_syserror("failed to get real path for '%s'", rootfs);
+               return -1;
+       }
 
 
-       free(pwd);
+       snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name);
 
        if (access(absrootfs, F_OK)) {
                lxc_log_syserror("'%s' is not accessible", absrootfs);
 
        if (access(absrootfs, F_OK)) {
                lxc_log_syserror("'%s' is not accessible", absrootfs);
@@ -486,6 +484,7 @@ static int configure_rootfs(const char *name, const char *rootfs)
        }
 
        ret = fprintf(f, "%s %s none bind 0 0\n", absrootfs, path);
        }
 
        ret = fprintf(f, "%s %s none bind 0 0\n", absrootfs, path);
+
        fclose(f);
 
        if (ret < 0) {
        fclose(f);
 
        if (ret < 0) {