Skip to content

Commit

Permalink
Merge pull request #3 from avm/master
Browse files Browse the repository at this point in the history
Write PID file before initializing Globals.
  • Loading branch information
lmovsesjan committed Sep 24, 2012
2 parents 1a88d41 + 195877e commit 5eba4cc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
@@ -1,3 +1,9 @@
fastcgi-daemon2 (2.10-14) unstable; urgency=low

* Write PID file before initializing globals.

-- Alexander Myltsev <myltsev@yandex-team.ru> Mon, 24 Sep 2012 12:58:53 +0400

fastcgi-daemon2 (2.10-13) unstable; urgency=low

* Added correct stop for daemon with delay (by ekilimchuk@).
Expand Down
6 changes: 3 additions & 3 deletions include/details/globals.h
Expand Up @@ -36,10 +36,10 @@ class RequestsThreadPool;

class Globals : private boost::noncopyable {
public:
Globals(Config *config);
Globals(const Config *config);
virtual ~Globals();

Config* config() const;
const Config* config() const;

typedef std::map<std::string, boost::shared_ptr<RequestsThreadPool> > ThreadPoolMap;

Expand All @@ -59,7 +59,7 @@ class Globals : private boost::noncopyable {

private:
ThreadPoolMap pools_;
Config* config_;
const Config* config_;
std::auto_ptr<Loader> loader_;
std::auto_ptr<HandlerSet> handlerSet_;
std::auto_ptr<ComponentSet> componentSet_;
Expand Down
4 changes: 2 additions & 2 deletions library/globals.cpp
Expand Up @@ -18,7 +18,7 @@
namespace fastcgi
{

Globals::Globals(Config *config) : config_(config), loader_(new Loader()),
Globals::Globals(const Config *config) : config_(config), loader_(new Loader()),
handlerSet_(new HandlerSet()), componentSet_(new ComponentSet()), logger_(NULL)
{
loader_->init(config);
Expand Down Expand Up @@ -58,7 +58,7 @@ Globals::logger() const {
return logger_;
}

Config*
const Config*
Globals::config() const {
return config_;
}
Expand Down
5 changes: 2 additions & 3 deletions main/fcgi_server.cpp
Expand Up @@ -88,8 +88,6 @@ FCGIServer::start() {

status_ = LOADING;

pid(globals_->config()->asString("/fastcgi/daemon/pidfile"));

logTimes_ = globals_->config()->asInt("/fastcgi/daemon/log-times", 0);

initMonitorThread();
Expand Down Expand Up @@ -372,7 +370,8 @@ FCGIServer::monitor() {
}

void
FCGIServer::pid(const std::string &file) {
FCGIServer::writePid(const Config& config) {
const std::string& file = config.asString("/fastcgi/daemon/pidfile");
try {
std::ofstream f(file.c_str());
f.exceptions(std::ios::badbit);
Expand Down
4 changes: 2 additions & 2 deletions main/fcgi_server.h
Expand Up @@ -71,6 +71,8 @@ class FCGIServer : public Server {
public:
FCGIServer(boost::shared_ptr<Globals> globals);
virtual ~FCGIServer();

static void writePid(const Config& config);
void start();
void stop();
void join();
Expand All @@ -84,8 +86,6 @@ class FCGIServer : public Server {

std::string getServerInfo() const;

void pid(const std::string &file);

void initMonitorThread();
void initRequestCache();
void initTimeStatistics();
Expand Down
3 changes: 2 additions & 1 deletion main/main.cpp
Expand Up @@ -102,7 +102,8 @@ main(int argc, char *argv[]) {
}
}

std::auto_ptr<Config> config = Config::create(argc, argv);
boost::scoped_ptr<Config> config(Config::create(argc, argv));
FCGIServer::writePid(*config);
boost::shared_ptr<Globals> globals(new Globals(config.get()));
FCGIServer server(globals);
::server = &server;
Expand Down

0 comments on commit 5eba4cc

Please sign in to comment.