Commit ebaeff33 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

cmd=status will not hang

parent c152627e
...@@ -129,17 +129,39 @@ if ($cmd == "run_camogm") ...@@ -129,17 +129,39 @@ if ($cmd == "run_camogm")
} }
else if ($cmd == "status") else if ($cmd == "status")
{ {
$pipe="/var/state/camogm.state"; // is camogm running
$mode=0777; $camogm_running = "not running";
if(!file_exists($pipe)) {
umask(0); exec('ps | grep "camogm"', $arr);
posix_mkfifo($pipe,$mode); function low_daemon($v)
{
return (substr($v, -1) != ']');
} }
$fcmd=fopen($cmd_pipe,"w");
fprintf($fcmd, "xstatus=%s\n",$pipe); $p = (array_filter($arr, "low_daemon"));
fclose($fcmd); $check = implode("<br />",$p);
$status=file_get_contents($pipe); if (strstr($check, $start_str))
$camogm_running = "on";
else
$camogm_running = "off";
if ($camogm_running=="on"){
$pipe="/var/state/camogm.state";
$mode=0777;
if(!file_exists($pipe)) {
umask(0);
posix_mkfifo($pipe,$mode);
}
$fcmd=fopen($cmd_pipe,"w");
fprintf($fcmd, "xstatus=%s\n",$pipe);
fclose($fcmd);
$status=file_get_contents($pipe);
}else{
$status = "<?xml version='1.0'?><camogm_state>\n<state>".$camogm_running."</state>\n</camogm_state>";
}
header("Content-Type: text/xml"); header("Content-Type: text/xml");
header("Content-Length: ".strlen($status)."\n"); header("Content-Length: ".strlen($status)."\n");
header("Pragma: no-cache\n"); header("Pragma: no-cache\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment