Prevent running the sub process more than once.

This commit is contained in:
FusionPBX
2022-04-24 01:24:18 -06:00
committed by GitHub
parent e5a49f4d43
commit 5967f8ac1a

View File

@@ -55,8 +55,79 @@
}
//get the primary key
$fax_queue_uuid = $_GET['fax_queue_uuid'];
$hostname = $_GET['hostname'];
if (is_uuid($_GET['fax_queue_uuid'])) {
$fax_queue_uuid = $_GET['fax_queue_uuid'];
$hostname = $_GET['hostname'];
$sleep_seconds = $_GET['sleep'];
}
else {
//invalid uuid
exit;
}
//define the process id file
$pid_file = "/var/run/fusionpbx/fax_send".".".$fax_queue_uuid.".pid";
//echo "pid_file: ".$pid_file."\n";
//function to check if the process exists
function process_exists($file = false) {
//set the default exists to false
$exists = false;
//check to see if the process is running
if (file_exists($file)) {
$pid = file_get_contents($file);
if (posix_getsid($pid) === false) {
//process is not running
$exists = false;
}
else {
//process is running
$exists = true;
}
}
//return the result
return $exists;
}
//check to see if the process exists
$pid_exists = process_exists($pid_file);
//prevent the process running more than once
if ($pid_exists) {
//echo "Cannot lock pid file {$pid_file}\n";
exit;
}
//make sure the /var/run/fusionpbx directory exists
if (!file_exists('/var/run/fusionpbx')) {
$result = mkdir('/var/run/fusionpbx', 0777, true);
if (!$result) {
die('Failed to create /var/run/fusionpbx');
}
}
//create the process id file if the process doesn't exist
if (!$pid_exists) {
//remove the old pid file
if (file_exists($file)) {
unlink($pid_file);
}
//show the details to the user
//echo "The process id is ".getmypid()."\n";
//echo "pid_file: ".$pid_file."\n";
//save the pid file
file_put_contents($pid_file, getmypid());
}
//sleep used for debugging
if (isset($sleep_seconds)) {
sleep($sleep_seconds);
}
//prepare to save the output
if (isset($_GET['debug'])) {
@@ -476,6 +547,11 @@
//}
}
//remove the old pid file
if (file_exists($pid_file)) {
unlink($pid_file);
}
//wait for a few seconds
//sleep(1);