]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Win32: detect unix socket support at runtime
authorMatthias Aßhauer <mha1993@live.de>
Wed, 3 Apr 2024 15:42:02 +0000 (15:42 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Apr 2024 21:54:28 +0000 (14:54 -0700)
Windows 10 build 17063 introduced support for unix sockets to Windows.
bb390b1 (git-compat-util: include declaration for unix sockets in
windows, 2021-09-14) introduced a way to build git with unix socket
support on Windows, but you still had to decide at build time which
Windows version the compiled executable was supposed to run on.

We can detect at runtime wether the operating system supports unix
sockets and act accordingly for all supported Windows versions.

This fixes https://github.com/git-for-windows/git/issues/3892

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/credential-cache--daemon.c
builtin/credential-cache.c
compat/mingw.c
compat/mingw.h
config.mak.uname
git-compat-util.h
t/t0301-credential-cache.sh

index 3a6a750a8eb320bb3622184843ede3d2b9884385..17f929dede30d1bfda914beccdc579bfb3a9d756 100644 (file)
@@ -294,6 +294,8 @@ int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, options, usage, 0);
        socket_path = argv[0];
 
+       if (!have_unix_sockets())
+               die(_("credential-cache--daemon unavailable; no unix socket support"));
        if (!socket_path)
                usage_with_options(usage, options);
 
index bba96d4ffd6f198adb186aaba0c853e34a93dd11..bef120b537533ca7c085d990da941817697f07dc 100644 (file)
@@ -149,6 +149,9 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix)
                usage_with_options(usage, options);
        op = argv[0];
 
+       if (!have_unix_sockets())
+               die(_("credential-cache unavailable; no unix socket support"));
+
        if (!socket_path)
                socket_path = get_socket_path();
        if (!socket_path)
index 320fb99a90e1db6006135e9798f7300f6fa29798..4876344b5b8009794eb9cefcbff342b1cc4f90a2 100644 (file)
@@ -3158,3 +3158,22 @@ int uname(struct utsname *buf)
                  "%u", (v >> 16) & 0x7fff);
        return 0;
 }
+
+int mingw_have_unix_sockets(void)
+{
+       SC_HANDLE scm, srvc;
+       SERVICE_STATUS_PROCESS status;
+       DWORD bytes;
+       int ret = 0;
+       scm = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
+       if (scm) {
+               srvc = OpenServiceA(scm, "afunix", SERVICE_QUERY_STATUS);
+               if (srvc) {
+                       if(QueryServiceStatusEx(srvc, SC_STATUS_PROCESS_INFO, (LPBYTE)&status, sizeof(SERVICE_STATUS_PROCESS), &bytes))
+                               ret = status.dwCurrentState == SERVICE_RUNNING;
+                       CloseServiceHandle(srvc);
+               }
+               CloseServiceHandle(scm);
+       }
+       return ret;
+}
index 6aec50e4124e145d6d43f584418288d3fc29f481..27b61284f46be61ec7baefa2e19328d58397d1f9 100644 (file)
@@ -631,3 +631,9 @@ void open_in_gdb(void);
  * Used by Pthread API implementation for Windows
  */
 int err_win_to_posix(DWORD winerr);
+
+#ifndef NO_UNIX_SOCKETS
+int mingw_have_unix_sockets(void);
+#undef have_unix_sockets
+#define have_unix_sockets mingw_have_unix_sockets
+#endif
index d0dcca2ec554cddf61447215357a7e15877b0aca..fcf3e2d785a04d765a495b67e24515755ef81c8e 100644 (file)
@@ -447,7 +447,6 @@ ifeq ($(uname_S),Windows)
        NO_POLL = YesPlease
        NO_SYMLINK_HEAD = YesPlease
        NO_IPV6 = YesPlease
-       NO_UNIX_SOCKETS = YesPlease
        NO_SETENV = YesPlease
        NO_STRCASESTR = YesPlease
        NO_STRLCPY = YesPlease
@@ -661,7 +660,6 @@ ifeq ($(uname_S),MINGW)
        NO_LIBGEN_H = YesPlease
        NO_POLL = YesPlease
        NO_SYMLINK_HEAD = YesPlease
-       NO_UNIX_SOCKETS = YesPlease
        NO_SETENV = YesPlease
        NO_STRCASESTR = YesPlease
        NO_STRLCPY = YesPlease
index 7c2a6538e5afea607f3d9a1c09cc6aea5539d8de..044f87454a291b116a436276ac812ac6fd5983e9 100644 (file)
@@ -218,6 +218,18 @@ struct strbuf;
 #define GIT_WINDOWS_NATIVE
 #endif
 
+#if defined(NO_UNIX_SOCKETS) || !defined(GIT_WINDOWS_NATIVE)
+static inline int _have_unix_sockets(void)
+{
+#if defined(NO_UNIX_SOCKETS)
+       return 0;
+#else
+       return 1;
+#endif
+}
+#define have_unix_sockets _have_unix_sockets
+#endif
+
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
index 8300faadea9a76f19e3d2c82f5ff600f38bfe18f..f2c146fa2a1dd79fd68bd0c71f836667d5c55cf3 100755 (executable)
@@ -8,6 +8,14 @@ test -z "$NO_UNIX_SOCKETS" || {
        skip_all='skipping credential-cache tests, unix sockets not available'
        test_done
 }
+if test_have_prereq MINGW
+then
+       service_running=$(sc query afunix | grep "4  RUNNING")
+       test -z "$service_running" || {
+               skip_all='skipping credential-cache tests, unix sockets not available'
+               test_done
+       }
+fi
 
 uname_s=$(uname -s)
 case $uname_s in