X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Fgetvservercfgstyle.c;h=28550e6bc232d8c31b2621fd06a029a5ab4fb670;hb=34708129e616039d99cee99a9bae3fb1e200ddb2;hp=cc5643333f7bdd3d66f89cf13e08ac1e5a93da23;hpb=0fbb86cbb2d2991b2497e94b434478c6bb3a3af6;p=util-vserver.git diff --git a/util-vserver/lib/getvservercfgstyle.c b/util-vserver/lib/getvservercfgstyle.c index cc56433..28550e6 100644 --- a/util-vserver/lib/getvservercfgstyle.c +++ b/util-vserver/lib/getvservercfgstyle.c @@ -22,12 +22,27 @@ #include "vserver.h" #include "pathconfig.h" +#include "internal.h" #include #include #include #include +static inline bool +isRelPath(char const *p) +{ + return p[0]=='.' && (p[1]=='/' || (p[1]=='.' && p[2]=='/')); +} + +static inline bool +isAbsPath(char const *p) +{ + return p[0]=='/'; +} + +#define ISDIR utilvserver_isDirectory(buf, true) + vcCfgStyle vc_getVserverCfgStyle(char const *id) { @@ -37,24 +52,27 @@ vc_getVserverCfgStyle(char const *id) MAX(sizeof(CONFDIR "/"),sizeof(DEFAULT_VSERVERDIR "/")) + MAX(sizeof("/legacy"), sizeof(".conf")) - 1]; char * marker = 0; + bool is_path; strcpy(buf, id); marker = buf+l1; strcpy(marker, "/vdir"); - - if (access(buf, X_OK)==0) res = vcCFG_RECENT_FULL; - else { + + is_path = isAbsPath(buf) || isRelPath(buf); + if (is_path && ISDIR) + res = vcCFG_RECENT_FULL; + else if (!is_path) { strcpy(buf, CONFDIR "/"); strcpy(buf+sizeof(CONFDIR "/") - 1, id); marker = buf+sizeof(CONFDIR "/")+l1 - 1; strcpy(marker, "/vdir"); - if (access(buf, X_OK)==0) res = vcCFG_RECENT_SHORT; + if (ISDIR) res = vcCFG_RECENT_SHORT; else { strcpy(buf, DEFAULT_VSERVERDIR "/"); strcpy(buf+sizeof(DEFAULT_VSERVERDIR)+1 - 1, id); - if (access(buf, X_OK)==0) res = vcCFG_LEGACY; + if (ISDIR) res = vcCFG_LEGACY; } if (res==vcCFG_LEGACY) { @@ -62,7 +80,7 @@ vc_getVserverCfgStyle(char const *id) strcpy(buf+sizeof(CONFDIR "/") - 1, id); strcpy(buf+sizeof(CONFDIR "/")+l1 - 1, ".conf"); - if (access(buf, R_OK)!=0) res = vcCFG_NONE; + if (!ISDIR) res = vcCFG_NONE; } }