From 4ba70d27087d6daffc75e8a04fed345e0f6003b3 Mon Sep 17 00:00:00 2001 From: Larry Adams Date: Mon, 20 Sep 2004 23:00:35 +0000 Subject: [PATCH] fix for early reads from RRDTool pipe git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/trunk/cacti@2086 860744bd-22fc-0310-8c96-e9fe5004b5ca --- lib/rrd.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/rrd.php b/lib/rrd.php index d016979eb8..3f6f67c3ae 100644 --- a/lib/rrd.php +++ b/lib/rrd.php @@ -42,8 +42,8 @@ function rrd_init() { $rrd_struc["fd"] = proc_open(read_config_option("path_rrdtool") . " -", $rrd_des, $rrd_pipes); $rrd_struc["pipes"] = $rrd_pipes; - stream_set_blocking($rrd_struc["pipes"][RRDTOOL_PIPE_CHILD_READ], false); - stream_set_blocking($rrd_struc["pipes"][RRDTOOL_PIPE_CHILD_WRITE], false); + stream_set_blocking($rrd_struc["pipes"][RRDTOOL_PIPE_CHILD_READ], true); + stream_set_blocking($rrd_struc["pipes"][RRDTOOL_PIPE_CHILD_WRITE], true); }else { $rrd_struc["fd"] = popen(read_config_option("path_rrdtool") . " -", "w"); } @@ -133,7 +133,7 @@ function rrdtool_execute($command_line, $log_to_stdout, $output_flag, $rrd_struc } if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_HIGH) { - cacti_log("RRD2CACTI: " . strip_newlines($line), false); + cacti_log("RRD2CACTI: " . strip_newlines($line), false, "POLLER"); } return $line; @@ -143,13 +143,25 @@ function rrdtool_execute($command_line, $log_to_stdout, $output_flag, $rrd_struc $fp = rrd_get_fd($rrd_struc, RRDTOOL_PIPE_CHILD_WRITE); } - $line = fgets($fp, 4096); + /* Prepare the read array */ + $read_fd = array($fp); - if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_HIGH) { - cacti_log("RRD2CACTI: " . strip_newlines($line), $log_to_stdout); + if (false === ($num_changed_streams = stream_select($read_fd, $write_fd = NULL, $except_fd = NULL, 2, 0))) { + /* Error handling */ + if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_HIGH) { + cacti_log("RRD2CACTI: ERROR: RRD Did not Respond to RRDTool Command", $log_to_stdout, "POLLER"); + } + } elseif ($num_changed_streams > 0) { + /* At least on one of the streams something interesting happened */ + $line = fgets($fp, 4096); + + if (read_config_option("log_verbosity") >= POLLER_VERBOSITY_HIGH) { + cacti_log("RRD2CACTI: " . strip_newlines($line), $log_to_stdout, "POLLER"); + } + + return $line; } - return $line; } break;