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) {
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);
}
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;
}
# 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; \
} \
#include <stdint.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <sys/types.h>
/** the value which is returned in error-case (no ctx found) */
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