git: 27a9f282940b - main - dns/dnsmasq: backport fix for leftover child processes

From: Matthias Andree <mandree_at_FreeBSD.org>
Date: Mon, 30 Jun 2025 16:53:22 UTC
The branch main has been updated by mandree:

URL: https://cgit.FreeBSD.org/ports/commit/?id=27a9f282940b43820ba2f4d92e7e96615d814bda

commit 27a9f282940b43820ba2f4d92e7e96615d814bda
Author:     Matthias Andree <mandree@FreeBSD.org>
AuthorDate: 2025-06-30 16:50:53 +0000
Commit:     Matthias Andree <mandree@FreeBSD.org>
CommitDate: 2025-06-30 16:53:20 +0000

    dns/dnsmasq: backport fix for leftover child processes
    
    For details, see
    https://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=commitdiff;h=15841f187d2b208a6113d4e2d479d3af4275bb1c
    
    Reported by:    novel@ (Roman Bogorodskiy)
    Obtained from:  Simon Kelley via upstream Git repo
    PR:             287324
    
    dns/dnsmasq-devel already has the fix as of v2.92test14.
    
    Thanks to Roman for the report, upstream communication, and test.
---
 dns/dnsmasq/Makefile               |  2 +-
 dns/dnsmasq/files/patch-src_util.c | 73 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/dns/dnsmasq/Makefile b/dns/dnsmasq/Makefile
index 96ca52b022e8..027ec8c2b4a2 100644
--- a/dns/dnsmasq/Makefile
+++ b/dns/dnsmasq/Makefile
@@ -1,7 +1,7 @@
 PORTNAME=	dnsmasq
 DISTVERSION=	2.91
 # Leave the PORTREVISION in even if 0 to avoid accidental PORTEPOCH bumps:
-PORTREVISION=	0
+PORTREVISION=	1
 PORTEPOCH=	1
 CATEGORIES=	dns
 MASTER_SITES=	https://www.thekelleys.org.uk/dnsmasq/ \
diff --git a/dns/dnsmasq/files/patch-src_util.c b/dns/dnsmasq/files/patch-src_util.c
new file mode 100644
index 000000000000..a50483debfeb
--- /dev/null
+++ b/dns/dnsmasq/files/patch-src_util.c
@@ -0,0 +1,73 @@
+commit 15841f187d2b208a6113d4e2d479d3af4275bb1c
+Author: Simon Kelley <simon@thekelleys.org.uk>
+Date:   Sun Jun 22 23:04:36 2025 +0100
+
+    Fix issue with fast file-descriptor close on *BSD.
+    
+    This fixes a problem introduced in 8a5fe8ce6bb6c2bd81f237a0f4a2583722ffbd1c
+    
+    On BSD, fdescfs is normally mounted at /dev/fd. However
+    if it is NOT mounted, devfs creates a directory at /dev/fd
+    which contains (only) the file descriptors 0,1 and 2.
+    
+    Under these conditions, opendir() will succeed, and
+    if we proceed we will fail to close extant
+    file descriptors which should be closed.
+    
+    Check that there is a filesystem mounted at /dev/fd
+    by checking that the device changes between /dev/fd
+    and /dev. If if doesn't, fall back to the dumb path.
+    
+    Thanks to Roman Bogorodskiy for spotting the problem
+    and helping with diagnosis.
+
+--- src/util.c.orig	2025-03-14 15:09:35 UTC
++++ src/util.c
+@@ -34,6 +34,10 @@
+ #include <sys/utsname.h>
+ #endif
+ 
++#ifdef HAVE_BSD_NETWORK
++#include <libgen.h>
++#endif
++
+ /* SURF random number generator */
+ 
+ static u32 seed[32];
+@@ -831,9 +835,34 @@ void close_fds(long max_fd, int spare1, int spare2, in
+ #endif
+ 
+ #ifdef FDESCFS
+-  DIR *d;
++  DIR *d = NULL;
+   
+-  if ((d = opendir(FDESCFS)))
++#  ifdef HAVE_BSD_NETWORK
++  dev_t dirdev = 0;
++  char fdescfs[] = FDESCFS; /* string must be writable */
++  struct stat statbuf;
++
++  /* On BSD, fdescfs is normally mounted at /dev/fd. However
++     if it is NOT mounted, devfs creates a directory at /dev/fd
++     which contains (only) the file descriptors 0,1 and 2.
++
++     Under these conditions, opendir() will succeed, and
++     if we proceed we will fail to close extant
++     file descriptors which should be closed.
++     
++     Check that there is a filesystem mounted at /dev/fd
++     by checking that the device changes between /dev/fd
++     and /dev. If if doesn't, fall back to the dumb path. */
++  
++  if (stat(fdescfs, &statbuf) != -1)
++    dirdev = statbuf.st_dev;
++
++  if (stat(dirname(fdescfs), &statbuf) != -1 &&
++      dirdev != statbuf.st_dev)
++#  endif
++    d = opendir(FDESCFS);
++      
++  if (d)
+     {
+       struct dirent *de;
+