X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Flib%2Fgetvserverctx.c;h=b565e4e78dc7b58748e6a8149b76d5338b4e8dde;hb=0c1e4aa88cd3f5b075014eac88241fe3a7459029;hp=3052c7a1e71e6052d2915f0583b863d1537a6ed3;hpb=d0ae91f088249a5c126ad170b82a8fc6e669b95f;p=util-vserver.git diff --git a/util-vserver/lib/getvserverctx.c b/util-vserver/lib/getvserverctx.c index 3052c7a..b565e4e 100644 --- a/util-vserver/lib/getvserverctx.c +++ b/util-vserver/lib/getvserverctx.c @@ -31,7 +31,7 @@ #include #include -static ctx_t +static xid_t getCtxFromFile(char const *pathname) { int fd; @@ -45,10 +45,10 @@ getCtxFromFile(char const *pathname) (lseek(fd, 0, SEEK_SET)==-1)) return VC_NOCTX; - BS; + { char buf[len+1]; char *errptr; - ctx_t res; + xid_t res; if (TEMP_FAILURE_RETRY(read(fd, buf, len+1))!=len) return VC_NOCTX; @@ -57,34 +57,45 @@ getCtxFromFile(char const *pathname) if (*errptr!='\0' && *errptr!='\n') return VC_NOCTX; return res; - BE; + } } -ctx_t -vc_getVserverCtx(char const *id, vcCfgStyle style) +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")]; if (style==vcCFG_NONE || style==vcCFG_AUTO) style = vc_getVserverCfgStyle(id); - + + if (is_running) *is_running = false; + switch (style) { case vcCFG_NONE : return VC_NOCTX; case vcCFG_LEGACY : return VC_NOCTX; // todo case vcCFG_RECENT_SHORT : case vcCFG_RECENT_FULL : { size_t idx = 0; + xid_t res = 0; + if (style==vcCFG_RECENT_SHORT) { memcpy(buf, CONFDIR "/", sizeof(CONFDIR "/")-1); idx = sizeof(CONFDIR "/") - 1; } memcpy(buf+idx, id, l1); idx += l1; - memcpy(buf+idx, "/run", 4); idx += 4; - buf[idx] = '\0'; + memcpy(buf+idx, "/run", 5); // appends '\0' too + + res = getCtxFromFile(buf); + if (is_running) *is_running = res!=VC_NOCTX; + if (res==VC_NOCTX && honor_static) { + memcpy(buf+idx, "/context", 9); // appends '\0' too - return getCtxFromFile(buf); + res = getCtxFromFile(buf); + } + + return res; } default : return VC_NOCTX; }