[Dnsmasq-discuss] Forked processes and supervise

clemens fischer ino-news at spotteswoode.dnsalias.org
Sat Jun 12 22:04:20 BST 2010


Simon Kelley wrote:

> clemens fischer wrote:
>
>>   pstree -Aa ->
>>   ...
>>   `-runsv,2290 dhcp-server
>>       |-dnsmasq,1880,nobody -C /etc/dnsmasq.conf -u nobody -g nobody ...
>>       |   `-dnsmasq,1944,root -C /etc/dnsmasq.conf -u nobody -g nobody ...
>>       `-svlogd,30206,log -r . ./log/ ./notify/
>>   ...
> 
> First, all the circumstances where dnsmasq forks itself:
> 
> 1) to handle TCP connections. Each TCP connection gets a new process
> (there are limits on the number and lifetime of these.)
> 
> 2) to call the DHCP script. If dnsmasq has a dhcp-script argument then
> it will always have a child process: this process retains root
> permissions even when the main process drops them, so that the script
> can be run as root. Clearly when the script needs to be run this process
> fork()s again and then exec()s the script.
> 
> In your case the child must be the script-runner, since its uid is root.
> If it was a TCP connection handler it would have uid nobody. This
> doesn't quite fit your description of what is going on though, since
> that process will be there from very early on in dnsmasq initialisation,
> and not "suddenly appear". What is also slightly strange is that the
> child has a rather different pid to the parent. normally they are
> consecutive or nearly so as they are created very closely in time.

Thanks!  I was a bit suspicious of a few lines in the start script
before the real exec.  If any of them fork themselves, as happens all
the time when not using only shell builtins, there's a race.  Should the
supervisor detect dnsmasq's exit it will restart its handler taking care
to keep the logging pipe open.  If the handler-script runs into trouble,
before that exec into dnsmasq, the supervisor sees the shell as its
precious child instead of dnsmasq.

I will try another route by going to the "exec dnsmasq ..." right away.
When dnsmasq cannot start on its interface(s), it will complain and die.
I'll let the logger filter out these specific complaints and it will all
work and I'll be happy again.  I hope.


clemens




More information about the Dnsmasq-discuss mailing list