src/rrdd.c: Implement option parsing.
authorFlorian Forster <octo@leeloo.home.verplant.org>
Sun, 22 Jun 2008 09:57:08 +0000 (11:57 +0200)
committerFlorian Forster <octo@leeloo.home.verplant.org>
Sun, 22 Jun 2008 09:57:08 +0000 (11:57 +0200)
The write interval is no longer hard coded. The other options are not
yet implemented.

src/rrdd.c

index 4ae3daa..c2f7936 100644 (file)
@@ -75,6 +75,9 @@ static cache_item_t   *cache_queue_tail = NULL;
 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t  cache_cond = PTHREAD_COND_INITIALIZER;
 
+static int config_write_interval = 300;
+static int config_flush_interval = 3600;
+
 /* 
  * Functions
  */
@@ -283,8 +286,7 @@ static int handle_request_update (int fd, /* {{{ */
     values_num++;
   }
 
-  /* FIXME: Timeout should not be hard-coded. */
-  if (((now - ci->last_flush_time) > 300)
+  if (((now - ci->last_flush_time) >= config_write_interval)
       && ((ci->flags & CI_FLAGS_IN_QUEUE) == 0))
   {
     RRDD_LOG (LOG_DEBUG, "handle_request_update: Adding %s to the update queue.",
@@ -685,12 +687,85 @@ static int cleanup (void) /* {{{ */
   return (0);
 } /* }}} int cleanup */
 
+static int read_options (int argc, char **argv) /* {{{ */
+{
+  int option;
+  int status = 0;
+
+  while ((option = getopt(argc, argv, "l:f:w:h?")) != -1)
+  {
+    switch (option)
+    {
+      case 'l':
+      {
+        printf ("Listening to: %s\n", optarg);
+      }
+      break;
+
+      case 'f':
+      {
+        int temp;
+
+        temp = atoi (optarg);
+        if (temp > 0)
+          config_flush_interval = temp;
+        else
+        {
+          fprintf (stderr, "Invalid flush interval: %s\n", optarg);
+          status = 3;
+        }
+      }
+      break;
+
+      case 'w':
+      {
+        int temp;
+
+        temp = atoi (optarg);
+        if (temp > 0)
+          config_write_interval = temp;
+        else
+        {
+          fprintf (stderr, "Invalid write interval: %s\n", optarg);
+          status = 2;
+        }
+      }
+      break;
+
+      case 'h':
+      case '?':
+        printf ("RRDd %s  Copyright (C) 2008 Florian octo Forster\n"
+            "\n"
+            "Usage: rrdd [options]\n"
+            "\n"
+            "Valid options are:\n"
+            "  -l <address>  Socket address to listen to.\n"
+            "  -w <seconds>  Interval in which to write data.\n"
+            "  -f <seconds>  Interval in which to flush dead data.\n"
+            "\n"
+            "For more information and a detailed description of all options "
+            "please refer\n"
+            "to the rrdd(1) manual page.\n",
+            PACKAGE_VERSION);
+        status = -1;
+        break;
+    } /* switch (option) */
+  } /* while (getopt) */
+
+  return (status);
+} /* }}} int read_options */
+
 int main (int argc, char **argv)
 {
   int status;
 
-  printf ("%s by Florian Forster, Version %s\n",
-      PACKAGE_NAME, PACKAGE_VERSION);
+  status = read_options (argc, argv);
+  if (status != 0)
+  {
+    if (status < 0)
+      status = 0;
+    return (status);
+  }
 
   status = daemonize ();
   if (status == 1)