added kernel headers
[util-vserver.git] / util-vserver / src / vserver-info.c
index 625e656..b7ccbdb 100644 (file)
@@ -44,6 +44,7 @@ typedef enum { tgNONE,tgCONTEXT, tgRUNNING,
               tgAPIVER,
               tgINITPID, tgINITPID_PID,
               tgXID, tgUTS, tgSYSINFO,
+              tgFEATURE,
 }      VserverTag;
 
 static struct {
@@ -51,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" },
@@ -65,6 +67,7 @@ static struct {
                                   "context, sysname, nodename, release, version, "
                                   "machine and domainname") },
   { "SYSINFO",     tgSYSINFO,     "gives out information about the systen" },
+  { "FEATURE",     tgFEATURE,     "returns 0 iff the queried feature is supported" },
 };
 
 int wrapper_exit_code = 1;
@@ -180,7 +183,7 @@ getInitPid(char *buf, xid_t xid)
   
   if (vc_get_vx_info(xid, &info)==-1) perror("vc_get_vx_info()");
   else {
-    utilvserver_fmt_long(buf, info.xid);
+    utilvserver_fmt_long(buf, info.initpid);
     return buf;
   }
 
@@ -197,7 +200,7 @@ getInitPidPid(char *buf, char const *vserver)
   if (xid==VC_NOCTX) perror("vc_get_task_xid()");
   else if (vc_get_vx_info(xid, &info)==-1) perror("vc_get_vx_info()");
   else {
-    utilvserver_fmt_long(buf, info.xid);
+    utilvserver_fmt_long(buf, info.initpid);
     return buf;
   }
 
@@ -280,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);
@@ -290,6 +294,18 @@ getContext(char *buf, char const *vserver)
 }
 
 static int
+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[])
 {
   char const *         res = 0;
@@ -311,13 +327,15 @@ 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;
     case tgAPIVER      :  res = getAPIVer(buf);               break;
     case tgUTS         :  res = getUTS(buf, xid, argc, argv); break;
     case tgSYSINFO     :  return printSysInfo(buf);           break;
+    case tgFEATURE     :  return testFeature(argc,argv);      break;
     
     default            :  assert(false); abort();  // TODO
   }