X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_cgi.cpp;h=fd844c74171fa0e9ffdad654a17de2597855ecdf;hb=c1d953eee6c00432493bc364da6284704ccd9cc2;hp=3747e6323eed7a058fd960bd7412a7a9c1ef0a61;hpb=74d16c70e558c6b5fb0ff5b057a047d4da6d5a66;p=metaproxy-moved-to-github.git diff --git a/src/filter_cgi.cpp b/src/filter_cgi.cpp index 3747e63..fd844c7 100644 --- a/src/filter_cgi.cpp +++ b/src/filter_cgi.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2010 Index Data + Copyright (C) 2005-2011 Index Data Metaproxy is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include #include #include @@ -43,17 +44,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 +105,7 @@ void yf::CGI::process(mp::Package &package) const int r; pid_t pid; int status; - + pid = ::fork(); switch (pid) { @@ -109,8 +123,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;