xen-vtx-unstable

annotate tools/console/daemon/main.c @ 6647:0922c82a4bf3

Exit if xen_setup fails.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Sep 06 18:18:56 2005 +0000 (2005-09-06)
parents dd668f7527cb
children 8db9c5873b9b
rev   line source
kaf24@6038 1 /*\
kaf24@6038 2 * Copyright (C) International Business Machines Corp., 2005
kaf24@6038 3 * Author(s): Anthony Liguori <aliguori@us.ibm.com>
kaf24@6038 4 *
kaf24@6038 5 * Xen Console Daemon
kaf24@6038 6 *
kaf24@6038 7 * This program is free software; you can redistribute it and/or modify
kaf24@6038 8 * it under the terms of the GNU General Public License as published by
kaf24@6038 9 * the Free Software Foundation; under version 2 of the License.
kaf24@6038 10 *
kaf24@6038 11 * This program is distributed in the hope that it will be useful,
kaf24@6038 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
kaf24@6038 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kaf24@6038 14 * GNU General Public License for more details.
kaf24@6038 15 *
kaf24@6038 16 * You should have received a copy of the GNU General Public License
kaf24@6038 17 * along with this program; if not, write to the Free Software
kaf24@6038 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
kaf24@6038 19 \*/
kaf24@6038 20
kaf24@6038 21 #include <getopt.h>
kaf24@6038 22 #include <stdlib.h>
kaf24@6038 23 #include <stdio.h>
kaf24@6038 24 #include <errno.h>
kaf24@6038 25 #include <unistd.h>
kaf24@6038 26 #include <sys/types.h>
kaf24@6038 27
cl349@6388 28 #include "xenctrl.h"
kaf24@6038 29
kaf24@6038 30 #include "utils.h"
kaf24@6038 31 #include "io.h"
kaf24@6038 32
kaf24@6038 33 int main(int argc, char **argv)
kaf24@6038 34 {
kaf24@6038 35 const char *sopts = "hVvi";
kaf24@6038 36 struct option lopts[] = {
kaf24@6038 37 { "help", 0, 0, 'h' },
kaf24@6038 38 { "version", 0, 0, 'V' },
kaf24@6038 39 { "verbose", 0, 0, 'v' },
kaf24@6038 40 { "interactive", 0, 0, 'i' },
kaf24@6038 41 { 0 },
kaf24@6038 42 };
kaf24@6038 43 bool is_interactive = false;
kaf24@6038 44 int ch;
kaf24@6038 45 int syslog_option = LOG_CONS;
kaf24@6038 46 int syslog_mask = LOG_WARNING;
kaf24@6038 47 int opt_ind = 0;
kaf24@6038 48
kaf24@6038 49 while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
kaf24@6038 50 switch (ch) {
kaf24@6038 51 case 'h':
kaf24@6038 52 //usage(argv[0]);
kaf24@6038 53 exit(0);
kaf24@6038 54 case 'V':
kaf24@6038 55 //version(argv[0]);
kaf24@6038 56 exit(0);
kaf24@6038 57 case 'v':
kaf24@6038 58 syslog_option |= LOG_PERROR;
kaf24@6038 59 syslog_mask = LOG_DEBUG;
kaf24@6038 60 break;
kaf24@6038 61 case 'i':
kaf24@6038 62 is_interactive = true;
kaf24@6038 63 break;
kaf24@6038 64 case '?':
kaf24@6038 65 fprintf(stderr,
kaf24@6038 66 "Try `%s --help' for more information\n",
kaf24@6038 67 argv[0]);
kaf24@6038 68 exit(EINVAL);
kaf24@6038 69 }
kaf24@6038 70 }
kaf24@6038 71
kaf24@6038 72 if (geteuid() != 0) {
kaf24@6038 73 fprintf(stderr, "%s requires root to run.\n", argv[0]);
kaf24@6038 74 exit(EPERM);
kaf24@6038 75 }
kaf24@6038 76
kaf24@6038 77 openlog("xenconsoled", syslog_option, LOG_DAEMON);
kaf24@6038 78 setlogmask(syslog_mask);
kaf24@6038 79
kaf24@6038 80 if (!is_interactive) {
kaf24@6038 81 daemonize("/var/run/xenconsoled.pid");
kaf24@6038 82 }
kaf24@6038 83
cl349@6647 84 if (!xen_setup())
cl349@6647 85 exit(1);
kaf24@6038 86
cl349@6484 87 enum_domains();
cl349@6484 88
kaf24@6038 89 handle_io();
kaf24@6038 90
kaf24@6038 91 closelog();
kaf24@6038 92
kaf24@6038 93 return 0;
kaf24@6038 94 }