/* * Copyright (C) 2009 Citrix Ltd. * Author Stefano Stabellini * Author Vincent Hanquez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; version 2.1 only. with the special * exception on linking described in file LICENSE. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ #include "libxl_osdeps.h" #include #include #include #include #include #include #include #include #include #include #include "libxl.h" #include "libxl_utils.h" #include "xl.h" xentoollog_logger_stdiostream *logger; static xentoollog_level minmsglevel = XTL_PROGRESS; int main(int argc, char **argv) { int opt = 0; char *cmd = 0; struct cmd_spec *cspec; int ret; while ((opt = getopt(argc, argv, "+v")) >= 0) { switch (opt) { case 'v': if (minmsglevel > 0) minmsglevel--; break; default: fprintf(stderr, "unknown global option\n"); exit(2); } } cmd = argv[optind++]; if (!cmd) { help(NULL); exit(1); } opterr = 0; logger = xtl_createlogger_stdiostream(stderr, minmsglevel, 0); if (!logger) exit(1); if (libxl_ctx_init(&ctx, LIBXL_VERSION, (xentoollog_logger*)logger)) { fprintf(stderr, "cannot init xl context\n"); exit(1); } srand(time(0)); cspec = cmdtable_lookup(cmd); if (cspec) ret = cspec->cmd_impl(argc, argv); else if (!strcmp(cmd, "help")) { help(argv[optind]); ret = 0; } else { fprintf(stderr, "command not implemented\n"); ret = 1; } libxl_ctx_free(&ctx); xtl_logger_destroy((xentoollog_logger*)logger); return ret; }