Removed the unlinking attempt at lockfp before exit: it was already done before by shutdown; other little changes about open files closing and the like

This commit is contained in:
pezcurrel 2022-12-17 18:43:13 +01:00
parent e5ad18e619
commit ca4367b719

View file

@ -167,15 +167,16 @@ for ($i=1; $i<$argc; $i++) {
}
$lockfp=__DIR__.'/peerscrawl.lock';
if (file_exists($lockfp) && !$opts['ignorelock'])
mexit('Lockfile exists: it seems the program is already running; if youre sure its not true, use «-I» to force execution.'.N,2);
if (is_file($lockfp) && !$opts['ignorelock']) {
echo('Lockfile exists: it seems the program is already running; if youre sure its not true, use «-I» to force execution.'.N);
exit(2);
}
touch($lockfp);
function mexit($msg,$code) {
global $link, $lockfp;
if ($link) mysqli_close($link);
if (isset($lockfp) && file_exists($lockfp))
unlink($lockfp);
if (isset($link) && $link!==false) mysqli_close($link);
if (isset($lockfp) && file_exists($lockfp)) unlink($lockfp);
if ($code==0)
echo($msg);
else
@ -217,8 +218,8 @@ function sortcheckandsave(&$arr,$arrdesc,&$fp) {
function shutdown($dosort) {
global $opts, $peersf, $allpeersf, $insts, $ainsts, $lockfp;
if ($peersf) @fclose($peersf);
if ($allpeersf) @fclose($allpeersf);
if (isset($peersf) && $peersf!==false) @fclose($peersf);
if (isset($allpeersf) && $allpeersf!==false) @fclose($allpeersf);
if (isset($lockfp) && file_exists($lockfp)) unlink($lockfp);
if ($dosort) {
sortcheckandsave($insts,'list of responding instances',$opts['peersfp']);
@ -441,14 +442,12 @@ function crawl($list,$id) {
}
$tini=time();
crawl(array($opts['startinst']),1);
gecho('DONE CRAWLING! :-)'.N,true,false);
shutdown(true);
$now=time();
gecho('Crawl started on '.date('Y-m-d H:i:s',$tini).' and ended on '.date('Y-m-d H:i:s',$now).'.'.N,true,false);
gecho(count($ainsts).' URIs checked in '.ght($now-$tini).'; '.count($insts).' responded. Max memory usage: '.ghs(memory_get_peak_usage(true)).N,true,false);
unlink($lockfp);
exit(0);
?>