[Dnsmasq-discuss] Leftover helper process after main process exit on FreeBSD
Geert Stappers
stappers at stappers.nl
Sun Jun 15 07:55:25 UTC 2025
On Fri, Jun 13, 2025 at 02:30:47PM +0200, Roman Bogorodskiy wrote:
> Hi,
>
> I've noticed an issue on FreeBSD which I can reproduce this way:
>
> # ./src/dnsmasq --interface=bridge0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
> $ ps aux|grep dnsm
> nobody 12741 0,0 0,0 14500 3128 - I 13:43 0:00,00 ./src/dnsmasq --interface=bridge0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
> root 12742 0,0 0,0 14500 3008 - I 13:43 0:00,00 ./src/dnsmasq --interface=bridge0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
> novel 12763 0,0 0,0 14192 2588 1 S+ 13:44 0:00,00 grep dnsm
> $
I mis parent PID in that output.
|$ ps aux | head -n 1
|USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
|$
> # kill 12741
Not sure, but assuming "parent"
> $ ps aux|grep dns
> root 12742 0,0 0,0 14500 3008 - I 13:43 0:00,00 ./src/dnsmasq --interface=bridge0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
> novel 12785 0,0 0,0 14192 2560 1 S+ 13:45 0:00,00 grep dns
> $
>
> There is a leftover process.
Which is strange.
Anyway: good that it is reported
> When I attach to it using gdb I see:
>
> (gdb) attach 12742
> Attaching to program: /usr/home/novel/code/dnsmasq/src/dnsmasq, process 12742
> Reading symbols from /lib/libc.so.7...
> Reading symbols from /usr/lib/debug//lib/libc.so.7.debug...
> Reading symbols from /lib/libsys.so.7...
> Reading symbols from /usr/lib/debug//lib/libsys.so.7.debug...
> Reading symbols from /libexec/ld-elf.so.1...
> Reading symbols from /usr/lib/debug//libexec/ld-elf.so.1.debug...
> _read () at _read.S:4
> 4 PSEUDO(read)
> (gdb) bt
> #0 _read () at _read.S:4
> #1 0x00000000002208a1 in read_write (fd=19, packet=0x8204deea8 "\260\236\212\"\b", size=112, rw=1) at util.c:783
> #2 0x000000000024e6ca in create_helper (event_fd=16, err_fd=18, uid=0, gid=0, max_fd=1877346) at helper.c:199
> #3 0x000000000023b1f1 in main (argc=5, argv=0x8204df170) at dnsmasq.c:743
> (gdb)
>
> So it looks like it's stuck reading from pipefd[0]:
>
> (gdb) fr 2
> #2 0x000000000024e6ca in create_helper (event_fd=16, err_fd=18, uid=0, gid=0, max_fd=1877346) at helper.c:199
> 199 if (!read_write(pipefd[0], (unsigned char *)&data, sizeof(data), RW_READ))
> (gdb)
>
> It also looks like both fd's are open in the helper side:
>
> (gdb) p pipefd
> $12 = {19, 20}
> (gdb)
>
> (gdb) call fcntl(20, 1)
> $13 = 0
> (gdb)
>
> Now if I close(20):
>
> (gdb) call close(20)
> $14 = 0
> (gdb) c
> Continuing.
> [Inferior 1 (process 12742) exited normally]
> (gdb)
>
>
> So the following change fixed this for me:
>
> --- a/src/helper.c
> +++ b/src/helper.c
> @@ -96,6 +96,8 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
> close(pipefd[0]); /* close reader side */
> return pipefd[1];
> }
> + else
> + close(pipefd[1]);
>
> /* ignore SIGTERM and SIGINT, so that we can clean up when the main process gets hit
> and SIGALRM so that we can use sleep() */
The patch has been seen. ( And with this email got the patch a "somebody noticed" :-)
> FWIW, that's happening on FreeBSD 15.0-CURRENT amd64 and latest master
> of dnsmasq.
>
> However, I'm not sure that these reproduction steps are 100% sufficient.
> I wasn't able to reproduce that on another FreeBSD 14.2-RELEASE amd64
> system with Dnsmasq version 2.91.
My attempt to reproduce
|stappers at alpaca:~/src/dnsmasq
|$ sudo ip link add dummy0 type dummy
|stappers at alpaca:~/src/dnsmasq
|$ sudo ip address add 192.168.127.1/24 dev dummy0
|stappers at alpaca:~/src/dnsmasq
|$ sudo src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|
|dnsmasq: failed to bind DHCP server socket: Address already in use
|stappers at alpaca:~/src/dnsmasq
|$
Yeah, I have dnsmasq running as DHCP server.
|stappers at alpaca:~/src/dnsmasq
|$ sudo systemctl stop dnsmasq
|stappers at alpaca:~/src/dnsmasq
|$ sudo src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|stappers at alpaca:~/src/dnsmasq
|$ ps -ef | grep dnsmasq
|nobody 24320 1 0 09:40 ? 00:00:00 src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|root 24321 24320 0 09:40 ? 00:00:00 src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|stappers 24330 5970 0 09:40 pts/6 00:00:00 grep dnsmasq
|stappers at alpaca:~/src/dnsmasq
|$ sudo kill 24320
|stappers at alpaca:~/src/dnsmasq
|$ ps -ef | grep dnsmasq
|stappers 24334 5970 0 09:41 pts/6 00:00:00 grep dnsmasq
|stappers at alpaca:~/src/dnsmasq
|$ sudo src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|stappers at alpaca:~/src/dnsmasq
|$ ps -ef | grep dnsmasq
|nobody 24338 1 0 09:42 ? 00:00:00 src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|root 24339 24338 0 09:42 ? 00:00:00 src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|stappers 24347 5970 0 09:42 pts/6 00:00:00 grep dnsmasq
|stappers at alpaca:~/src/dnsmasq
|$ sleep 6
|stappers at alpaca:~/src/dnsmasq
|$ ps -ef | grep dnsmasq
|nobody 24338 1 0 09:42 ? 00:00:00 src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|root 24339 24338 0 09:42 ? 00:00:00 src/dnsmasq --interface=dummy0 --except-interface=lo0 --dhcp-range=192.168.127.2,192.168.127.254,255.255.255.0 --dhcp-script=/usr/bin/true
|stappers 24352 5970 0 09:42 pts/6 00:00:00 grep dnsmasq
|stappers at alpaca:~/src/dnsmasq
|$ sudo kill 24338
|stappers at alpaca:~/src/dnsmasq
|$ ps -ef | grep dnsmasq
|stappers 24357 5970 0 09:43 pts/6 00:00:00 grep dnsmasq
|stappers at alpaca:~/src/dnsmasq
|$
So on my setup, Debian, no leftover process.
> Thanks,
> Roman
Thank you!
Groeten
Geert Stappers
--
Silence is hard to parse
More information about the Dnsmasq-discuss
mailing list