From 1b2eff44387f49f68cfc400aa9d4b5185e9f4532 Mon Sep 17 00:00:00 2001 From: Akihiro Uchida Date: Thu, 26 Feb 2015 01:38:28 +0900 Subject: [PATCH 1/3] Remember the agent_name_cmd result in xml header --- pandora_agents/win32/pandora_windows_service.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index fe5980e8d4..ef6136a32a 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -370,7 +370,7 @@ Pandora_Windows_Service::launchTentacleProxy() { string Pandora_Windows_Service::getXmlHeader () { char timestamp[20]; - string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd, temp_agent_name; + string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd; string custom_id, url_address, latitude, longitude, altitude, position_description, gis_exec, gis_result; time_t ctime; struct tm *ctime_tm = NULL; @@ -385,7 +385,7 @@ Pandora_Windows_Service::getXmlHeader () { agent_name_cmd = conf->getValue ("agent_name_cmd"); if (agent_name_cmd != "") { agent_name_cmd = "cmd.exe /c \"" + agent_name_cmd + "\""; - temp_agent_name = getCoordinatesFromCmdExec(agent_name_cmd); + static string temp_agent_name = getCoordinatesFromCmdExec(agent_name_cmd); // Delete carriage return if is provided pos = temp_agent_name.find("\n"); if(pos != string::npos) { From 9ff9a4149479125b46ed1459cd23d6d1e296cb60 Mon Sep 17 00:00:00 2001 From: Akihiro Uchida Date: Wed, 4 Mar 2015 20:18:47 +0900 Subject: [PATCH 2/3] Extend getCoordinatesFromCmdExec timeout to 500 ms to make consistent with timeout for WaitForSingleObject --- pandora_agents/win32/pandora_windows_service.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index ef6136a32a..69bd415267 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -546,7 +546,7 @@ Pandora_Windows_Service::getCoordinatesFromCmdExec (string cmd_exec) HANDLE out, new_stdout, out_read, job; string working_dir; string output = ""; - int timeout = 30; + int timeout = 500; /* Set the bInheritHandle flag so pipe handles are inherited. */ attributes.nLength = sizeof (SECURITY_ATTRIBUTES); From ce6d76eabcd7dca2876fb516dafd57b5b5d8d7cb Mon Sep 17 00:00:00 2001 From: Akihiro Uchida Date: Wed, 4 Mar 2015 20:23:05 +0900 Subject: [PATCH 3/3] Separate getAgentNameCmdExec from getCoordinatesFromCmdExec --- pandora_agents/win32/pandora_windows_service.cc | 17 ++++++++++++++--- pandora_agents/win32/pandora_windows_service.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 69bd415267..9e3892da1c 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -385,7 +385,7 @@ Pandora_Windows_Service::getXmlHeader () { agent_name_cmd = conf->getValue ("agent_name_cmd"); if (agent_name_cmd != "") { agent_name_cmd = "cmd.exe /c \"" + agent_name_cmd + "\""; - static string temp_agent_name = getCoordinatesFromCmdExec(agent_name_cmd); + static string temp_agent_name = getAgentNameFromCmdExec(agent_name_cmd); // Delete carriage return if is provided pos = temp_agent_name.find("\n"); if(pos != string::npos) { @@ -536,7 +536,7 @@ Pandora_Windows_Service::getXmlHeader () { } string -Pandora_Windows_Service::getCoordinatesFromCmdExec (string cmd_exec) +Pandora_Windows_Service::getValueFromCmdExec (string cmd_exec, int timeout) { PROCESS_INFORMATION pi; STARTUPINFO si; @@ -546,7 +546,6 @@ Pandora_Windows_Service::getCoordinatesFromCmdExec (string cmd_exec) HANDLE out, new_stdout, out_read, job; string working_dir; string output = ""; - int timeout = 500; /* Set the bInheritHandle flag so pipe handles are inherited. */ attributes.nLength = sizeof (SECURITY_ATTRIBUTES); @@ -660,6 +659,18 @@ Pandora_Windows_Service::getCoordinatesFromCmdExec (string cmd_exec) return output; } +string +Pandora_Windows_Service::getAgentNameFromCmdExec (string cmd_exec) +{ + return getValueFromCmdExec(cmd_exec, 10000); +} + +string +Pandora_Windows_Service::getCoordinatesFromCmdExec (string cmd_exec) +{ + return getValueFromCmdExec(cmd_exec, 500); +} + int Pandora_Windows_Service::copyTentacleDataFile (string host, string filename, diff --git a/pandora_agents/win32/pandora_windows_service.h b/pandora_agents/win32/pandora_windows_service.h index 16d02ab433..c64152dd0f 100644 --- a/pandora_agents/win32/pandora_windows_service.h +++ b/pandora_agents/win32/pandora_windows_service.h @@ -53,6 +53,8 @@ namespace Pandora { string getXmlHeader (); int copyDataFile (string filename); + string getValueFromCmdExec (string cmd_exec, int timeout); + string getAgentNameFromCmdExec (string cmd_exec); string getCoordinatesFromCmdExec (string cmd_exec); int copyTentacleDataFile (string host, string filename,