taskman_lock/lock.inc.php

45 lines
787 B
PHP

<?php
namespace taskman;
function gamectl_check_lock()
{
global $GAME_ROOT;
if(getenv("GAMECTL_IN_LOCK"))
return;
//don't bother with windows
if(DIRECTORY_SEPARATOR != '/')
return;
$lock = $GAME_ROOT . '/gamectl.lock';
while(file_exists($lock))
{
echo "gamectl is locked. Waiting...\n";
$pid = file_get_contents($lock);
if(!trim(exec("lsof -p $pid")))
{
echo "Seems gamectl process is gone but lock still exists, proceeding..\n";
break;
}
sleep(1);
}
register_shutdown_function('taskman\\gamectl_unlock');
putenv("GAMECTL_IN_LOCK=1");
file_put_contents($lock, getmypid());
}
function gamectl_unlock()
{
global $GAME_ROOT;
$lock = $GAME_ROOT . '/gamectl.lock';
if(file_exists($lock))
unlink($lock);
}