X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Fgetvservercfgstyle.c;h=7fca17a7b648c61a03a49d8c8a0ab8ca7dca1957;hb=e8d2f5c6dfacc5612f7a5ccfee517a47688bd6f8;hp=f56143b143e1c2ea783de36c75bc3492b23e258f;hpb=f30fdcfd6caa637eaaee58301d1f67cf9901eb29;p=util-vserver.git diff --git a/util-vserver/lib/getvservercfgstyle.c b/util-vserver/lib/getvservercfgstyle.c index f56143b..7fca17a 100644 --- a/util-vserver/lib/getvservercfgstyle.c +++ b/util-vserver/lib/getvservercfgstyle.c @@ -22,12 +22,29 @@ #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) +#define ISFILE utilvserver_isFile(buf, true) +#define ISLINK utilvserver_isLink(buf) + vcCfgStyle vc_getVserverCfgStyle(char const *id) { @@ -35,29 +52,41 @@ vc_getVserverCfgStyle(char const *id) size_t l1 = strlen(id); char buf[l1 + MAX(sizeof(CONFDIR "/"),sizeof(DEFAULT_VSERVERDIR "/")) + - sizeof("/legacy") - 1]; + 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 || ISLINK)) + 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)) res = vcCFG_LEGACY; + if (ISDIR) res = vcCFG_LEGACY; + } + + if (res==vcCFG_LEGACY) { + strcpy(buf, CONFDIR "/"); + strcpy(buf+sizeof(CONFDIR "/") - 1, id); + strcpy(buf+sizeof(CONFDIR "/")+l1 - 1, ".conf"); + + if (!ISFILE) res = vcCFG_NONE; } } + if (res==vcCFG_RECENT_FULL || res==vcCFG_RECENT_SHORT) { assert(marker!=0); strcpy(marker, "/legacy");