use a second fork to avoid a terminal

after the setsid() we are the process leader. And as a process leader we
are able to open a new terminal, even if we currently don't own one. So
we do another fork and do not call setsid() and not become a process
leader to avoid that.
This commit is contained in:
Christian Kruse
2014-01-21 15:51:33 +01:00
parent b36dbf61fe
commit 3978ead184

View File

@@ -230,6 +230,24 @@ main(int argc, char **argv)
log_err("Error in setsid(): %s\n", strerror(errno));
exit(ERR_SYS_FAILURE);
}
/* ensure that we are no longer able to open a terminal */
pid = fork();
if(pid == -1) /* error case */
{
log_err("Error in fork(): %s\n", strerror(errno));
exit(ERR_SYS_FAILURE);
break;
}
if (pid != 0) /* parent process */
{
exit(0);
}
/* a child just flows along */
break;
default: /* parent process */