2008-06-11 Esteban Sanchez <estebans@artica.es>
* pandora_windows_service.cc, modules/pandora_module_list.cc: Deleted debug output. * modules/pandora_module_exec.cc: Reindented the code. Add blank output to the module if there were nothing to read (like when the executions return nothing). * bin/PandoraAgent.exe: Updated to commit. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@854 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
48ed82ba8c
commit
6d05eec1c6
|
@ -1,3 +1,14 @@
|
|||
2008-06-11 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* pandora_windows_service.cc, modules/pandora_module_list.cc: Deleted
|
||||
debug output.
|
||||
|
||||
* modules/pandora_module_exec.cc: Reindented the code. Add blank
|
||||
output to the module if there were nothing to read (like when the
|
||||
executions return nothing).
|
||||
|
||||
* bin/PandoraAgent.exe: Updated to commit.
|
||||
|
||||
2008-06-11 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* bin/libodbc++.dll: Added to repository. Needed to run agent since
|
||||
|
|
Binary file not shown.
|
@ -294,7 +294,6 @@ Pandora_Module::getXml () {
|
|||
TiXmlText *text;
|
||||
string item_clean, data_clean, desc_clean;
|
||||
Pandora_Data *data;
|
||||
|
||||
|
||||
pandoraDebug ("%s getXML begin", module_name.c_str ());
|
||||
|
||||
|
@ -317,7 +316,7 @@ Pandora_Module::getXml () {
|
|||
root->InsertEndChild (*element);
|
||||
delete element;
|
||||
delete text;
|
||||
|
||||
|
||||
if (this->data_list && this->data_list->size () > 1) {
|
||||
list<Pandora_Data *>::iterator iter;
|
||||
|
||||
|
|
|
@ -36,127 +36,129 @@ using namespace Pandora_Modules;
|
|||
*/
|
||||
Pandora_Module_Exec::Pandora_Module_Exec (string name, string exec)
|
||||
: Pandora_Module (name) {
|
||||
this->module_exec = "cmd.exe /c \"" + exec + "\"";
|
||||
|
||||
this->setKind (module_exec_str);
|
||||
this->module_exec = "cmd.exe /c \"" + exec + "\"";
|
||||
|
||||
this->setKind (module_exec_str);
|
||||
}
|
||||
|
||||
void
|
||||
Pandora_Module_Exec::run () {
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
DWORD retval;
|
||||
SECURITY_ATTRIBUTES attributes;
|
||||
HANDLE out, new_stdout, out_read, job;
|
||||
string working_dir;
|
||||
|
||||
try {
|
||||
Pandora_Module::run ();
|
||||
} catch (Interval_Not_Fulfilled e) {
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
DWORD retval;
|
||||
SECURITY_ATTRIBUTES attributes;
|
||||
HANDLE out, new_stdout, out_read, job;
|
||||
string working_dir;
|
||||
|
||||
try {
|
||||
Pandora_Module::run ();
|
||||
} catch (Interval_Not_Fulfilled e) {
|
||||
this->has_output = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the bInheritHandle flag so pipe handles are inherited. */
|
||||
attributes.nLength = sizeof (SECURITY_ATTRIBUTES);
|
||||
attributes.bInheritHandle = TRUE;
|
||||
attributes.lpSecurityDescriptor = NULL;
|
||||
|
||||
/* Create a job to kill the child tree if it become zombie */
|
||||
/* CAUTION: In order to work this, WINVER should be defined to 0x0500.
|
||||
This may need no change, since it was redefined by the
|
||||
program, but if needed, the macro is defined
|
||||
in <windef.h> */
|
||||
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
||||
if (job == NULL) {
|
||||
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the bInheritHandle flag so pipe handles are inherited. */
|
||||
attributes.nLength = sizeof (SECURITY_ATTRIBUTES);
|
||||
attributes.bInheritHandle = TRUE;
|
||||
attributes.lpSecurityDescriptor = NULL;
|
||||
|
||||
/* Create a job to kill the child tree if it become zombie */
|
||||
/* CAUTION: In order to compile this, WINVER should be defined to 0x0500.
|
||||
This may need no change, since it was redefined by the
|
||||
program, but if needed, the macro is defined
|
||||
in <windef.h> */
|
||||
job = CreateJobObject (&attributes, this->module_name.c_str ());
|
||||
if (job == NULL) {
|
||||
pandoraLog ("CreateJobObject bad. Err: %d", GetLastError ());
|
||||
this->has_output = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the handle to the current STDOUT. */
|
||||
out = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
|
||||
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
||||
pandoraLog ("CreatePipe failed. Err: %d", GetLastError ());
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the handle to the current STDOUT. */
|
||||
out = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
|
||||
if (! CreatePipe (&out_read, &new_stdout, &attributes, 0)) {
|
||||
pandoraLog ("CreatePipe failed. Err: %d", GetLastError ());
|
||||
this->has_output = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ensure the read handle to the pipe for STDOUT is not inherited */
|
||||
SetHandleInformation (out_read, HANDLE_FLAG_INHERIT, 0);
|
||||
|
||||
/* Set up members of the STARTUPINFO structure. */
|
||||
ZeroMemory (&si, sizeof (si));
|
||||
GetStartupInfo (&si);
|
||||
|
||||
si.cb = sizeof (si);
|
||||
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
si.hStdError = new_stdout;
|
||||
si.hStdOutput = new_stdout;
|
||||
|
||||
/* Set up members of the PROCESS_INFORMATION structure. */
|
||||
ZeroMemory (&pi, sizeof (pi));
|
||||
pandoraDebug ("Executing: %s", this->module_exec.c_str ());
|
||||
|
||||
/* Set the working directory of the process. It's "utils" directory
|
||||
to find the GNU W32 tools */
|
||||
working_dir = getPandoraInstallDir () + "util\\";
|
||||
|
||||
/* Create the child process. */
|
||||
if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL,
|
||||
NULL, TRUE, CREATE_SUSPENDED, NULL,
|
||||
working_dir.c_str (), &si, &pi)) {
|
||||
pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d",
|
||||
this->module_name.c_str (), GetLastError ());
|
||||
return;
|
||||
}
|
||||
|
||||
/* Ensure the read handle to the pipe for STDOUT is not inherited */
|
||||
SetHandleInformation (out_read, HANDLE_FLAG_INHERIT, 0);
|
||||
|
||||
/* Set up members of the STARTUPINFO structure. */
|
||||
ZeroMemory (&si, sizeof (si));
|
||||
GetStartupInfo (&si);
|
||||
|
||||
si.cb = sizeof (si);
|
||||
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
si.hStdError = new_stdout;
|
||||
si.hStdOutput = new_stdout;
|
||||
|
||||
/* Set up members of the PROCESS_INFORMATION structure. */
|
||||
ZeroMemory (&pi, sizeof (pi));
|
||||
pandoraDebug ("Executing: %s", this->module_exec.c_str ());
|
||||
|
||||
/* Set the working directory of the process. It's "utils" directory
|
||||
to find the GNU W32 tools */
|
||||
working_dir = getPandoraInstallDir () + "util\\";
|
||||
|
||||
/* Create the child process. */
|
||||
if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL,
|
||||
NULL, TRUE, CREATE_SUSPENDED, NULL,
|
||||
working_dir.c_str (), &si, &pi)) {
|
||||
pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d",
|
||||
this->module_name.c_str (), GetLastError ());
|
||||
this->has_output = false;
|
||||
} else {
|
||||
char buffer[BUFSIZE + 1];
|
||||
unsigned long read, avail;
|
||||
|
||||
if (! AssignProcessToJobObject (job, pi.hProcess)) {
|
||||
pandoraLog ("Could not assigned proccess to job (error %d)",
|
||||
GetLastError ());
|
||||
}
|
||||
ResumeThread (pi.hThread);
|
||||
|
||||
/* Wait until process exits. */
|
||||
/* TODO: The time should be an attribute*/
|
||||
WaitForSingleObject (pi.hProcess, 15000);
|
||||
|
||||
GetExitCodeProcess (pi.hProcess, &retval);
|
||||
if (retval != 0) {
|
||||
if (! TerminateJobObject (job, 0)) {
|
||||
pandoraLog ("TerminateJobObject failed. (error %d)",
|
||||
GetLastError ());
|
||||
}
|
||||
|
||||
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
|
||||
this->module_name.c_str (), retval);
|
||||
} else {
|
||||
char buffer[BUFSIZE + 1];
|
||||
unsigned long read, avail;
|
||||
|
||||
if (! AssignProcessToJobObject (job, pi.hProcess)) {
|
||||
pandoraLog ("Could not assigned proccess to job (error %d)",
|
||||
GetLastError ());
|
||||
}
|
||||
ResumeThread (pi.hThread);
|
||||
|
||||
/* Wait until process exits. */
|
||||
/* TODO: The time should be an attribute*/
|
||||
WaitForSingleObject (pi.hProcess, 15000);
|
||||
|
||||
GetExitCodeProcess (pi.hProcess, &retval);
|
||||
if (retval != 0) {
|
||||
if (! TerminateJobObject (job, 0)) {
|
||||
pandoraLog ("TerminateJobObject failed. (error %d)",
|
||||
GetLastError ());
|
||||
}
|
||||
|
||||
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
|
||||
this->module_name.c_str (), retval);
|
||||
this->has_output = false;
|
||||
}
|
||||
|
||||
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
||||
/* Read from the stdout */
|
||||
if (read != 0) {
|
||||
}
|
||||
|
||||
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
||||
/* Read from the stdout */
|
||||
if (read != 0) {
|
||||
string output;
|
||||
do {
|
||||
ReadFile (out_read, buffer, BUFSIZE, &read,
|
||||
NULL);
|
||||
buffer[read] = '\0';
|
||||
output += (char *) buffer;
|
||||
} while (read >= BUFSIZE);
|
||||
do {
|
||||
ReadFile (out_read, buffer, BUFSIZE, &read,
|
||||
NULL);
|
||||
buffer[read] = '\0';
|
||||
output += (char *) buffer;
|
||||
} while (read >= BUFSIZE);
|
||||
this->setOutput (output);
|
||||
}
|
||||
|
||||
/* Close job, process and thread handles. */
|
||||
CloseHandle (job);
|
||||
CloseHandle (pi.hProcess);
|
||||
CloseHandle (pi.hThread);
|
||||
}
|
||||
|
||||
CloseHandle (new_stdout);
|
||||
CloseHandle (out_read);
|
||||
} else {
|
||||
this->setOutput ("");
|
||||
}
|
||||
|
||||
/* Close job, process and thread handles. */
|
||||
CloseHandle (job);
|
||||
CloseHandle (pi.hProcess);
|
||||
CloseHandle (pi.hThread);
|
||||
}
|
||||
|
||||
CloseHandle (new_stdout);
|
||||
CloseHandle (out_read);
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,6 @@ Pandora_Modules::Pandora_Module_List::parseModuleDefinition (string definition)
|
|||
module = Pandora_Module_Factory::getModuleFromDefinition (definition);
|
||||
|
||||
if (module != NULL) {
|
||||
cout << module->getModuleKind () << endl;
|
||||
switch (module->getModuleKind ()) {
|
||||
case MODULE_EXEC:
|
||||
module_exec = (Pandora_Module_Exec *) module;
|
||||
|
|
|
@ -135,7 +135,6 @@ Pandora_Windows_Service::pandora_init () {
|
|||
this->transfer_interval = this->interval;
|
||||
}
|
||||
}
|
||||
cout << "trans: " << this->transfer_interval << endl;
|
||||
|
||||
srand ((unsigned) time (0));
|
||||
this->setSleepTime (this->interval);
|
||||
|
@ -631,7 +630,7 @@ Pandora_Windows_Service::pandora_run () {
|
|||
}
|
||||
|
||||
this->elapsed_transfer_time += interval;
|
||||
cout << "interval time: " << interval << " transfer time:" << this->transfer_interval << " time passed: " << this->elapsed_transfer_time << endl;
|
||||
|
||||
if (this->elapsed_transfer_time >= this->transfer_interval) {
|
||||
agent = getXmlHeader ();
|
||||
|
||||
|
|
Loading…
Reference in New Issue