From c8ac254bb3539e089426392187e582462d07ebfe Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 13 Jul 2008 14:34:33 +0200 Subject: [PATCH] src/rrd_daemon.c: Stat files before creating a tree-node for them. This way `rrdtool update' does complain about nonexistent files. --- src/rrd_daemon.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index eb94e89..dfdd0e3 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -909,6 +909,33 @@ static int handle_request_update (int fd, /* {{{ */ 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) { -- 2.11.0