Skip to content

Commit 2406bf5

Browse files
rimrulgitster
authored andcommitted
Win32: detect unix socket support at runtime
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 #3892 Signed-off-by: Matthias Aßhauer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c75fd8d commit 2406bf5

7 files changed

+50
-2
lines changed

builtin/credential-cache--daemon.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ int cmd_credential_cache_daemon(int argc, const char **argv, const char *prefix)
294294
argc = parse_options(argc, argv, prefix, options, usage, 0);
295295
socket_path = argv[0];
296296

297+
if (!have_unix_sockets())
298+
die(_("credential-cache--daemon unavailable; no unix socket support"));
297299
if (!socket_path)
298300
usage_with_options(usage, options);
299301

builtin/credential-cache.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ int cmd_credential_cache(int argc, const char **argv, const char *prefix)
149149
usage_with_options(usage, options);
150150
op = argv[0];
151151

152+
if (!have_unix_sockets())
153+
die(_("credential-cache unavailable; no unix socket support"));
154+
152155
if (!socket_path)
153156
socket_path = get_socket_path();
154157
if (!socket_path)

compat/mingw.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,3 +3158,22 @@ int uname(struct utsname *buf)
31583158
"%u", (v >> 16) & 0x7fff);
31593159
return 0;
31603160
}
3161+
3162+
int mingw_have_unix_sockets(void)
3163+
{
3164+
SC_HANDLE scm, srvc;
3165+
SERVICE_STATUS_PROCESS status;
3166+
DWORD bytes;
3167+
int ret = 0;
3168+
scm = OpenSCManagerA(NULL, NULL, SC_MANAGER_CONNECT);
3169+
if (scm) {
3170+
srvc = OpenServiceA(scm, "afunix", SERVICE_QUERY_STATUS);
3171+
if (srvc) {
3172+
if(QueryServiceStatusEx(srvc, SC_STATUS_PROCESS_INFO, (LPBYTE)&status, sizeof(SERVICE_STATUS_PROCESS), &bytes))
3173+
ret = status.dwCurrentState == SERVICE_RUNNING;
3174+
CloseServiceHandle(srvc);
3175+
}
3176+
CloseServiceHandle(scm);
3177+
}
3178+
return ret;
3179+
}

compat/mingw.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,9 @@ void open_in_gdb(void);
631631
* Used by Pthread API implementation for Windows
632632
*/
633633
int err_win_to_posix(DWORD winerr);
634+
635+
#ifndef NO_UNIX_SOCKETS
636+
int mingw_have_unix_sockets(void);
637+
#undef have_unix_sockets
638+
#define have_unix_sockets mingw_have_unix_sockets
639+
#endif

config.mak.uname

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ ifeq ($(uname_S),Windows)
447447
NO_POLL = YesPlease
448448
NO_SYMLINK_HEAD = YesPlease
449449
NO_IPV6 = YesPlease
450-
NO_UNIX_SOCKETS = YesPlease
451450
NO_SETENV = YesPlease
452451
NO_STRCASESTR = YesPlease
453452
NO_STRLCPY = YesPlease
@@ -661,7 +660,6 @@ ifeq ($(uname_S),MINGW)
661660
NO_LIBGEN_H = YesPlease
662661
NO_POLL = YesPlease
663662
NO_SYMLINK_HEAD = YesPlease
664-
NO_UNIX_SOCKETS = YesPlease
665663
NO_SETENV = YesPlease
666664
NO_STRCASESTR = YesPlease
667665
NO_STRLCPY = YesPlease

git-compat-util.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ struct strbuf;
218218
#define GIT_WINDOWS_NATIVE
219219
#endif
220220

221+
#if defined(NO_UNIX_SOCKETS) || !defined(GIT_WINDOWS_NATIVE)
222+
static inline int _have_unix_sockets(void)
223+
{
224+
#if defined(NO_UNIX_SOCKETS)
225+
return 0;
226+
#else
227+
return 1;
228+
#endif
229+
}
230+
#define have_unix_sockets _have_unix_sockets
231+
#endif
232+
221233
#include <unistd.h>
222234
#include <stdio.h>
223235
#include <sys/stat.h>

t/t0301-credential-cache.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ test -z "$NO_UNIX_SOCKETS" || {
88
skip_all='skipping credential-cache tests, unix sockets not available'
99
test_done
1010
}
11+
if test_have_prereq MINGW
12+
then
13+
service_running=$(sc query afunix | grep "4 RUNNING")
14+
test -z "$service_running" || {
15+
skip_all='skipping credential-cache tests, unix sockets not available'
16+
test_done
17+
}
18+
fi
1119

1220
uname_s=$(uname -s)
1321
case $uname_s in

0 commit comments

Comments
 (0)