From 9f36182b7d4747966bcd98dbc5a6b31a1dd6feb3 Mon Sep 17 00:00:00 2001 From: Louis Rossouw Date: Sun, 21 Jun 2015 19:36:44 +0200 Subject: [PATCH] Add timeout on unix agent execution after connect. --- includes/polling/unix-agent.inc.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index a1ea028bf..fa2fb1c90 100644 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -12,13 +12,23 @@ if ($device['os_group'] == "unix") $agent_start = utime(); $agent = fsockopen($device['hostname'], $agent_port, $errno, $errstr, 10); + // Set stream timeout (for timeouts during agent fetch + stream_set_timeout($agent,10); + $agentinfo = stream_get_meta_data($agent); + if (!$agent) { echo "Connection to UNIX agent failed on port ".$port."."; } else { - while (!feof($agent)) + // fetch data while not eof and not timed-out + while ((!feof($agent)) && (!$agentinfo['timed_out'])) { $agent_raw .= fgets($agent, 128); + $agentinfo = stream_get_meta_data($agent); + } + if ($agentinfo['timed_out']) + { + echo "Connection to UNIX agent timed out during fetch on port ".$port."."; } }