[syslog-ng] cvs tree
Balazs Scheidler
bazsi@balabit.hu
Wed, 9 Jun 1999 10:03:47 +0200
> > parent:
> > wait until term signal arrives
> >
> > child:
> > initialize config
> > send SIGTERM to parent
>
> Maybe I'm missing something, but why don't you initialize the config
> *before* forking? Then all the parent needs to do is exit.... (I assume you
> set the parent's SIGCHLD handler to ignore and that the child removes itself
> from the parent's process group.... though even that you can do before
> forking.)
Because initialization may mean something that cannot be inherited by
fork(), for instance door support may create threads etc.
I background the child using the following function:
void go_background()
{
pid_t pid;
pid = fork();
if (pid == 0) {
return;
}
else if (pid == -1) {
werror("Cannot fork(), (%z)\n", strerror(errno));
exit(1);
}
signal(SIGTERM, sig_term);
while (sigtermrecvd == 0)
pause();
exit(0);
}
The child then initializes config and calls the following code:
if (do_fork) {
set_error_internal();
close(0);
close(1);
close(2);
setsid();
kill(getppid(), SIGTERM);
}
I don't understand everything about process groups, process leaders and
such, but this should work IMHO. If you have a better idea, please don't
hesitate to tell me.
--
Bazsi
PGP key: http://www.balabit.hu/pgpkey.txt, or finger bazsi@balabit.hu