nghttpx: Save pid file after daemon() call

This commit is contained in:
Tatsuhiro Tsujikawa 2013-08-10 18:55:18 +09:00
parent 3ee7ca2cdd
commit 989d613448
1 changed files with 17 additions and 17 deletions

View File

@ -232,6 +232,19 @@ void drop_privileges()
}
} // namespace
namespace {
void save_pid()
{
std::ofstream out(get_config()->pid_file, std::ios::binary);
out << getpid() << "\n";
out.close();
if(!out) {
LOG(ERROR) << "Could not save PID to file " << get_config()->pid_file;
exit(EXIT_FAILURE);
}
}
} // namespace
namespace {
int event_loop()
{
@ -258,6 +271,10 @@ int event_loop()
}
}
if(get_config()->pid_file) {
save_pid();
}
evconnlistener *evlistener6, *evlistener4;
evlistener6 = create_evlistener(listener_handler, AF_INET6);
evlistener4 = create_evlistener(listener_handler, AF_INET);
@ -291,19 +308,6 @@ int event_loop()
}
} // namespace
namespace {
void save_pid()
{
std::ofstream out(get_config()->pid_file, std::ios::binary);
out << getpid() << "\n";
out.close();
if(!out) {
LOG(ERROR) << "Could not save PID to file " << get_config()->pid_file;
exit(EXIT_FAILURE);
}
}
} // namespace
namespace {
// Returns true if regular file or symbolic link |path| exists.
bool conf_exists(const char *path)
@ -962,10 +966,6 @@ int main(int argc, char **argv)
mod_config()->use_syslog = true;
}
if(get_config()->pid_file) {
save_pid();
}
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = SIG_IGN;