mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #158 from laf/issue-156
Urgent: Updated external_exec to use proc_open
This commit is contained in:
@@ -21,10 +21,43 @@ function format_number_short($number, $sf)
|
|||||||
|
|
||||||
function external_exec($command)
|
function external_exec($command)
|
||||||
{
|
{
|
||||||
global $debug;
|
global $debug , $exec_response;
|
||||||
|
|
||||||
|
$exec_response = array('command' => $command);
|
||||||
|
|
||||||
if ($debug) { echo($command."\n"); }
|
if ($debug) { echo($command."\n"); }
|
||||||
$output = shell_exec($command);
|
|
||||||
|
$descriptorspec = array(
|
||||||
|
0 => array('pipe', 'r'), // stdin
|
||||||
|
1 => array('pipe', 'w'), // stdout
|
||||||
|
2 => array('pipe', 'w') // stderr
|
||||||
|
);
|
||||||
|
|
||||||
|
$process = proc_open($command, $descriptorspec, $pipes);
|
||||||
|
stream_set_blocking($pipes[2], 0);
|
||||||
|
if (is_resource($process))
|
||||||
|
{
|
||||||
|
$exec_response['error'] = stream_get_contents($pipes[2]);
|
||||||
|
if ($exec_response['error'])
|
||||||
|
{
|
||||||
|
$output = FALSE;
|
||||||
|
} else {
|
||||||
|
$output = stream_get_contents($pipes[1]);
|
||||||
|
}
|
||||||
|
fclose($pipes[0]);
|
||||||
|
fclose($pipes[1]);
|
||||||
|
fclose($pipes[2]);
|
||||||
|
$exec_response['status'] = proc_close($process);
|
||||||
|
} else {
|
||||||
|
fclose($pipes[0]);
|
||||||
|
fclose($pipes[1]);
|
||||||
|
fclose($pipes[2]);
|
||||||
|
proc_terminate($process);
|
||||||
|
$output = FALSE;
|
||||||
|
$exec_error['error'] = '';
|
||||||
|
$exec_response['status'] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ($debug) { echo($output."\n"); }
|
if ($debug) { echo($output."\n"); }
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
@@ -47,7 +47,7 @@ function discover_new_device($hostname)
|
|||||||
|
|
||||||
function discover_device($device, $options = NULL)
|
function discover_device($device, $options = NULL)
|
||||||
{
|
{
|
||||||
global $config, $valid;
|
global $config, $valid, $exec_response;
|
||||||
|
|
||||||
$valid = array(); // Reset $valid array
|
$valid = array(); // Reset $valid array
|
||||||
|
|
||||||
|
@@ -89,7 +89,7 @@ function poll_sensor($device, $class, $unit)
|
|||||||
|
|
||||||
function poll_device($device, $options)
|
function poll_device($device, $options)
|
||||||
{
|
{
|
||||||
global $config, $device, $polled_devices, $db_stats, $memcache;
|
global $config, $device, $polled_devices, $db_stats, $memcache, $exec_response;
|
||||||
|
|
||||||
$attribs = get_dev_attribs($device['device_id']);
|
$attribs = get_dev_attribs($device['device_id']);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user