[systemd-devel] possible bug guessing mainpid when service type=forking..
Lennart Poettering
lennart at poettering.net
Tue Jun 21 10:25:57 PDT 2011
On Tue, 21.06.11 18:50, Marius Tolzmann (tolzmann at molgen.mpg.de) wrote:
> > but it should be doing:
> >
> > fork() ------------> fork() --> write_pid_file()
> > wait_for_notify() exit() notify_grandparent()
> > exit() run_main_loop()
> > ...
>
> the run-in-foreground patch works fine.. and as far as i understood
> Type=forking is just good for compatibility and daemons should not fork
> away anymore!?
Yes, daemons which do not double-fork are definitely much nicer than
those which do.
> > i.e. the main process should not exit before it hasn't ensure that the
> > PID file of the daemon process has been written. Otherwise any usage of
> > the PID file is necessarily racy.
>
> but it doesn't work without setting PIDFile= either - so the PID itself
> is racy, too.
Hmm?
There's one important distinction here: daemons which return in the
parent before having made sure that the PID file is fully written are
simply broken. But services which run more than one process by default
are not broken but perfectly valid.
>
> >> BTW a patch for ypbind-mt adding a -foreground commandline switch will
> >> be sent to the maintainers soon..
> >
> > Nice, this is good to hear, Type=simple is definitely the ncier solution.
>
> may be it could be mentioned in the manpage where Type=forking is
> explained that there could be a race if the daemon is forking twice or
> if it behaves odd in another way.. - GuessMainPID= already states that
> it may not work reliable..
Well, GuessMainPID= does not work properly for some correctly written
daemon (i.e. those which run more than one process continously). But the
PID file reading will only break for broken services. We generally do
not add extra comments regarding bugs in software to the
documentation. We instead prefer if those bug are fixed. Which is why the
comment regarding GuessMainPID='s reliability is there but no comment
regarding handling of daemons incorrectly writing PID files.
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the systemd-devel
mailing list