xen-vtx-unstable

view tools/console/daemon/main.c @ 6774:4d899a738d59

merge?
author cl349@firebug.cl.cam.ac.uk
date Tue Sep 13 15:05:49 2005 +0000 (2005-09-13)
parents 3f2751c6e721 8db9c5873b9b
children e7c7196fa329 8ca0f98ba8e2
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 void usage(char *prg)
34 {
35 fprintf(stderr,
36 "usage: %s [-h] [-V] [-v] [-i]\n", prg);
37 }
39 int main(int argc, char **argv)
40 {
41 const char *sopts = "hVvi";
42 struct option lopts[] = {
43 { "help", 0, 0, 'h' },
44 { "version", 0, 0, 'V' },
45 { "verbose", 0, 0, 'v' },
46 { "interactive", 0, 0, 'i' },
47 { 0 },
48 };
49 bool is_interactive = false;
50 int ch;
51 int syslog_option = LOG_CONS;
52 int syslog_mask = LOG_WARNING;
53 int opt_ind = 0;
55 while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
56 switch (ch) {
57 case 'h':
58 usage(argv[0]);
59 exit(0);
60 case 'V':
61 //version(argv[0]);
62 exit(0);
63 case 'v':
64 syslog_option |= LOG_PERROR;
65 syslog_mask = LOG_DEBUG;
66 break;
67 case 'i':
68 is_interactive = true;
69 break;
70 case '?':
71 fprintf(stderr,
72 "Try `%s --help' for more information\n",
73 argv[0]);
74 exit(EINVAL);
75 }
76 }
78 if (geteuid() != 0) {
79 fprintf(stderr, "%s requires root to run.\n", argv[0]);
80 exit(EPERM);
81 }
83 openlog("xenconsoled", syslog_option, LOG_DAEMON);
84 setlogmask(syslog_mask);
86 if (!is_interactive) {
87 daemonize("/var/run/xenconsoled.pid");
88 }
90 if (!xen_setup())
91 exit(1);
93 enum_domains();
95 handle_io();
97 closelog();
99 return 0;
100 }