X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffilter_cgi.cpp;h=a89d03e4c96eb2b53177d5c2ef766f6ed88bd557;hb=018d0f565c921d316d91e8dcb80e86f6469ebc21;hp=3747e6323eed7a058fd960bd7412a7a9c1ef0a61;hpb=74d16c70e558c6b5fb0ff5b057a047d4da6d5a66;p=metaproxy-moved-to-github.git diff --git a/src/filter_cgi.cpp b/src/filter_cgi.cpp index 3747e63..a89d03e 100644 --- a/src/filter_cgi.cpp +++ b/src/filter_cgi.cpp @@ -43,17 +43,30 @@ namespace metaproxy_1 { class CGI::Rep { friend class CGI; std::list exec_map; + std::map children; + boost::mutex m_mutex; + public: + ~Rep(); }; } } yf::CGI::CGI() : m_p(new Rep) { + +} +yf::CGI::Rep::~Rep() +{ + std::map::const_iterator it; + boost::mutex::scoped_lock lock(m_mutex); + + for (it = children.begin(); it != children.end(); it++) + kill(it->second, SIGTERM); } yf::CGI::~CGI() -{ // must have a destructor because of boost::scoped_ptr +{ } void yf::CGI::process(mp::Package &package) const @@ -91,7 +104,7 @@ void yf::CGI::process(mp::Package &package) const int r; pid_t pid; int status; - + pid = ::fork(); switch (pid) { @@ -109,8 +122,18 @@ void yf::CGI::process(mp::Package &package) const package.response() = zgdu_res; break; default: /* parent */ + if (pid) + { + boost::mutex::scoped_lock lock(m_p->m_mutex); + m_p->children[pid] = pid; + } waitpid(pid, &status, 0); + if (pid) + { + boost::mutex::scoped_lock lock(m_p->m_mutex); + m_p->children.erase(pid); + } zgdu_res = odr.create_HTTP_Response( package.session(), zgdu_req->u.HTTP_Request, 200); package.response() = zgdu_res;