Skip to content
Snippets Groups Projects
Commit b4388cab authored by Steven Murray's avatar Steven Murray
Browse files

Removed the sanity check of the castor::server::Daemon::daemonize() method

that is carried out when the method checks that the child has successfully
detached from the parent by making sure the return value of getppid() is 1.

I have removed the sanity check because it is time dependent.  If the child
calls getppid() before the parent has enough time to exit then the child
gets the process ID of its true parent as opposed to the process ID of the
init process.
parent 2ddb2df6
Branches
Tags
No related merge requests found
......@@ -31,6 +31,7 @@
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
//------------------------------------------------------------------------------
// constructor
......@@ -222,18 +223,6 @@ void castor::server::Daemon::daemonize() throw (castor::exception::Exception) {
castor::exception::Errnum::throwOnNegative(setsid(),
"Failed to daemonize: Failed to run daemon is a new session");
// Sanity check - At this point we are executing as the child process, and
// the parent process should be init with a process ID of 1
{
const pid_t ppid = getppid();
if (1 != ppid) {
castor::exception::Internal ex;
ex.getMessage() << "Failed to daemonize: "
" Failed to detach from parent process: getppid() returned " << ppid;
throw ex;
}
}
// Redirect standard files to /dev/null
castor::exception::Errnum::throwOnNull(
freopen("/dev/null", "r", stdin),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment