Subject: [PATCH v6 06/10] fsmonitor: deduplicate settings logic for Unix platforms

From: "Paul Tarjan via GitGitGadget" <[email-masked]>
Date: Wed, 25 Feb 2026 20:17:12 +0000

From: Paul Tarjan <[email-masked]>

The fsmonitor settings logic for checking Unix domain socket
compatibility is nearly identical between macOS and Linux.  Both check
whether the IPC socket directory resides on a remote filesystem or a
filesystem that does not support Unix domain sockets (NTFS, FAT32, etc).

Merge the two implementations into a single fsm-settings-unix.c shared
by both platforms.  The unified version uses the safer xstrdup() +
dirname() approach from the macOS implementation (avoiding strbuf
mutation with dirname()) and includes the "vfat" filesystem check.

Update Makefile, meson.build, and CMakeLists.txt to use the new shared
file for non-Windows platforms.

Signed-off-by: Paul Tarjan <[email-masked]>
---
 Makefile                                      |  6 ++++-
 ...-settings-darwin.c => fsm-settings-unix.c} | 24 ++++++++++++-------
 contrib/buildsystems/CMakeLists.txt           |  2 +-
 meson.build                                   | 11 ++++++---
 4 files changed, 29 insertions(+), 14 deletions(-)
 rename compat/fsmonitor/{fsm-settings-darwin.c => fsm-settings-unix.c} (82%)

diff --git a/Makefile b/Makefile
index 2157bbf173..febdaeb42c 100644
--- a/Makefile
+++ b/Makefile
@@ -2374,7 +2374,11 @@ endif
 
 ifdef FSMONITOR_OS_SETTINGS
 	COMPAT_CFLAGS += -DHAVE_FSMONITOR_OS_SETTINGS
-	COMPAT_OBJS += compat/fsmonitor/fsm-settings-$(FSMONITOR_OS_SETTINGS).o
+ifeq ($(FSMONITOR_OS_SETTINGS),win32)
+	COMPAT_OBJS += compat/fsmonitor/fsm-settings-win32.o
+else
+	COMPAT_OBJS += compat/fsmonitor/fsm-settings-unix.o
+endif
 	COMPAT_OBJS += compat/fsmonitor/fsm-path-utils-$(FSMONITOR_OS_SETTINGS).o
 endif
 
diff --git a/compat/fsmonitor/fsm-settings-darwin.c b/compat/fsmonitor/fsm-settings-unix.c
similarity index 82%
rename from compat/fsmonitor/fsm-settings-darwin.c
rename to compat/fsmonitor/fsm-settings-unix.c
index a382590635..27d89207af 100644
--- a/compat/fsmonitor/fsm-settings-darwin.c
+++ b/compat/fsmonitor/fsm-settings-unix.c
@@ -5,7 +5,7 @@
 #include "fsmonitor-settings.h"
 #include "fsmonitor-path-utils.h"
 
- /*
+/*
  * For the builtin FSMonitor, we create the Unix domain socket for the
  * IPC in the .git directory.  If the working directory is remote,
  * then the socket will be created on the remote file system.  This
@@ -22,25 +22,31 @@
  * The builtin FSMonitor uses a Unix domain socket in the .git
  * directory for IPC.  These Windows drive formats do not support
  * Unix domain sockets, so mark them as incompatible for the daemon.
- *
  */
 static enum fsmonitor_reason check_uds_volume(struct repository *r)
 {
 	struct fs_info fs;
 	const char *ipc_path = fsmonitor_ipc__get_path(r);
-	struct strbuf path = STRBUF_INIT;
-	strbuf_add(&path, ipc_path, strlen(ipc_path));
+	char *path;
+	char *dir;
+
+	/*
+	 * Create a copy for dirname() since it may modify its argument.
+	 */
+	path = xstrdup(ipc_path);
+	dir = dirname(path);
 
-	if (fsmonitor__get_fs_info(dirname(path.buf), &fs) == -1) {
-		strbuf_release(&path);
+	if (fsmonitor__get_fs_info(dir, &fs) == -1) {
+		free(path);
 		return FSMONITOR_REASON_ERROR;
 	}
 
-	strbuf_release(&path);
+	free(path);
 
 	if (fs.is_remote ||
-		!strcmp(fs.typename, "msdos") ||
-		!strcmp(fs.typename, "ntfs")) {
+	    !strcmp(fs.typename, "msdos") ||
+	    !strcmp(fs.typename, "ntfs") ||
+	    !strcmp(fs.typename, "vfat")) {
 		free(fs.typename);
 		return FSMONITOR_REASON_NOSOCKETS;
 	}
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index 32ef6ebe1b..0eba0c2c98 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -307,7 +307,7 @@ if(SUPPORTS_SIMPLE_IPC)
 		list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c)
 
 		add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
-		list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c)
+		list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-unix.c)
 	endif()
 endif()
 
diff --git a/meson.build b/meson.build
index 8de795f9d4..e02f9708da 100644
--- a/meson.build
+++ b/meson.build
@@ -1334,13 +1334,18 @@ if fsmonitor_backend != ''
     'compat/fsmonitor/fsm-health-' + fsmonitor_backend + '.c',
     'compat/fsmonitor/fsm-listen-' + fsmonitor_backend + '.c',
     'compat/fsmonitor/fsm-path-utils-' + fsmonitor_backend + '.c',
-    'compat/fsmonitor/fsm-settings-' + fsmonitor_backend + '.c',
   ]
 
   if fsmonitor_backend == 'win32'
-    libgit_sources += 'compat/fsmonitor/fsm-ipc-win32.c'
+    libgit_sources += [
+      'compat/fsmonitor/fsm-ipc-win32.c',
+      'compat/fsmonitor/fsm-settings-win32.c',
+    ]
   else
-    libgit_sources += 'compat/fsmonitor/fsm-ipc-unix.c'
+    libgit_sources += [
+      'compat/fsmonitor/fsm-ipc-unix.c',
+      'compat/fsmonitor/fsm-settings-unix.c',
+    ]
   endif
 endif
 build_options_config.set_quoted('FSMONITOR_DAEMON_BACKEND', fsmonitor_backend)
-- 
gitgitgadget