debuggers.hg

view tools/console/daemon/main.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children dec845b4d9c3
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 <string.h>
27 #include <signal.h>
28 #include <sys/types.h>
30 #include "xenctrl.h"
32 #include "utils.h"
33 #include "io.h"
35 int log_reload = 0;
36 int log_guest = 0;
37 int log_hv = 0;
38 int log_time_hv = 0;
39 int log_time_guest = 0;
40 char *log_dir = NULL;
41 int discard_overflowed_data = 1;
43 static void handle_hup(int sig)
44 {
45 log_reload = 1;
46 }
48 static void usage(char *name)
49 {
50 printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all] [-o, --overflow-data=discard|keep]\n", name);
51 }
53 static void version(char *name)
54 {
55 printf("Xen Console Daemon 3.0\n");
56 }
58 int main(int argc, char **argv)
59 {
60 const char *sopts = "hVvit:o:";
61 struct option lopts[] = {
62 { "help", 0, 0, 'h' },
63 { "version", 0, 0, 'V' },
64 { "verbose", 0, 0, 'v' },
65 { "interactive", 0, 0, 'i' },
66 { "log", 1, 0, 'l' },
67 { "log-dir", 1, 0, 'r' },
68 { "pid-file", 1, 0, 'p' },
69 { "timestamp", 1, 0, 't' },
70 { "overflow-data", 1, 0, 'o'},
71 { 0 },
72 };
73 bool is_interactive = false;
74 int ch;
75 int syslog_option = LOG_CONS;
76 int syslog_mask = LOG_WARNING;
77 int opt_ind = 0;
78 char *pidfile = NULL;
80 while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
81 switch (ch) {
82 case 'h':
83 usage(argv[0]);
84 exit(0);
85 case 'V':
86 version(argv[0]);
87 exit(0);
88 case 'v':
89 syslog_option |= LOG_PERROR;
90 syslog_mask = LOG_DEBUG;
91 break;
92 case 'i':
93 is_interactive = true;
94 break;
95 case 'l':
96 if (!strcmp(optarg, "all")) {
97 log_hv = 1;
98 log_guest = 1;
99 } else if (!strcmp(optarg, "hv")) {
100 log_hv = 1;
101 } else if (!strcmp(optarg, "guest")) {
102 log_guest = 1;
103 }
104 break;
105 case 'r':
106 log_dir = strdup(optarg);
107 break;
108 case 'p':
109 pidfile = strdup(optarg);
110 break;
111 case 't':
112 if (!strcmp(optarg, "all")) {
113 log_time_hv = 1;
114 log_time_guest = 1;
115 } else if (!strcmp(optarg, "hv")) {
116 log_time_hv = 1;
117 } else if (!strcmp(optarg, "guest")) {
118 log_time_guest = 1;
119 } else if (!strcmp(optarg, "none")) {
120 log_time_guest = 0;
121 log_time_hv = 0;
122 }
123 break;
124 case 'o':
125 if (!strcmp(optarg, "keep")) {
126 discard_overflowed_data = 0;
127 } else if (!strcmp(optarg, "discard")) {
128 discard_overflowed_data = 1;
129 }
130 break;
131 case '?':
132 fprintf(stderr,
133 "Try `%s --help' for more information\n",
134 argv[0]);
135 exit(EINVAL);
136 }
137 }
139 if (!log_dir) {
140 log_dir = strdup("/var/log/xen/console");
141 }
143 if (geteuid() != 0) {
144 fprintf(stderr, "%s requires root to run.\n", argv[0]);
145 exit(EPERM);
146 }
148 signal(SIGHUP, handle_hup);
150 openlog("xenconsoled", syslog_option, LOG_DAEMON);
151 setlogmask(syslog_mask);
153 if (!is_interactive) {
154 daemonize(pidfile ? pidfile : "/var/run/xenconsoled.pid");
155 }
157 if (!xen_setup())
158 exit(1);
160 enum_domains();
162 handle_io();
164 closelog();
165 free(log_dir);
166 free(pidfile);
168 return 0;
169 }
171 /*
172 * Local variables:
173 * c-file-style: "linux"
174 * indent-tabs-mode: t
175 * c-indent-level: 8
176 * c-basic-offset: 8
177 * tab-width: 8
178 * End:
179 */