3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 typedef enum { tgNONE,tgCONTEXT, tgRUNNING,
35 tgVDIR, tgNAME, tgCFGDIR, tgAPPDIR } VserverTag;
38 char const * const tag;
40 char const * const descr;
42 { "CONTEXT", tgCONTEXT, "the current and/or assigned context" },
43 { "RUNNING", tgRUNNING, "gives out '1' when vserver is running; else, it fails without output" },
44 { "VDIR", tgVDIR, "gives out the root-directory of the vserver" },
45 { "NAME", tgNAME, "gives out the name of the vserver" },
46 { "CFGDIR", tgCFGDIR, "gives out the configuration directory of the vserver" },
47 { "APPDIR", tgAPPDIR, "gives out the name of the toplevel application cfgdir" },
50 #define TAGS_COUNT (sizeof(TAGS)/sizeof(TAGS[0]))
52 int wrapper_exit_code = 1;
54 static struct option const
56 { "help", no_argument, 0, 'h' },
57 { "version", no_argument, 0, 'v' },
63 showHelp(int fd, char const *cmd, int res)
65 WRITE_MSG(fd, "Usage: ");
68 " [-q] <vserver> <tag>\n"
69 "Please report bugs to " PACKAGE_BUGREPORT "\n");
77 "vserver-info " VERSION " -- returns information about vservers\n"
78 "This program is part of " PACKAGE_STRING "\n\n"
79 "Copyright (C) 2003 Enrico Scholz\n"
80 VERSION_COPYRIGHT_DISCLAIMER);
87 char const * delim = "";
90 WRITE_MSG(1, "Valid tags are: ");
91 for (i=0; i<TAGS_COUNT; ++i) {
93 WRITE_STR(1, TAGS[i].tag);
102 stringToTag(char const *str)
105 for (i=0; i<TAGS_COUNT; ++i)
106 if (strcmp(TAGS[i].tag, str)==0) return TAGS[i].val;
112 execQuery(char const *vserver, VserverTag tag, int argc, char *argv[])
114 char const * res = 0;
115 char buf[sizeof(xid_t)*4 + 16];
119 case tgNAME : res = vc_getVserverName(vserver, vcCFG_AUTO); break;
121 res = vc_getVserverVdir(vserver, vcCFG_AUTO, argc>0 && atoi(argv[0]));
123 case tgCFGDIR : res = vc_getVserverCfgDir(vserver, vcCFG_AUTO); break;
125 res = vc_getVserverAppDir(vserver, vcCFG_AUTO, argc==0 ? "" : argv[0]);
128 ctx = vc_getVserverCtx(vserver, vcCFG_AUTO, true, 0);
130 utilvserver_fmt_long(buf, ctx);
136 res = (vc_getVserverCtx(vserver, vcCFG_AUTO, false, 0)==VC_NOCTX) ? 0 : "1";
139 default : assert(false); abort(); // TODO
142 if (res==0) return EXIT_FAILURE;
148 int main(int argc, char *argv[])
151 char const * vserver;
155 int c = getopt_long(argc, argv, "ql", CMDLINE_OPTIONS, 0);
159 case 'h' : showHelp(1, argv[0], 0);
160 case 'v' : showVersion();
161 case 'l' : showTags();
162 case 'q' : quiet = true; break;
164 WRITE_MSG(2, "Try '");
165 WRITE_STR(2, argv[0]);
166 WRITE_MSG(2, " --help\" for more information.\n");
173 WRITE_MSG(2, "No vserver or tag give; please try '--help' for more information.\n");
177 vserver = argv[optind];
178 tag = stringToTag(argv[optind+1]);
181 WRITE_MSG(2, "Unknown tag; use '-l' to get list of valid tags\n");
186 int fd = Eopen("/dev/null", O_WRONLY, 0644);
191 return execQuery(vserver, tag, argc-(optind+2), argv+optind+2);