2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <apr_general.h>
28 #include <apr_network_io.h>
29 #include <apr_getopt.h>
31 #include "hostinfod.h"
33 const char *conf_file = DEFAULT_CONF_FILE;
34 const char *socket_dir = DEFAULT_SOCKET_DIR;
35 char *guests_file = NULL;
36 int socket_dir_set_on_cmdline = 0;
38 int debug_set_on_cmdline = 0;
40 int verbose_set_on_cmdline = 0;
42 int foreground_set_on_cmdline = 0;
43 apr_pool_t *pool = NULL;
48 printf ("hostinfod (virt-hostinfo daemon)\n"
49 "Copyright (C) 2009 Red Hat Inc.\n"
52 " hostinfod [--options]\n"
55 " --help Display full usage\n"
56 " -c file | --config file\n"
57 " Configuration file (default: %s)\n"
58 " -d | --debug Enable debug messages to stderr (implies -v)\n"
59 " -f | --foreground\n"
60 " Run in the foreground (don't fork)\n"
61 " -s dir | --socketdir dir\n"
62 " Socket directory (default: %s)\n"
63 " -v Enable verbose messages (sent to syslog, and to\n"
64 " stderr if -d option is given)\n",
65 DEFAULT_CONF_FILE, DEFAULT_SOCKET_DIR);
69 main (int argc, char *argv[])
71 static const apr_getopt_option_t options[] = {
72 { "config", 'c', TRUE, "configuration file" },
73 { "debug", 'd', FALSE, "enable debug messages to stderr" },
74 { "foreground", 'f', FALSE, "run in foreground (don't fork)" },
75 { "socketdir", 's', TRUE, "socket directory" },
76 { "verbose", 'v', FALSE, "enable verbose messages" },
77 { "help", '?', FALSE, "display help" },
86 apr_pool_create (&pool, NULL);
88 apr_getopt_init (&opt, pool, argc, argv);
90 while ((r = apr_getopt_long (opt, options, &c, &optarg)) == APR_SUCCESS) {
94 /* If the user is specifying this on the command line, then
95 * it should exist. They may have typo'd the name.
97 if (access (conf_file, R_OK) == -1) {
104 debug_set_on_cmdline = verbose_set_on_cmdline = 1;
108 foreground_set_on_cmdline = 1;
112 socket_dir_set_on_cmdline = 1;
116 verbose_set_on_cmdline = 1;
126 fprintf (stderr, "%s: unknown command line option\n", argv[0]);
130 read_main_conf_file ();