Commit 65d58636 authored by Andrey Filippov's avatar Andrey Filippov

modified "cmd=start" behavior

parent 2be574ef
......@@ -85,7 +85,9 @@ if (!isset($logger_config[LOGGER_FLEN])) $logger_config[LOGGER_FLEN] = DEFAULT_F
if (isset($_GET[LOGGER_MNT])) $logger_config[LOGGER_MNT] = $_GET[LOGGER_MNT];
if (isset($_GET[LOGGER_DIR])) $logger_config[LOGGER_DIR] = $_GET[LOGGER_DIR];
if (isset($_GET[LOGGER_FILE])) $logger_config[LOGGER_FILE] = $_GET[LOGGER_FILE];
if (isset($_GET[LOGGER_FLEN])) $logger_config[LOGGER_FLEN] = $_GET[LOGGER_FLEN];
if (isset($_GET[LOGGER_FLEN])) $logger_config[LOGGER_FLEN] = $_GET[LOGGER_FLEN]; // will set as string
$logger_config[LOGGER_FLEN] = numval($logger_config[LOGGER_FLEN]); // regardless of origin
//get parameters
if (isset($_GET['cmd'])) $cmd = $_GET['cmd'];
......@@ -127,12 +129,6 @@ switch ($cmd) {
$proc = getPIDByName('log_imu');
$was_running = count($proc) > 0;
$xml->addChild('prev_state', $was_running ? 'RUNNING' : 'STOPPED');
if ($was_running) {
$xml->addChild('error', 'was running');
add_state_to_xml($xml);
send_response($xml);
break;
}
$dir_path = $logger_config[LOGGER_MNT];
if ($logger_config[LOGGER_DIR]) {
$dir_path .= '/'.$logger_config[LOGGER_DIR];
......@@ -140,6 +136,22 @@ switch ($cmd) {
$pref_path = $dir_path.'/'.$logger_config[LOGGER_FILE];
$xml->addChild('dir_path', $dir_path);
$xml->addChild('pref_path', $pref_path);
if ($was_running) {
// 1. See if the path and num_records are the same. If yes, than continue
$same = ($proc[0]['argv'] >1) && ($pref_path == $proc[0]['argv'][1]);
$same &= ($proc[0]['argv'] >3) && (intval($logger_config[LOGGER_FLEN]) == intval($proc[0]['argv'][3]));
if (!$same){
$xml->addChild('info', 'Have to restart as parameters differ.');
// stop previous instance
exec("killall -1 ".BIN_NAME);
exec("sync");
// continue as when just starting
} else {
$xml->addChild('info', 'Reusing running instance.');
add_state_to_xml($xml);
break;
}
}
$indx = get_next_index($dir_path, $logger_config[LOGGER_FILE]);
if ($indx == -1){ // create directory recursive if it does not exist
$xml->addChild('mkdir', $dir_path);
......@@ -151,7 +163,7 @@ switch ($cmd) {
$indx = get_next_index($dir_path, $logger_config[LOGGER_FILE]);
}
if ($indx == -1) {
$xml->addChild('error', 'write dir does not exist');
$xml->addChild('error', 'write dir does not exist'); // should not get here as it was just mkder-ed
break;
}
if ($indx == -2) {
......@@ -162,8 +174,12 @@ switch ($cmd) {
$flen = $logger_config[LOGGER_FLEN];
exec("$exe $pref_path $indx $flen >/dev/null 2>&1 &");
add_state_to_xml($xml);
// save config
$config_xml = loggerConfigToXML($logger_config);
$conf_file = fopen ( LOGGER_CONF, "w");
fwrite ( $conf_file, $config_xml->asXML ());
fclose ( $conf_file );
break;
case 'state':
add_state_to_xml($xml);
break;
......@@ -292,7 +308,7 @@ function loggerConfigFromXML($confXML) {
break;
default :
// $conf[$key]=(int) $item;
$conf [$key] = (( string ) $item) + 0;
$conf [$key] = numval($item); // numeric int/float result
}
}
return $conf;
......@@ -322,6 +338,9 @@ function loggerConfigToXML($conf) {
return $logger_xml;
}
function numval($str){
return (( string ) $str) + 0; // numeric int/float result
}
......
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