Bug #3222 » bug_3222.patch
| src/fcgi/Server.C | ||
|---|---|---|
|
Server::Server(WServer& wt, int argc, char *argv[])
|
||
|
: wt_(wt),
|
||
|
argc_(argc),
|
||
|
argv_(argv)
|
||
|
argv_(argv),
|
||
|
childrenDied_(0),
|
||
|
handleSigChld_(0)
|
||
|
{
|
||
|
instance = this;
|
||
| ... | ... | |
|
LOG_DEBUG("argv[" << i << "]: " << argv[i]);
|
||
|
}
|
||
|
#ifdef WT_THREADED
|
||
|
// Unblocking all signals before exec
|
||
|
sigset_t mask;
|
||
|
sigfillset(&mask);
|
||
|
pthread_sigmask(SIG_UNBLOCK, &mask, 0);
|
||
|
#endif // WT_THREADED
|
||
|
execv(argv[0], const_cast<char *const *>(argv));
|
||
|
delete[] argv;
|
||
| ... | ... | |
|
exit(1);
|
||
|
} else {
|
||
|
LOG_INFO_S(&wt_, "spawned session process: pid = " << pid);
|
||
|
#ifdef WT_THREADED
|
||
|
boost::recursive_mutex::scoped_lock sessionsLock(mutex_);
|
||
|
#endif
|
||
|
sessionProcessPids_.push_back(pid);
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
void Server::handleSigChld()
|
||
|
{
|
||
|
handleSigChld_ = 1;
|
||
|
}
|
||
|
void Server::doHandleSigChld()
|
||
|
{
|
||
|
pid_t cpid;
|
||
|
int stat;
|
||
| ... | ... | |
|
Configuration& conf = wt_.configuration();
|
||
|
if (conf.sessionPolicy() == Configuration::DedicatedProcess) {
|
||
|
for (SessionMap::iterator i = sessions_.begin(); i != sessions_.end();
|
||
|
++i)
|
||
|
#ifdef WT_THREADED
|
||
|
boost::recursive_mutex::scoped_lock sessionsLock(mutex_);
|
||
|
#endif
|
||
|
for (SessionMap::iterator i = sessions_.begin(); i != sessions_.end(); ++i) {
|
||
|
if (i->second->childPId() == cpid) {
|
||
|
LOG_INFO_S(&wt_, "deleting session: " << i->second->sessionId());
|
||
| ... | ... | |
|
break;
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
#ifdef WT_THREADED
|
||
|
boost::recursive_mutex::scoped_lock sessionsLock(mutex_);
|
||
|
#endif
|
||
|
for (unsigned i = 0; i < sessionProcessPids_.size(); ++i) {
|
||
|
if (sessionProcessPids_[i] == cpid) {
|
||
|
sessionProcessPids_.erase(sessionProcessPids_.begin() + i);
|
||
| ... | ... | |
|
* TODO: cleanup all sessions that pointed to this pid
|
||
|
*/
|
||
|
static int childrenDied = 0;
|
||
|
++childrenDied;
|
||
|
++childrenDied_;
|
||
|
if (childrenDied < 5)
|
||
|
if (childrenDied_ < 5) {
|
||
|
spawnSharedProcess();
|
||
|
else
|
||
|
} else
|
||
|
LOG_ERROR_S(&wt_, "sessions process restart limit (5) reached");
|
||
|
break;
|
||
| ... | ... | |
|
exit (1);
|
||
|
}
|
||
|
checkAndQueueSigChld();
|
||
|
handleRequestThreaded(serverSocket);
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
void Server::checkAndQueueSigChld()
|
||
|
{
|
||
|
if (handleSigChld_ == 1) {
|
||
|
sigset_t new_mask;
|
||
|
sigemptyset(&new_mask);
|
||
|
sigaddset(&new_mask, SIGCHLD);
|
||
|
sigset_t old_mask;
|
||
|
#ifdef WT_THREADED
|
||
|
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
||
|
#else
|
||
|
sigprocmask(SIG_BLOCK, &new_mask, &old_mask);
|
||
|
#endif // WT_THREADED
|
||
|
if (handleSigChld_ == 1) {
|
||
|
handleSigChld_ = 0;
|
||
|
#ifdef WT_THREADED
|
||
|
wt_.ioService().post(boost::bind(&Server::doHandleSigChld, this));
|
||
|
#else
|
||
|
doHandleSigChld();
|
||
|
#endif // WT_THREADED
|
||
|
}
|
||
|
#ifdef WT_THREADED
|
||
|
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
|
||
|
#else
|
||
|
sigprocmask(SIG_SETMASK, &old_mask, 0);
|
||
|
#endif // WT_THREADED
|
||
|
}
|
||
|
}
|
||
|
void Server::handleRequestThreaded(int serverSocket)
|
||
|
{
|
||
|
#ifdef WT_THREADED
|
||
| src/fcgi/Server.h | ||
|---|---|---|
|
int argc_;
|
||
|
char **argv_;
|
||
|
int childrenDied_;
|
||
|
volatile sig_atomic_t handleSigChld_;
|
||
|
#ifdef WT_THREADED
|
||
|
// mutex to protect access to the sessions map
|
||
|
boost::recursive_mutex mutex_;
|
||
|
#endif
|
||
|
void checkAndQueueSigChld();
|
||
|
void doHandleSigChld();
|
||
|
void spawnSharedProcess();
|
||
|
void execChild(bool debug, const std::string& extraArg);
|
||
- « Previous
- 1
- 2
- 3
- Next »