In order to get the correct pid, we should daemonize before writing the pidfile

This commit is contained in:
Tamas Szabo 2014-12-19 11:44:10 +02:00
parent 00da8bf7ba
commit 6b08f63fff

View File

@ -201,13 +201,6 @@ int main(int argc, char* argv[], char* env[])
}
}
if (!pidfile.empty()) {
std::ofstream pf;
pf.open(pidfile.c_str(), std::ios::out | std::ios::trunc);
pf << getpid() << std::endl;
pf.close();
}
logger::notice()
<< "ndppd (NDP Proxy Daemon) version " NDPPD_VERSION << logger::endl
<< "Using configuration file '" << config_path << "'";
@ -226,6 +219,13 @@ int main(int argc, char* argv[], char* env[])
}
}
if (!pidfile.empty()) {
std::ofstream pf;
pf.open(pidfile.c_str(), std::ios::out | std::ios::trunc);
pf << getpid() << std::endl;
pf.close();
}
// Time stuff.
struct timeval t1, t2;