X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Fgetvserverbyctx-compat.hc;h=9418e2f9453ff33e3985e9dc9873484d7e7bb2a1;hb=319929791248f823537ac5fb2fe10a01b5b820b9;hp=c1e7198cec816a7e6a829e8768b3ca6238d7f9a0;hpb=d753067d6122070c0ce165e81578966f11e67f74;p=util-vserver.git diff --git a/util-vserver/lib/getvserverbyctx-compat.hc b/util-vserver/lib/getvserverbyctx-compat.hc index c1e7198..9418e2f 100644 --- a/util-vserver/lib/getvserverbyctx-compat.hc +++ b/util-vserver/lib/getvserverbyctx-compat.hc @@ -28,6 +28,44 @@ #include #include +#ifdef VC_ENABLE_API_COMPAT +#include +#include + + +static char * +handleLegacy(xid_t xid) +{ + DIR *dir = opendir(DEFAULT_PKGSTATEDIR); + struct dirent *ep; + char * result = 0; + + if (dir==0) return 0; + while ((ep=readdir(dir))!=0) { + char * const name = ep->d_name; + size_t l = name ? strlen(name) : 0; + xid_t cur_xid; + + if (l<=4 || strcmp(name+l-4, ".ctx")!=0) continue; + name[l-4] = '\0'; + cur_xid = vc_getVserverCtx(name, vcCFG_LEGACY, false, 0); + if (cur_xid!=xid) continue; + + result = strdup(name); + break; + } + + closedir(dir); + return result; +} +#else +static inline char * +handleLegacy(xid_t UNUSED xid) +{ + return 0; +} +#endif + static char * vc_getVserverByCtx_compat(xid_t ctx, vcCfgStyle *style, char const *revdir) { @@ -46,7 +84,7 @@ vc_getVserverByCtx_compat(xid_t ctx, vcCfgStyle *style, char const *revdir) if (style==0 || *style==vcCFG_AUTO) { if (access(path, F_OK)==0) cur_style = vcCFG_RECENT_FULL; - // TODO: handle legacy + else cur_style = vcCFG_LEGACY; } else cur_style = *style; @@ -60,6 +98,15 @@ vc_getVserverByCtx_compat(xid_t ctx, vcCfgStyle *style, char const *revdir) if (style) *style = vcCFG_RECENT_FULL; return strdup(path); // TODO: handle legacy + case vcCFG_LEGACY : + { + char * tmp = handleLegacy(ctx); + if (tmp && style) + *style = vcCFG_LEGACY; + + return tmp; + } + default : return 0; }