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 } 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" }
49 #define TAGS_COUNT (sizeof(TAGS)/sizeof(TAGS[0]))
51 int wrapper_exit_code = 1;
53 static struct option const
55 { "help", no_argument, 0, 'h' },
56 { "version", no_argument, 0, 'v' },
62 showHelp(int fd, char const *cmd, int res)
64 WRITE_MSG(fd, "Usage: ");
67 " [-q] <vserver> <tag>\n"
68 "Please report bugs to " PACKAGE_BUGREPORT "\n");
76 "vserver-info " VERSION " -- returns information about vservers\n"
77 "This program is part of " PACKAGE_STRING "\n\n"
78 "Copyright (C) 2003 Enrico Scholz\n"
79 VERSION_COPYRIGHT_DISCLAIMER);
86 char const * delim = "";
89 WRITE_MSG(1, "Valid tags are: ");
90 for (i=0; i<TAGS_COUNT; ++i) {
92 WRITE_STR(1, TAGS[i].tag);
101 stringToTag(char const *str)
104 for (i=0; i<TAGS_COUNT; ++i)
105 if (strcmp(TAGS[i].tag, str)==0) return TAGS[i].val;
111 execQuery(char const *vserver, VserverTag tag)
113 char const * res = 0;
114 char buf[sizeof(xid_t)*4 + 16];
118 case tgNAME : res = vc_getVserverName(vserver, vcCFG_AUTO); break;
119 case tgVDIR : res = vc_getVserverVdir(vserver, vcCFG_AUTO); break;
121 ctx = vc_getVserverCtx(vserver, vcCFG_AUTO, true, 0);
123 utilvserver_fmt_long(buf, ctx);
129 res = (vc_getVserverCtx(vserver, vcCFG_AUTO, false, 0)==VC_NOCTX) ? 0 : "1";
133 default : assert(false); abort(); // TODO
136 if (res==0) return EXIT_FAILURE;
142 int main(int argc, char *argv[])
145 char const * vserver;
149 int c = getopt_long(argc, argv, "ql", CMDLINE_OPTIONS, 0);
153 case 'h' : showHelp(1, argv[0], 0);
154 case 'v' : showVersion();
155 case 'l' : showTags();
156 case 'q' : quiet = true; break;
158 WRITE_MSG(2, "Try '");
159 WRITE_STR(2, argv[0]);
160 WRITE_MSG(2, " --help\" for more information.\n");
166 if (optind+2!=argc) {
167 WRITE_MSG(2, "No vserver or tag give; please try '--help' for more information.\n");
171 vserver = argv[optind];
172 tag = stringToTag(argv[optind+1]);
175 WRITE_MSG(2, "Unknown tag; use '-l' to get list of valid tags\n");
180 int fd = Eopen("/dev/null", O_WRONLY, 0644);
185 return execQuery(vserver, tag);