ia64/xen-unstable

view tools/console/daemon/main.c @ 6427:3428d58a85e1

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 25 14:41:52 2005 +0000 (2005-08-25)
parents 4abd299ef2f6 6e899a3840b2
children b54144915ae6
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"
29 #include "xen/io/domain_controller.h"
30 #include "xcs_proto.h"
32 #include "utils.h"
33 #include "io.h"
35 int main(int argc, char **argv)
36 {
37 const char *sopts = "hVvi";
38 struct option lopts[] = {
39 { "help", 0, 0, 'h' },
40 { "version", 0, 0, 'V' },
41 { "verbose", 0, 0, 'v' },
42 { "interactive", 0, 0, 'i' },
43 { 0 },
44 };
45 bool is_interactive = false;
46 int ch;
47 int syslog_option = LOG_CONS;
48 int syslog_mask = LOG_WARNING;
49 int opt_ind = 0;
51 while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
52 switch (ch) {
53 case 'h':
54 //usage(argv[0]);
55 exit(0);
56 case 'V':
57 //version(argv[0]);
58 exit(0);
59 case 'v':
60 syslog_option |= LOG_PERROR;
61 syslog_mask = LOG_DEBUG;
62 break;
63 case 'i':
64 is_interactive = true;
65 break;
66 case '?':
67 fprintf(stderr,
68 "Try `%s --help' for more information\n",
69 argv[0]);
70 exit(EINVAL);
71 }
72 }
74 if (geteuid() != 0) {
75 fprintf(stderr, "%s requires root to run.\n", argv[0]);
76 exit(EPERM);
77 }
79 openlog("xenconsoled", syslog_option, LOG_DAEMON);
80 setlogmask(syslog_mask);
82 if (!is_interactive) {
83 daemonize("/var/run/xenconsoled.pid");
84 }
86 xen_setup();
88 handle_io();
90 closelog();
92 return 0;
93 }