Lennart Poettering <mzerqung(a)0pointer.de> writes:
> the major linux distributions. By changing paradigm from forking
to
> non-forking daemon you can avoid all the complicated 'stop' code;
> e.g. 'start' will be
>
> | pid = fork();
> | if (pid==0) { /* ... */ execve(...); }
>
> and 'stop' be
>
> | kill(pid, SIGTERM); /* wait for timeout/sigchld */ kill(pid, SIGKILL);
This is not as simple as it might appear. Well behaving daemons don't
detach before initialization is complete.
That has the problem that heuristics like pid-files must be used to
check/modify status of daemons.
Has the problem too that only one state of "complete" is possible. But
e.g. for dhclient the state 'link was brought up' might be interesting.
This fact is implicitly used by SysV init to make sure that daemons
which depend on each other (like in "Avahi needs D-Bus")
meaning of "complete" depends on the program. E.g. waiting for
completeness of udevd can be done by 'wait-for /dev/.udev'. It is an
implementation detail of the initsystem, whether to detect it with
external tools or by adding builtin functionality. E.g. udevd init
might like like
--- system/udevd ---
need = scripts/udevd-wait
--- scripts/udevd-wait
need = daemon/udevd-daemon
exec = some-inotify-tool --wait-for-file /dev/.udev # external tool
wait_for = /dev/.udev # builtin
--- daemon/udevd-daemon
daemon = udevd
Enrico