[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2988] When available use the ForkServer to execute CG
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [2988] When available use the ForkServer to execute CGI scripts. |
Date: |
Sat, 31 Jan 2009 19:05:37 +0000 |
Revision: 2988
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2988
Author: gscrivano
Date: 2009-01-31 19:05:36 +0000 (Sat, 31 Jan 2009)
Log Message:
-----------
When available use the ForkServer to execute CGI scripts.
Modified Paths:
--------------
trunk/myserver/include/base/process/fork_server.h
trunk/myserver/src/base/process/fork_server.cpp
trunk/myserver/src/http_handler/cgi/cgi.cpp
Modified: trunk/myserver/include/base/process/fork_server.h
===================================================================
--- trunk/myserver/include/base/process/fork_server.h 2009-01-31 17:55:29 UTC
(rev 2987)
+++ trunk/myserver/include/base/process/fork_server.h 2009-01-31 19:05:36 UTC
(rev 2988)
@@ -52,7 +52,8 @@
int forkServerLoop (SocketPair *socket);
int executeProcess (StartProcInfo *spi, int flags,
- int *pid, int *port);
+ int *pid, int *port,
+ bool waitEnd = false);
u_short getPort (){return port;}
bool isInitialized (){return initialized;}
Modified: trunk/myserver/src/base/process/fork_server.cpp
===================================================================
--- trunk/myserver/src/base/process/fork_server.cpp 2009-01-31 17:55:29 UTC
(rev 2987)
+++ trunk/myserver/src/base/process/fork_server.cpp 2009-01-31 19:05:36 UTC
(rev 2988)
@@ -23,6 +23,7 @@
#ifdef NOT_WIN
#include <unistd.h>
+#include <sys/wait.h>
#endif
/*!
@@ -32,7 +33,6 @@
*/
int ForkServer::writeFd (SocketPair *socket, FileHandle fd)
{
-
if (socket->writeHandle (fd))
return 1;
@@ -208,6 +208,9 @@
spi.stdOut = stdOut;
spi.stdError = stdErr;
+ spi.uid = uid;
+ spi.gid = gid;
+
spi.cmd.assign (exec);
spi.arg.assign (arg);
spi.cwd.assign (cwd);
@@ -225,24 +228,14 @@
delete [] env;
if (flags & FLAG_USE_IN)
- {
- Socket s0 (stdIn);
- s0.close ();
- }
+ close (stdIn);
if (flags & FLAG_USE_OUT)
- {
- Socket s1 (stdOut);
- s1.close ();
- }
+ close (stdOut);
if (flags & FLAG_USE_ERR)
- {
- Socket s0 (stdIn);
- s0.close ();
- }
+ close (stdErr);
-
return 0;
#endif
return 0;
@@ -300,10 +293,18 @@
*\param flags Flags.
*\param pid The new process ID.
*\param port if FLAG_STDIN_SOCKET was specified.
+ *\param waitEnd If true `executeProcess' will wait until
+ *the process terminates.
*/
int ForkServer::executeProcess (StartProcInfo *spi,
- int flags, int *pid, int *port)
+ int flags,
+ int *pid,
+ int *port,
+ bool waitEnd)
{
+#ifdef WIN32
+ return 0;
+#else
u_long nbw;
int len = 0;
const char * env = (const char *) spi->envString;
@@ -348,7 +349,14 @@
serverLock.unlock ();
+ if (waitEnd)
+ {
+ return waitpid (*pid, NULL, 0);
+ }
+
return 0;
+#endif
+
}
/*!
Modified: trunk/myserver/src/http_handler/cgi/cgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/cgi/cgi.cpp 2009-01-31 17:55:29 UTC (rev
2987)
+++ trunk/myserver/src/http_handler/cgi/cgi.cpp 2009-01-31 19:05:36 UTC (rev
2988)
@@ -269,7 +269,24 @@
/* Execute the CGI process. */
{
- if( cgiProc.exec (&spi) == -1)
+ int ret;
+ if (Process::getForkServer ()->isInitialized ())
+ {
+ int pid;
+ int port;
+
+ ret = Process::getForkServer ()->executeProcess (&spi,
+
ForkServer::FLAG_USE_IN |
+
ForkServer::FLAG_USE_OUT |
+
ForkServer::FLAG_USE_ERR,
+ &pid,
+ &port);
+ cgiProc.setPid (pid);
+ }
+ else
+ ret = cgiProc.exec (&spi);
+
+ if( ret == -1)
{
stdInFile.close();
stdOutFile.close();
@@ -277,7 +294,7 @@
("Cgi: Error in the CGI execution");
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
- }
+ }
/* Close the write stream of the pipe on the server. */
stdOutFile.closeWrite();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2988] When available use the ForkServer to execute CGI scripts.,
Giuseppe Scrivano <=