direct-io.hg

view tools/console/daemon/main.c @ 7603:e519f3239a97

Make the -V option of xenconsoled actually do something.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Nov 02 11:25:21 2005 +0100 (2005-11-02)
parents 06d84bf87159
children edf407a3dd70
line source
1 /*\
2 * Copyright (C) International Business Machines Corp., 2005
3 * Author(s): Anthony Liguori <aliguori@us.ibm.com>
4 *
5 * Xen Console Daemon
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; under version 2 of the 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 \*/
21 #include <getopt.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include <sys/types.h>
28 #include "xenctrl.h"
30 #include "utils.h"
31 #include "io.h"
33 static void usage(char *name)
34 {
35 printf("Usage: %s [-h] [-V] [-v] [-i]\n", name);
36 }
38 static void version(char *name)
39 {
40 printf("Xen Console Daemon 3.0\n");
41 }
43 int main(int argc, char **argv)
44 {
45 const char *sopts = "hVvi";
46 struct option lopts[] = {
47 { "help", 0, 0, 'h' },
48 { "version", 0, 0, 'V' },
49 { "verbose", 0, 0, 'v' },
50 { "interactive", 0, 0, 'i' },
51 { 0 },
52 };
53 bool is_interactive = false;
54 int ch;
55 int syslog_option = LOG_CONS;
56 int syslog_mask = LOG_WARNING;
57 int opt_ind = 0;
59 while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
60 switch (ch) {
61 case 'h':
62 usage(argv[0]);
63 exit(0);
64 case 'V':
65 version(argv[0]);
66 exit(0);
67 case 'v':
68 syslog_option |= LOG_PERROR;
69 syslog_mask = LOG_DEBUG;
70 break;
71 case 'i':
72 is_interactive = true;
73 break;
74 case '?':
75 fprintf(stderr,
76 "Try `%s --help' for more information\n",
77 argv[0]);
78 exit(EINVAL);
79 }
80 }
82 if (geteuid() != 0) {
83 fprintf(stderr, "%s requires root to run.\n", argv[0]);
84 exit(EPERM);
85 }
87 openlog("xenconsoled", syslog_option, LOG_DAEMON);
88 setlogmask(syslog_mask);
90 if (!is_interactive) {
91 daemonize("/var/run/xenconsoled.pid");
92 }
94 if (!xen_setup())
95 exit(1);
97 enum_domains();
99 handle_io();
101 closelog();
103 return 0;
104 }