From b9ab1c6460688f5a828bff0bc7cb76fe1fe2219c Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Mon, 5 Jan 2004 21:53:33 +0000 Subject: [PATCH] small cosmetical fix git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@537 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/fmtx.hc | 2 +- util-vserver/lib/getvserverbyctx.c | 2 +- util-vserver/lib/getvserverctx.c | 21 ++++++++++++++++----- util-vserver/lib/vserver-internal.h | 2 +- util-vserver/lib/vserver.h | 13 ++++++++++--- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/util-vserver/lib/fmtx.hc b/util-vserver/lib/fmtx.hc index df29616..4f25ae6 100644 --- a/util-vserver/lib/fmtx.hc +++ b/util-vserver/lib/fmtx.hc @@ -32,7 +32,7 @@ CONCAT(FMT_P(xuint),)(char *ptr, CONCAT(uint_least,_t) val) size_t CONCAT(FMT_P(xint),)(char *ptr, - CONCAT(int_least,_t) val) + CONCAT(int_least,_t) val) { size_t offset=0; if (val<0) { diff --git a/util-vserver/lib/getvserverbyctx.c b/util-vserver/lib/getvserverbyctx.c index 5759f1c..ce45d43 100644 --- a/util-vserver/lib/getvserverbyctx.c +++ b/util-vserver/lib/getvserverbyctx.c @@ -55,7 +55,7 @@ vc_getVserverByCtx(xid_t ctx, vcCfgStyle *style, char const *revdir) case vcCFG_RECENT_SHORT : case vcCFG_RECENT_FULL : // check if expected ctx == actual ctx - if (vc_getVserverCtx(path, vcCFG_RECENT_FULL)!=ctx) return 0; + if (vc_getVserverCtx(path, vcCFG_RECENT_FULL, false, 0)!=ctx) return 0; if (style) *style = vcCFG_RECENT_FULL; return strdup(path); diff --git a/util-vserver/lib/getvserverctx.c b/util-vserver/lib/getvserverctx.c index 774c80f..71de198 100644 --- a/util-vserver/lib/getvserverctx.c +++ b/util-vserver/lib/getvserverctx.c @@ -61,30 +61,41 @@ getCtxFromFile(char const *pathname) } xid_t -vc_getVserverCtx(char const *id, vcCfgStyle style) +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; } diff --git a/util-vserver/lib/vserver-internal.h b/util-vserver/lib/vserver-internal.h index 601f687..9c051b2 100644 --- a/util-vserver/lib/vserver-internal.h +++ b/util-vserver/lib/vserver-internal.h @@ -42,7 +42,7 @@ # define VC_SELECT(ID) case ID: if(1) # define CALL_VC(...) \ switch (utilvserver_checkCompatVersion()&~0xff) { \ - case -1 : if (1) break; \ + case -1 & ~0xff : if (1) break; \ VC_SUFFIX, __VA_ARGS__ , VC_PREFIX; \ default : errno = EINVAL; \ } \ diff --git a/util-vserver/lib/vserver.h b/util-vserver/lib/vserver.h index d45dc9d..f0439b0 100644 --- a/util-vserver/lib/vserver.h +++ b/util-vserver/lib/vserver.h @@ -22,6 +22,7 @@ #include #include +#include #include /** the value which is returned in error-case (no ctx found) */ @@ -175,9 +176,15 @@ extern "C" { char * vc_getVserverVdir(char const *id, vcCfgStyle style); - /** Returns the ctx of the given vserver, or VC_NOCTX if vserver is not - * running */ - xid_t vc_getVserverCtx(char const *id, vcCfgStyle style); + /** Returns the ctx of the given vserver. When vserver is not running and + * 'honor_static' is false, VC_NOCTX will be returned. Else, when + * 'honor_static' is true and a static assignment exists, those value will + * be returned. Else, the result will be VC_NOCTX. + * + * When 'is_running' is not null, the status of the vserver will be + * assigned to this variable. */ + xid_t vc_getVserverCtx(char const *id, vcCfgStyle style, + bool honor_static, bool /*@null@*/ *is_running); /** Resolves the cfg-path of the vserver owning the given ctx. 'revdir' will be used as the directory holding the mapping-links; when NULL, the -- 1.8.1.5