Speedtest: created temp file prior to write actual result file.

This commit is contained in:
Riccardo Bicelli 2021-07-12 12:34:56 +02:00
parent 8f15f006f4
commit 7c28500ad9
1 changed files with 2 additions and 0 deletions

View File

@ -204,6 +204,7 @@ function pfz_speedtest_cron_install($enable=true){
function pfz_speedtest_exec ($ifname, $ipaddr){
$filename = "/tmp/speedtest-$ifname";
$filetemp = "$filename.tmp";
$filerun = "/tmp/speedtest-run";
if ( (time()-filemtime($filename) > SPEEDTEST_INTERVAL * 3600) || (file_exists($filename)==false) ) {
@ -214,6 +215,7 @@ function pfz_speedtest_exec ($ifname, $ipaddr){
touch($filerun);
$st_command = "/usr/local/bin/speedtest --source $ipaddr --json > $filename";
exec ($st_command);
rename($filetemp,$filename);
@unlink($filerun);
}
}