]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/service.c
service: handle services with racy daemonization gracefully
authorMichal Schmidt <mschmidt@redhat.com>
Sat, 3 Dec 2011 01:13:30 +0000 (02:13 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Sat, 3 Dec 2011 20:50:27 +0000 (21:50 +0100)
commit3a11183858af30bc9b4e9dac430dd7541deec19b
treee691cc4eb945d292ac889dcb4c820af9538415d0
parente92238567b9fc83ef77e359588d7b005ecae3d70
service: handle services with racy daemonization gracefully

There are a lot of forking daemons that do not exactly follow the
initialization steps as described in daemon(7). It is common that they
do not bother waiting in the parent process for the child to write the
PID file before exiting. The daemons' developers often do not perceive
this as a bug and they're unwilling to change.

Currently systemd warns about the missing PID file and falls back to
guessing the main PID. Being not quite deterministic, the guess can be
wrong with bad consequences. If the guessing is disabled, determinism is
achieved at the cost of losing the ability of noticing when the main
process of the service dies.

As long as it does not negatively affect properly written services,
systemd should strive for compatibility even with services with racy
daemonization. It is possible to provide determinism _and_ main process
supervision to them.

If the PID file is not there, rather than guessing and considering the
service running immediately after getting the SIGCHLD from the ExecStart
(or ExecStartPost) process, we can keep the service in the activating
state for a bit longer. We can use inotify to wait for the PID file to
appear. Only when it finally does appear and we read a valid PID from
it, we'll move the service to the running state. If the PID file never
appears, the usual timeout kicks in and the service fails.
src/service.c
src/service.h