mirror of
https://github.com/unraid/webgui.git
synced 2026-01-23 18:09:02 -06:00
Only do 'lsof' command on disks and shares; add timeout so it doesn't hang.
This commit is contained in:
@@ -28,6 +28,10 @@ require_once "$docroot/webGui/include/Translations.php";
|
||||
// remember current language
|
||||
$locale_init = $locale;
|
||||
|
||||
/* Parse the ini files */
|
||||
$shares = parse_ini_file('state/shares.ini', true);
|
||||
$disks = parse_ini_file('state/disks.ini', true);
|
||||
|
||||
function update_translation($locale) {
|
||||
global $docroot,$language;
|
||||
$language = [];
|
||||
@@ -91,10 +95,25 @@ while (true) {
|
||||
}
|
||||
// add fans information
|
||||
if (count($fans)) $echo['fan'] = array_map(function($fan){return "$fan RPM";},$fans);
|
||||
|
||||
// add streams information
|
||||
exec('LANG="en_US.UTF8" lsof -Fn /mnt/* 2>/dev/null|awk -F/ \'$1=="n" && $2=="mnt" && $5!="" {print $4"/"$5"/"$6"/"$7}\'|sort -u|awk -F/ \'{print $1}\'',$lsof);
|
||||
$share = array_keys(parse_ini_file("$varroot/shares.ini",true));
|
||||
$count = array_count_values($lsof);
|
||||
/* Extract keys from both ini files */
|
||||
$paths = array_merge(array_keys($shares), array_keys($disks));
|
||||
|
||||
/* Construct the list of paths */
|
||||
$mnt_paths = array_map(function($key) {
|
||||
return '/mnt/'.escapeshellarg($key);
|
||||
}, $paths);
|
||||
|
||||
/* Combine paths into the command */
|
||||
$mnt_list = implode(' ', $mnt_paths);
|
||||
|
||||
/* Build and execute the modified command */
|
||||
$command = 'LANG="en_US.UTF8" timeout 3 lsof -Fn '.$mnt_list.' 2>/dev/null | awk -F/ \'$1=="n" && $2=="mnt" && $5!="" {print $4"/"$5"/"$6"/"$7}\' | sort -u | awk -F/ \'{print $1}\'';
|
||||
exec($command, $lsof);
|
||||
|
||||
$share = array_keys($shares);
|
||||
$count = array_count_values($lsof ?? array());
|
||||
foreach ($share as $name) $echo['stream'][] = $count[$name]??0;
|
||||
$echo = json_encode($echo);
|
||||
$md5_new = md5($echo,true);
|
||||
|
||||
Reference in New Issue
Block a user