From d67dd341deb61e34ec5e7a133efc2db27b2fab2a Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Wed, 10 Mar 2004 02:49:08 +0000 Subject: [PATCH] added an option the 'CONTEXT' query so that it can be choosen between running/non running git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1200 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/src/vserver-info.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/util-vserver/src/vserver-info.c b/util-vserver/src/vserver-info.c index eb63df4..b7ccbdb 100644 --- a/util-vserver/src/vserver-info.c +++ b/util-vserver/src/vserver-info.c @@ -52,7 +52,8 @@ static struct { VserverTag const val; char const * const descr; } const TAGS[] = { - { "CONTEXT", tgCONTEXT, "the current and/or assigned context" }, + { "CONTEXT", tgCONTEXT, ("the current and/or assigned context; when an optinal argument " + "evaluates to false,only the current context will be printed") }, { "RUNNING", tgRUNNING, "gives out '1' when vserver is running; else, it fails without output" }, { "VDIR", tgVDIR, "gives out the root-directory of the vserver" }, { "NAME", tgNAME, "gives out the name of the vserver" }, @@ -282,9 +283,10 @@ printSysInfo(char *buf) } static char * -getContext(char *buf, char const *vserver) +getContext(char *buf, char const *vserver, bool allow_only_static) { - xid_t xid = vc_getVserverCtx(vserver, vcCFG_AUTO, true, 0); + xid_t xid = vc_getVserverCtx(vserver, vcCFG_AUTO, + allow_only_static, 0); if (xid==VC_NOCTX) return 0; utilvserver_fmt_long(buf, xid); @@ -297,6 +299,12 @@ testFeature(int argc, char *argv[]) return (argc>0 && vc_isSupportedString(argv[0])) ? EXIT_SUCCESS : EXIT_FAILURE; } +static bool +str2bool(char const *str) +{ + return atoi(str)!=0 || strchr("yYtY", str[0])!=0; +} + static int execQuery(char const *vserver, VserverTag tag, int argc, char *argv[]) { @@ -319,7 +327,8 @@ execQuery(char const *vserver, VserverTag tag, int argc, char *argv[]) res = (vc_getVserverCtx(vserver, vcCFG_AUTO, false, 0)==VC_NOCTX) ? 0 : "1"; break; - case tgCONTEXT : res = getContext(buf, vserver); break; + case tgCONTEXT : res = getContext(buf, vserver, + argc==0 || str2bool(argv[0])); break; case tgXID : res = getXid(buf, vserver); break; case tgINITPID : res = getInitPid(buf, xid); break; case tgINITPID_PID : res = getInitPidPid(buf, vserver); break; -- 1.8.1.5