/* virt-hostinfo * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include "hostinfod.h" const char *conf_file = DEFAULT_CONF_FILE; const char *socket_dir = DEFAULT_SOCKET_DIR; char *guests_file = NULL; int socket_dir_set_on_cmdline = 0; int debug = 0; int debug_set_on_cmdline = 0; int verbose = 0; int verbose_set_on_cmdline = 0; int foreground = 0; int foreground_set_on_cmdline = 0; apr_pool_t *pool = NULL; static void usage (void) { printf ("hostinfod (virt-hostinfo daemon)\n" "Copyright (C) 2009 Red Hat Inc.\n" "\n" "Usage:\n" " hostinfod [--options]\n" "\n" "Options:\n" " --help Display full usage\n" " -c file | --config file\n" " Configuration file (default: %s)\n" " -d | --debug Enable debug messages to stderr (implies -v)\n" " -f | --foreground\n" " Run in the foreground (don't fork)\n" " -s dir | --socketdir dir\n" " Socket directory (default: %s)\n" " -v Enable verbose messages (sent to syslog, and to\n" " stderr if -d option is given)\n", DEFAULT_CONF_FILE, DEFAULT_SOCKET_DIR); } int main (int argc, char *argv[]) { static const apr_getopt_option_t options[] = { { "config", 'c', TRUE, "configuration file" }, { "debug", 'd', FALSE, "enable debug messages to stderr" }, { "foreground", 'f', FALSE, "run in foreground (don't fork)" }, { "socketdir", 's', TRUE, "socket directory" }, { "verbose", 'v', FALSE, "enable verbose messages" }, { "help", '?', FALSE, "display help" }, { NULL, 0, 0, NULL }, }; apr_status_t r; apr_getopt_t *opt; int c; const char *optarg; apr_initialize (); apr_pool_create (&pool, NULL); apr_getopt_init (&opt, pool, argc, argv); while ((r = apr_getopt_long (opt, options, &c, &optarg)) == APR_SUCCESS) { switch (c) { case 'c': conf_file = optarg; /* If the user is specifying this on the command line, then * it should exist. They may have typo'd the name. */ if (access (conf_file, R_OK) == -1) { perror (conf_file); exit (1); } break; case 'd': debug = verbose = 1; debug_set_on_cmdline = verbose_set_on_cmdline = 1; break; case 'f': foreground = 1; foreground_set_on_cmdline = 1; break; case 's': socket_dir = optarg; socket_dir_set_on_cmdline = 1; break; case 'v': verbose = 1; verbose_set_on_cmdline = 1; break; case '?': usage (); exit (0); default: abort (); } } if (r != APR_EOF) { fprintf (stderr, "%s: unknown command line option\n", argv[0]); exit (1); } read_main_conf_file (); /* Daemonize. */ chdir ("/"); if (!foreground) apr_proc_detach (1); apr_terminate (); return 0; }