Hostinfo day 5: Implement first round of static host commands.
[virt-hostinfo.git] / hostinfod / main.c
index e9ca8ae..7c9601a 100644 (file)
@@ -57,6 +57,9 @@ const char *conf_file = DEFAULT_CONF_FILE;
 char *socket_dir = NULL;
 char *guests_file = NULL;
 
+char *libvirt_uri = NULL;
+int libvirt_uri_set_on_cmdline = 0;
+
 int verbose = 0;
 int verbose_set_on_cmdline = 0;
 int foreground = 0;
@@ -91,6 +94,8 @@ usage (void)
          "  --help           Display full usage\n"
          "  -c file | --config file\n"
          "                   Configuration file (default: %s)\n"
+         "  -C uri | --connect uri\n"
+         "                   Set libvirt connection URI (default: NULL)\n"
          "  -f | --foreground\n"
          "                   Run in the foreground (don't fork)\n"
          "  -v               Enable verbose messages (sent to syslog)\n",
@@ -110,6 +115,7 @@ main (int argc, char *argv[])
 {
   static const apr_getopt_option_t options[] = {
     { "config", 'c', TRUE, "configuration file" },
+    { "connect", 'C', TRUE, "libvirt connection URI" },
     { "foreground", 'f', FALSE, "run in foreground (don't fork)" },
     { "verbose", 'v', FALSE, "enable verbose messages" },
     { "help", '?', FALSE, "display help" },
@@ -146,6 +152,10 @@ main (int argc, char *argv[])
        exit (1);
       }
       break;
+    case 'C':
+      libvirt_uri = optarg;
+      libvirt_uri_set_on_cmdline = 1;
+      break;
     case 'f':
       foreground = 1;
       foreground_set_on_cmdline = 1;
@@ -169,6 +179,9 @@ main (int argc, char *argv[])
   /* Read the config file. */
   read_main_conf_file ();
 
+  /* Connect to libvirt. */
+  init_libvirt ();
+
   /* Monitor the socket directory. */
   monitor_socket_dir ();
 
@@ -457,6 +470,7 @@ guest_added (const char *sock_path, const char *name)
   hval->sock = sock;
   hval->request_max = 4096;
   hval->request = apr_palloc (hval->pool, hval->request_max);
+  hval->lasttime = apr_hash_make (hval->pool);
 
   /* Convert Unix fd into APR socket type. */
   r = apr_os_sock_put (&hval->aprsock, &sock, hval->pool);
@@ -530,7 +544,7 @@ guest_force_close (struct guest_description *hval)
 }
 
 /* Difference between two timespec structures (r = a - b) */
-static struct timespec *
+struct timespec *
 diff_timespec (struct timespec *r,
               const struct timespec *a, const struct timespec *b)
 {