src/rrd_daemon.c: Stat files before creating a tree-node for them.
authorFlorian Forster <octo@leeloo.home.verplant.org>
Sun, 13 Jul 2008 12:34:33 +0000 (14:34 +0200)
committerFlorian Forster <octo@leeloo.home.verplant.org>
Sun, 13 Jul 2008 12:34:33 +0000 (14:34 +0200)
This way `rrdtool update' does complain about nonexistent files.

src/rrd_daemon.c

index eb94e89..dfdd0e3 100644 (file)
@@ -909,6 +909,33 @@ static int handle_request_update (int fd, /* {{{ */
   ci = g_tree_lookup (cache_tree, file);
   if (ci == NULL) /* {{{ */
   {
   ci = g_tree_lookup (cache_tree, file);
   if (ci == NULL) /* {{{ */
   {
+    struct stat statbuf;
+
+    memset (&statbuf, 0, sizeof (statbuf));
+    status = stat (file, &statbuf);
+    if (status != 0)
+    {
+      pthread_mutex_unlock (&cache_lock);
+      RRDD_LOG (LOG_ERR, "handle_request_update: stat (%s) failed.", file);
+
+      status = errno;
+      if (status == ENOENT)
+        snprintf (answer, sizeof (answer), "-1 No such file: %s", file);
+      else
+        snprintf (answer, sizeof (answer), "-1 stat failed with error %i.\n",
+            status);
+      RRDD_UPDATE_SEND;
+      return (0);
+    }
+    if (!S_ISREG (statbuf.st_mode))
+    {
+      pthread_mutex_unlock (&cache_lock);
+
+      snprintf (answer, sizeof (answer), "-1 Not a regular file: %s", file);
+      RRDD_UPDATE_SEND;
+      return (0);
+    }
+
     ci = (cache_item_t *) malloc (sizeof (cache_item_t));
     if (ci == NULL)
     {
     ci = (cache_item_t *) malloc (sizeof (cache_item_t));
     if (ci == NULL)
     {