2011-04-05 Vanessa Gil <vanessa.gil@artica.es>
* win32/modules/pandora_module_exec.cc, win32/pandora_windows_service.cc: Fixed get module output part of over 4096 byte. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4305 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
b86a4fc557
commit
cc491d5c6e
|
@ -1,3 +1,9 @@
|
|||
2011-04-05 Vanessa Gil <vanessa.gil@artica.es>
|
||||
|
||||
* win32/modules/pandora_module_exec.cc,
|
||||
win32/pandora_windows_service.cc: Fixed get module output part of over 4096 byte.
|
||||
|
||||
|
||||
2011-03-17 Dario Rodriguez <dario.rodriguez@artica.es>
|
||||
|
||||
* unix/pandora_agent: Fixed a typo with logfile parameter. Also fixed
|
||||
|
|
|
@ -45,7 +45,7 @@ void
|
|||
Pandora_Module_Exec::run () {
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
DWORD retval;
|
||||
DWORD retval, dwRet;
|
||||
SECURITY_ATTRIBUTES attributes;
|
||||
HANDLE out, new_stdout, out_read, job;
|
||||
string working_dir;
|
||||
|
@ -121,41 +121,45 @@ Pandora_Module_Exec::run () {
|
|||
}
|
||||
ResumeThread (pi.hThread);
|
||||
|
||||
/* Wait until process exits. */
|
||||
WaitForSingleObject (pi.hProcess, this->getTimeout ());
|
||||
|
||||
string output;
|
||||
int tickbase = GetTickCount();
|
||||
while ( (dwRet = WaitForSingleObject (pi.hProcess, 500)) != WAIT_ABANDONED ) {
|
||||
PeekNamedPipe (out_read, buffer, BUFSIZE, &read, &avail, NULL);
|
||||
if (avail > 0) {
|
||||
ReadFile (out_read, buffer, BUFSIZE, &read, NULL);
|
||||
buffer[read] = '\0';
|
||||
output += (char *) buffer;
|
||||
}
|
||||
|
||||
if (dwRet == WAIT_OBJECT_0) {
|
||||
break;
|
||||
} else if(this->getTimeout() < GetTickCount() - tickbase) {
|
||||
/* STILL_ACTIVE */
|
||||
TerminateProcess(pi.hThread, STILL_ACTIVE);
|
||||
pandoraLog ("Pandora_Module_Exec: %s timed out (retcode: %d)", this->module_name.c_str (), STILL_ACTIVE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GetExitCodeProcess (pi.hProcess, &retval);
|
||||
|
||||
if (retval != 0) {
|
||||
if (! TerminateJobObject (job, 0)) {
|
||||
pandoraLog ("TerminateJobObject failed. (error %d)",
|
||||
GetLastError ());
|
||||
}
|
||||
|
||||
/* STILL_ACTIVE */
|
||||
if (retval == 259) {
|
||||
pandoraLog ("Pandora_Module_Exec: %s timed out (retcode: 259)",
|
||||
this->module_name.c_str ());
|
||||
} else {
|
||||
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) {
|
||||
string output;
|
||||
do {
|
||||
ReadFile (out_read, buffer, BUFSIZE, &read,
|
||||
NULL);
|
||||
buffer[read] = '\0';
|
||||
output += (char *) buffer;
|
||||
} while (read >= BUFSIZE);
|
||||
this->setOutput (output);
|
||||
} else {
|
||||
this->setOutput ("");
|
||||
if (retval != STILL_ACTIVE) {
|
||||
pandoraLog ("Pandora_Module_Exec: %s did not executed well (retcode: %d)",
|
||||
this->module_name.c_str (), retval);
|
||||
}
|
||||
this->has_output = false;
|
||||
}
|
||||
|
||||
if (!output.empty()) {
|
||||
this->setOutput (output);
|
||||
} else {
|
||||
this->setOutput ("");
|
||||
}
|
||||
|
||||
/* Close job, process and thread handles. */
|
||||
CloseHandle (job);
|
||||
|
|
|
@ -1194,6 +1194,7 @@ Pandora_Windows_Service::pandora_run () {
|
|||
|
||||
if (module->checkCron () == 1) {
|
||||
module->run ();
|
||||
Sleep(10);
|
||||
}
|
||||
|
||||
/* Save module data to an environment variable */
|
||||
|
|
Loading…
Reference in New Issue