debuggers.hg

view tools/console/daemon/main.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 91ce0b0953ca
children
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_MASK(LOG_WARNING)|LOG_MASK(LOG_ERR)|LOG_MASK(LOG_CRIT)|\
77 LOG_MASK(LOG_ALERT)|LOG_MASK(LOG_EMERG);
78 int opt_ind = 0;
79 char *pidfile = NULL;
81 while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
82 switch (ch) {
83 case 'h':
84 usage(argv[0]);
85 exit(0);
86 case 'V':
87 version(argv[0]);
88 exit(0);
89 case 'v':
90 #ifndef __sun__
91 syslog_option |= LOG_PERROR;
92 #endif
93 syslog_mask |= LOG_MASK(LOG_NOTICE)|LOG_MASK(LOG_INFO)| \
94 LOG_MASK(LOG_DEBUG);
95 break;
96 case 'i':
97 is_interactive = true;
98 break;
99 case 'l':
100 if (!strcmp(optarg, "all")) {
101 log_hv = 1;
102 log_guest = 1;
103 } else if (!strcmp(optarg, "hv")) {
104 log_hv = 1;
105 } else if (!strcmp(optarg, "guest")) {
106 log_guest = 1;
107 }
108 break;
109 case 'r':
110 log_dir = strdup(optarg);
111 break;
112 case 'p':
113 pidfile = strdup(optarg);
114 break;
115 case 't':
116 if (!strcmp(optarg, "all")) {
117 log_time_hv = 1;
118 log_time_guest = 1;
119 } else if (!strcmp(optarg, "hv")) {
120 log_time_hv = 1;
121 } else if (!strcmp(optarg, "guest")) {
122 log_time_guest = 1;
123 } else if (!strcmp(optarg, "none")) {
124 log_time_guest = 0;
125 log_time_hv = 0;
126 }
127 break;
128 case 'o':
129 if (!strcmp(optarg, "keep")) {
130 discard_overflowed_data = 0;
131 } else if (!strcmp(optarg, "discard")) {
132 discard_overflowed_data = 1;
133 }
134 break;
135 case '?':
136 fprintf(stderr,
137 "Try `%s --help' for more information\n",
138 argv[0]);
139 exit(EINVAL);
140 }
141 }
143 if (!log_dir) {
144 log_dir = strdup("/var/log/xen/console");
145 }
147 if (geteuid() != 0) {
148 fprintf(stderr, "%s requires root to run.\n", argv[0]);
149 exit(EPERM);
150 }
152 signal(SIGHUP, handle_hup);
154 openlog("xenconsoled", syslog_option, LOG_DAEMON);
155 setlogmask(syslog_mask);
157 if (!is_interactive) {
158 daemonize(pidfile ? pidfile : "/var/run/xenconsoled.pid");
159 }
161 if (!xen_setup())
162 exit(1);
164 enum_domains();
166 handle_io();
168 closelog();
169 free(log_dir);
170 free(pidfile);
172 return 0;
173 }
175 /*
176 * Local variables:
177 * c-file-style: "linux"
178 * indent-tabs-mode: t
179 * c-indent-level: 8
180 * c-basic-offset: 8
181 * tab-width: 8
182 * End:
183 */