From 668c08193e182ebf73da2b188a645a29cc7f759d Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Wed, 3 Aug 2016 16:40:31 -0500 Subject: [PATCH] Try to flush the output stream before we check it. --- includes/rrdtool.inc.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index c5c07939b3..4f3cbc6cb7 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -149,13 +149,13 @@ function rrdtool_graph($graph_file, $options) * @param string $command create, update, updatev, graph, graphv, dump, restore, fetch, tune, first, last, lastupdate, info, resize, xport, flushcached * @param string $filename The full patth to the rrd file * @param string $options rrdtool command options - * @param integer $timeout seconds give up waiting for output, default 5, setting this too low may disrupt subsequent rrdtool commands + * @param integer $timeout seconds give up waiting for output, default 0 * @return array the output of stdout and stderr in an array * @global config * @global debug * @global rrd_pipes */ -function rrdtool($command, $filename, $options, $timeout=5) +function rrdtool($command, $filename, $options, $timeout=0) { global $config, $debug, $rrd_pipes, $console_color; @@ -179,6 +179,10 @@ function rrdtool($command, $filename, $options, $timeout=5) print $console_color->convert('[%rRRD Disabled%n]'); $output = array(null, null); } else { + if ( $timeout > 0 && stream_select($r = $rrd_pipes, $w = null, $x = null, 0) ) { + // dump existing data + stream_get_contents($rrd_pipes[1]); + } fwrite($rrd_pipes[0], $cmd . "\n"); @@ -208,10 +212,10 @@ function rrdtool($command, $filename, $options, $timeout=5) */ function rrdtool_create($filename, $options) { - if (rrdtool_check_rrd_exists($filename)) { - return true; - } - return rrdtool('create', $filename, str_replace(array("\r", "\n"), '', $options)); + $options = str_replace(array("\r", "\n"), '', $options); + $options .= ' -O'; // do not overwrite files with create + + return rrdtool('create', $filename, $options); } /** @@ -225,7 +229,7 @@ function rrdtool_check_rrd_exists($filename) { global $config; if ($config['rrdcached'] && version_compare($config['rrdtool_version'], '1.5', '>=')) { - $chk = rrdtool('last', $filename, '', 5); // wait up to 5 seconds + $chk = rrdtool('last', $filename, '', 10); // wait up to 10 seconds return strpos(implode($chk), "$filename': No such file or directory") === false; } else { return is_file($filename);