kaf24@6038: /*\ kaf24@6038: * Copyright (C) International Business Machines Corp., 2005 kaf24@6038: * Author(s): Anthony Liguori kaf24@6038: * kaf24@6038: * Xen Console Daemon kaf24@6038: * kaf24@6038: * This program is free software; you can redistribute it and/or modify kaf24@6038: * it under the terms of the GNU General Public License as published by kaf24@6038: * the Free Software Foundation; under version 2 of the License. kaf24@6038: * kaf24@6038: * This program is distributed in the hope that it will be useful, kaf24@6038: * but WITHOUT ANY WARRANTY; without even the implied warranty of kaf24@6038: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kaf24@6038: * GNU General Public License for more details. kaf24@6038: * kaf24@6038: * You should have received a copy of the GNU General Public License kaf24@6038: * along with this program; if not, write to the Free Software kaf24@6038: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA kaf24@6038: \*/ kaf24@6038: kaf24@6038: #include kaf24@6038: #include kaf24@6038: #include kaf24@6038: #include kaf24@6038: #include kaf24@6038: #include kaf24@6038: cl349@6388: #include "xenctrl.h" kaf24@6038: kaf24@6038: #include "utils.h" kaf24@6038: #include "io.h" kaf24@6038: vh249@6725: void usage(char *prg) vh249@6725: { vh249@6725: fprintf(stderr, vh249@6725: "usage: %s [-h] [-V] [-v] [-i]\n", prg); vh249@6725: } vh249@6725: kaf24@6038: int main(int argc, char **argv) kaf24@6038: { kaf24@6038: const char *sopts = "hVvi"; kaf24@6038: struct option lopts[] = { kaf24@6038: { "help", 0, 0, 'h' }, kaf24@6038: { "version", 0, 0, 'V' }, kaf24@6038: { "verbose", 0, 0, 'v' }, kaf24@6038: { "interactive", 0, 0, 'i' }, kaf24@6038: { 0 }, kaf24@6038: }; kaf24@6038: bool is_interactive = false; kaf24@6038: int ch; kaf24@6038: int syslog_option = LOG_CONS; kaf24@6038: int syslog_mask = LOG_WARNING; kaf24@6038: int opt_ind = 0; kaf24@6038: kaf24@6038: while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) { kaf24@6038: switch (ch) { kaf24@6038: case 'h': vh249@6725: usage(argv[0]); kaf24@6038: exit(0); kaf24@6038: case 'V': kaf24@6038: //version(argv[0]); kaf24@6038: exit(0); kaf24@6038: case 'v': kaf24@6038: syslog_option |= LOG_PERROR; kaf24@6038: syslog_mask = LOG_DEBUG; kaf24@6038: break; kaf24@6038: case 'i': kaf24@6038: is_interactive = true; kaf24@6038: break; kaf24@6038: case '?': kaf24@6038: fprintf(stderr, kaf24@6038: "Try `%s --help' for more information\n", kaf24@6038: argv[0]); kaf24@6038: exit(EINVAL); kaf24@6038: } kaf24@6038: } kaf24@6038: kaf24@6038: if (geteuid() != 0) { kaf24@6038: fprintf(stderr, "%s requires root to run.\n", argv[0]); kaf24@6038: exit(EPERM); kaf24@6038: } kaf24@6038: kaf24@6038: openlog("xenconsoled", syslog_option, LOG_DAEMON); kaf24@6038: setlogmask(syslog_mask); kaf24@6038: kaf24@6038: if (!is_interactive) { kaf24@6038: daemonize("/var/run/xenconsoled.pid"); kaf24@6038: } kaf24@6038: cl349@6647: if (!xen_setup()) cl349@6647: exit(1); kaf24@6038: cl349@6484: enum_domains(); cl349@6484: kaf24@6038: handle_io(); kaf24@6038: kaf24@6038: closelog(); kaf24@6038: kaf24@6038: return 0; kaf24@6038: }