X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Fgetvserverctx.c;h=cf7a4f9bc3b3ee1b820486749984707be0237e4a;hb=3eb1b2279739d0f16391a3724a9897c686f030d3;hp=b565e4e78dc7b58748e6a8149b76d5338b4e8dde;hpb=90ea9558c3d51f65b96228653fd54b8ba8604e48;p=util-vserver.git diff --git a/util-vserver/lib/getvserverctx.c b/util-vserver/lib/getvserverctx.c index b565e4e..cf7a4f9 100644 --- a/util-vserver/lib/getvserverctx.c +++ b/util-vserver/lib/getvserverctx.c @@ -23,6 +23,7 @@ #include "vserver.h" #include "pathconfig.h" #include "compat-c99.h" +#include "lib_internal/util.h" #include #include @@ -31,6 +32,58 @@ #include #include +#ifdef VC_ENABLE_API_COMPAT +#include + +static xid_t +extractLegacyXID(char const *dir, char const *basename) +{ + size_t l1 = strlen(dir); + size_t l2 = strlen(basename); + char path[l1 + l2 + sizeof("/.ctx")]; + char * ptr = path; + int fd; + ssize_t len; + xid_t result = VC_NOXID; + + ptr = Xmemcpy(ptr, dir, l1); + *ptr++ = '/'; + ptr = Xmemcpy(ptr, basename, l2); + ptr = Xmemcpy(ptr, ".ctx", 5); + + fd = open(path, O_RDONLY); + if (fd==-1) return VC_NOXID; + + len = lseek(fd, 0, SEEK_END); + + if (len!=-1 && lseek(fd, 0, SEEK_SET)!=-1) { + char buf[len+2]; + char const *pos = 0; + + buf[0] = '\n'; + + if (read(fd, buf+1, len+1)==len) { + buf[len+1] = '\0'; + pos = strstr(buf, "\nS_CONTEXT="); + } + + if (pos) pos += 11; + if (*pos>='1' && *pos<='9') + result = atoi(pos); + } + + close(fd); + return result; +} +#else +static xid_t +extractLegacyXID(char const UNUSED *dir, char const UNUSED *basename) +{ + return VC_NOXID; +} +#endif + + static xid_t getCtxFromFile(char const *pathname) { @@ -64,7 +117,7 @@ xid_t vc_getVserverCtx(char const *id, vcCfgStyle style, bool honor_static, bool *is_running) { size_t l1 = strlen(id); - char buf[sizeof(CONFDIR "//") + l1 + sizeof("/run")]; + char buf[sizeof(CONFDIR "//") + l1 + sizeof("/context")]; if (style==vcCFG_NONE || style==vcCFG_AUTO) style = vc_getVserverCfgStyle(id); @@ -73,7 +126,8 @@ vc_getVserverCtx(char const *id, vcCfgStyle style, bool honor_static, bool *is_r switch (style) { case vcCFG_NONE : return VC_NOCTX; - case vcCFG_LEGACY : return VC_NOCTX; // todo + case vcCFG_LEGACY : + return extractLegacyXID(DEFAULT_PKGSTATEDIR, id); case vcCFG_RECENT_SHORT : case vcCFG_RECENT_FULL : { size_t idx = 0;