diff options
author | Reinhard Tartler <siretart@tauware.de> | 2010-11-09 17:28:58 +0100 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2010-11-09 17:28:58 +0100 |
commit | 8a937bd354001a190dbe66538aacb353e7c99341 (patch) | |
tree | 9db021722d1743482e76f93d00fb97bed32a3ea7 /lib/server | |
parent | b591c86a418e8d5a0d1c1afd319d9acdad6fd4e3 (diff) |
Import upstream version 0.11~rc8~r2714
Diffstat (limited to 'lib/server')
-rw-r--r-- | lib/server/LocalProcessStream.cpp | 11 | ||||
-rw-r--r-- | lib/server/LocalProcessStream.h | 3 | ||||
-rw-r--r-- | lib/server/Makefile.extra | 4 | ||||
-rw-r--r-- | lib/server/ServerControl.cpp | 1 | ||||
-rw-r--r-- | lib/server/ServerStream.h | 54 |
5 files changed, 55 insertions, 18 deletions
diff --git a/lib/server/LocalProcessStream.cpp b/lib/server/LocalProcessStream.cpp index af24de1b..c331a135 100644 --- a/lib/server/LocalProcessStream.cpp +++ b/lib/server/LocalProcessStream.cpp @@ -43,13 +43,14 @@ // Created: 12/3/04 // // -------------------------------------------------------------------------- -std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidOut) +std::auto_ptr<IOStream> LocalProcessStream(const std::string& rCommandLine, + pid_t &rPidOut) { #ifndef WIN32 // Split up command std::vector<std::string> command; - SplitString(std::string(CommandLine), ' ', command); + SplitString(rCommandLine, ' ', command); // Build arguments char *args[MAX_ARGUMENTS + 4]; @@ -137,8 +138,8 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO startupInfo.hStdInput = INVALID_HANDLE_VALUE; startupInfo.dwFlags |= STARTF_USESTDHANDLES; - CHAR* commandLineCopy = (CHAR*)malloc(strlen(CommandLine) + 1); - strcpy(commandLineCopy, CommandLine); + CHAR* commandLineCopy = (CHAR*)malloc(rCommandLine.size() + 1); + strcpy(commandLineCopy, rCommandLine.c_str()); BOOL result = CreateProcess(NULL, commandLineCopy, // command line @@ -155,7 +156,7 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO if(!result) { - BOX_ERROR("Failed to CreateProcess: '" << CommandLine << + BOX_ERROR("Failed to CreateProcess: '" << rCommandLine << "': " << GetErrorMessage(GetLastError())); CloseHandle(writeInChild); CloseHandle(readFromChild); diff --git a/lib/server/LocalProcessStream.h b/lib/server/LocalProcessStream.h index 490c0f45..51e51f8a 100644 --- a/lib/server/LocalProcessStream.h +++ b/lib/server/LocalProcessStream.h @@ -13,7 +13,8 @@ #include <memory> #include "IOStream.h" -std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidOut); +std::auto_ptr<IOStream> LocalProcessStream(const std::string& rCommandLine, + pid_t &rPidOut); #endif // LOCALPROCESSSTREAM__H diff --git a/lib/server/Makefile.extra b/lib/server/Makefile.extra index 33fac0a1..7fc6baf9 100644 --- a/lib/server/Makefile.extra +++ b/lib/server/Makefile.extra @@ -3,9 +3,9 @@ MAKEEXCEPTION = ../../lib/common/makeexception.pl # AUTOGEN SEEDING autogen_ServerException.h autogen_ServerException.cpp: $(MAKEEXCEPTION) ServerException.txt - $(PERL) $(MAKEEXCEPTION) ServerException.txt + $(_PERL) $(MAKEEXCEPTION) ServerException.txt # AUTOGEN SEEDING autogen_ConnectionException.h autogen_ConnectionException.cpp: $(MAKEEXCEPTION) ConnectionException.txt - $(PERL) $(MAKEEXCEPTION) ConnectionException.txt + $(_PERL) $(MAKEEXCEPTION) ConnectionException.txt diff --git a/lib/server/ServerControl.cpp b/lib/server/ServerControl.cpp index c4668b57..b9650cee 100644 --- a/lib/server/ServerControl.cpp +++ b/lib/server/ServerControl.cpp @@ -1,6 +1,7 @@ #include "Box.h" #include <errno.h> +#include <stdio.h> #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index 34de7def..e49dbcbe 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -302,16 +302,7 @@ public: // Clean up child processes (if forking daemon) if(ForkToHandleRequests && !IsSingleProcess()) { - int status = 0; - int p = 0; - do - { - if((p = ::waitpid(0 /* any child in process group */, &status, WNOHANG)) == -1 - && errno != ECHILD && errno != EINTR) - { - THROW_EXCEPTION(ServerException, ServerWaitOnChildError) - } - } while(p > 0); + WaitForChildren(); } #endif // !WIN32 } @@ -326,6 +317,49 @@ public: DeleteSockets(); } + #ifndef WIN32 // no waitpid() on Windows + void WaitForChildren() + { + int p = 0; + do + { + int status = 0; + p = ::waitpid(0 /* any child in process group */, + &status, WNOHANG); + + if(p == -1 && errno != ECHILD && errno != EINTR) + { + THROW_EXCEPTION(ServerException, + ServerWaitOnChildError) + } + else if(p == 0) + { + // no children exited, will return from + // function + } + else if(WIFEXITED(status)) + { + BOX_INFO("child process " << p << " " + "terminated normally"); + } + else if(WIFSIGNALED(status)) + { + int sig = WTERMSIG(status); + BOX_ERROR("child process " << p << " " + "terminated abnormally with " + "signal " << sig); + } + else + { + BOX_WARNING("something unknown happened " + "to child process " << p << ": " + "status = " << status); + } + } + while(p > 0); + } + #endif + virtual void HandleConnection(StreamType &rStream) { Connection(rStream); |