Hostinfo day 6: RPM packaging, initscripts, hostinfo-status, hostinfo-test.
[virt-hostinfo.git] / hostinfod / main.c
index e9ca8ae..b27338e 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 ();
 
@@ -354,7 +367,12 @@ do_reread_socket_dir (void)
    * been updated.
    */
   for (hi = apr_hash_first (pool, guests); hi; hi = apr_hash_next (hi)) {
-    apr_hash_this(hi, NULL, NULL, (void **) &hval);
+    /* On RHEL 5 this gives:
+     * dereferencing type-punned pointer will break strict-aliasing rules
+     * XXX
+     */
+    apr_hash_this (hi, NULL, NULL, (void **) &hval);
+
     if (hval->counter != count) {
       /* This hash table implementation allows you to delete the
        * current entry safely.
@@ -457,6 +475,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 +549,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)
 {