xen-vtx-unstable

annotate tools/console/daemon/main.c @ 6725:3f2751c6e721

add a simple usage string to xenconsoled

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