From 5b8402780372d71c9224cd164489c05a2af8f45b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 4 Oct 2016 17:49:56 +0200 Subject: [PATCH] Avoid zero division on systems with no swap --- pandora_agents/unix/plugins/pandora_mem | 16 +++++++++++-- .../include/functions_update_manager.php | 24 +++++++++++++------ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/pandora_agents/unix/plugins/pandora_mem b/pandora_agents/unix/plugins/pandora_mem index b918abe31b..e207f032d3 100755 --- a/pandora_agents/unix/plugins/pandora_mem +++ b/pandora_agents/unix/plugins/pandora_mem @@ -7,10 +7,22 @@ use POSIX; my $TOTAL=`vmstat -s | grep "total memory" | awk '{ print $1 } '`; my $FREE=`vmstat -s | grep "free memory" | awk '{ print $1 } '`; -my $FREEP=($FREE/$TOTAL)*100; +my $FREEP; +eval { +$FREEP=($FREE/$TOTAL)*100; +}; +if ($@) { + $FREEP = 0; +} my $STOTAL=`vmstat -s | grep "total swap" | awk '{ print $1 } '`; my $SUSED=`vmstat -s | grep "free swap" | awk '{ print $1 } '`; -my $SFREE=($SUSED/$STOTAL)*100; +my $SFREE; +eval { +$SFREE=($SUSED/$STOTAL)*100; +}; +if ($@) { + $SFREE = 0; +} $SFREE = floor($SFREE); $FREEP = floor($FREEP); diff --git a/pandora_console/include/functions_update_manager.php b/pandora_console/include/functions_update_manager.php index 2397b8ebde..b51db5aadf 100755 --- a/pandora_console/include/functions_update_manager.php +++ b/pandora_console/include/functions_update_manager.php @@ -56,6 +56,9 @@ function rrmdir($dir) { reset($objects); rmdir($dir); } + else { + unlink ($dir); + } } function update_manager_install_package_step2() { @@ -606,14 +609,19 @@ function update_manager_starting_update() { "/downloads/last_package.tgz"; $full_path = $config['attachment_store'] . "/downloads/pandora_console"; - rrmdir($full_path); - - + + $phar = new PharData($path_package); ob_start(); - $result = system("tar xvzf " . $path_package . - " -C " . $config['attachment_store'] . "/downloads/", $none); + try { + $result = $phar->extractTo($config['attachment_store'] . "/downloads/"); + } + catch (Exception $e) { + echo ' There\'s a problem ... -> ' . $e->getMessage(); + } ob_end_clean(); - + + rrmdir($path_package); + if ($result != 0) { db_process_sql_update('tconfig', array('value' => json_encode( @@ -640,7 +648,9 @@ function update_manager_starting_update() { $full_path, $homedir, array('install.php')); - + + rrmdir($full_path); + if (!$result) { db_process_sql_update('tconfig', array('value' => json_encode(