X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Fgetvservervdir.c;h=754ae155a8e04f40130790c541288a4b25b67644;hb=faa778968d1a7dfeaebc9fe4b847e691dc62fd15;hp=f1b3b9224efad8a5e9040a666d1f84294231403d;hpb=f30fdcfd6caa637eaaee58301d1f67cf9901eb29;p=util-vserver.git diff --git a/util-vserver/lib/getvservervdir.c b/util-vserver/lib/getvservervdir.c index f1b3b92..754ae15 100644 --- a/util-vserver/lib/getvservervdir.c +++ b/util-vserver/lib/getvservervdir.c @@ -21,15 +21,41 @@ #endif #include "vserver.h" +#include "internal.h" #include "pathconfig.h" #include +#include +#include #include -#include -#include +static char * +getDir(char *dir, bool physical) +{ + int fd; + char tmp[PATH_MAX]; + + if (!physical) return strdup(dir); + + fd = open(".", O_RDONLY); + if (fd==-1) return 0; + + if (chdir(dir)!=-1 && + getcwd(tmp, sizeof tmp)!=0) + dir = strdup(tmp); + else + dir = 0; + + if (fchdir(fd)==-1) { + if (write(2, "FATAL error: failed to restore directory\n", 41)!=41) { /*...*/ } + abort(); + } + close(fd); + return dir; +} + char * -vc_getVserverVdir(char const *id, vcCfgStyle style) +vc_getVserverVdir(char const *id, vcCfgStyle style, bool physical) { size_t l1 = strlen(id); char *res = 0; @@ -46,7 +72,7 @@ vc_getVserverVdir(char const *id, vcCfgStyle style) strcpy(buf, DEFAULT_VSERVERDIR "/"); strcpy(buf+sizeof(DEFAULT_VSERVERDIR "/") - 1, id); - res = strdup(buf); + res = getDir(buf, physical); break; } @@ -58,7 +84,7 @@ vc_getVserverVdir(char const *id, vcCfgStyle style) strcpy(buf+sizeof(CONFDIR "/") - 1, id); strcpy(buf+sizeof(CONFDIR "/")+l1 - 1, "/vdir"); - res = strdup(buf); + res = getDir(buf, physical); break; } @@ -69,14 +95,16 @@ vc_getVserverVdir(char const *id, vcCfgStyle style) strcpy(buf, id); strcpy(buf+l1, "/vdir"); - res = strdup(buf); + res = getDir(buf, physical); break; } default : return 0; } - if (access(res, X_OK)==-1) { + // ignore physical-case; we went into the directory while determining + // the physical path so the directory exists + if (!physical && !utilvserver_isDirectory(res, true)) { free(res); res = 0; }