debuggers.hg

view tools/libxl/xl.c @ 21945:5b52397e10dc

xl: free the libxl context before exit

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Fri Jul 30 15:15:54 2010 +0100 (2010-07-30)
parents 96c2178bd448
children 7090637d61c5
line source
1 /*
2 * Copyright (C) 2009 Citrix Ltd.
3 * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
4 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; version 2.1 only. with the special
9 * exception on linking described in file LICENSE.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 */
17 #include "libxl_osdeps.h"
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <sys/time.h> /* for time */
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <ctype.h>
28 #include <inttypes.h>
30 #include "libxl.h"
31 #include "libxl_utils.h"
32 #include "xl.h"
34 xentoollog_logger_stdiostream *logger;
36 static xentoollog_level minmsglevel = XTL_PROGRESS;
38 int main(int argc, char **argv)
39 {
40 int opt = 0;
41 char *cmd = 0;
42 struct cmd_spec *cspec;
43 int ret;
45 while ((opt = getopt(argc, argv, "+v")) >= 0) {
46 switch (opt) {
47 case 'v':
48 if (minmsglevel > 0) minmsglevel--;
49 break;
50 default:
51 fprintf(stderr, "unknown global option\n");
52 exit(2);
53 }
54 }
56 cmd = argv[optind++];
58 if (!cmd) {
59 help(NULL);
60 exit(1);
61 }
62 opterr = 0;
64 logger = xtl_createlogger_stdiostream(stderr, minmsglevel, 0);
65 if (!logger) exit(1);
67 if (libxl_ctx_init(&ctx, LIBXL_VERSION, (xentoollog_logger*)logger)) {
68 fprintf(stderr, "cannot init xl context\n");
69 exit(1);
70 }
72 srand(time(0));
74 cspec = cmdtable_lookup(cmd);
75 if (cspec)
76 ret = cspec->cmd_impl(argc, argv);
77 else if (!strcmp(cmd, "help")) {
78 help(argv[optind]);
79 ret = 0;
80 } else {
81 fprintf(stderr, "command not implemented\n");
82 ret = 1;
83 }
85 libxl_ctx_free(&ctx);
87 return ret;
88 }