Acquire exclusive lock on <datadir>/server.lock to avoid data corruption (#2858)

this fixes #2855.
This commit is contained in:
Dylan T 2019-04-08 20:31:24 +01:00 committed by GitHub
parent 383ec8a8e3
commit 3925e598d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -189,6 +189,14 @@ namespace pocketmine {
mkdir(\pocketmine\DATA, 0777, true);
}
define('pocketmine\LOCK_FILE_PATH', \pocketmine\DATA . 'server.lock');
define('pocketmine\LOCK_FILE', fopen(\pocketmine\LOCK_FILE_PATH, "cb"));
if(!flock(\pocketmine\LOCK_FILE, LOCK_EX | LOCK_NB)){
critical_error("Another " . \pocketmine\NAME . " instance is already using this folder (" . realpath(\pocketmine\DATA) . ").");
critical_error("Please stop the other server first before running a new one.");
exit(1);
}
//Logger has a dependency on timezone
$tzError = Timezone::init();