Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Detect unix socket support at runtime #4762

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions builtin/credential-cache--daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions builtin/credential-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -4215,3 +4215,22 @@ int file_attr_to_st_mode (DWORD attr, DWORD tag, const char *path)
fMode |= S_IWRITE;
return fMode;
}

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;
}
6 changes: 6 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,9 @@ int err_win_to_posix(DWORD winerr);
* Check current process is inside Windows Container.
*/
int is_inside_windows_container(void);

#ifndef NO_UNIX_SOCKETS
int mingw_have_unix_sockets(void);
#undef have_unix_sockets
#define have_unix_sockets mingw_have_unix_sockets
#endif
2 changes: 0 additions & 2 deletions config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -652,7 +651,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
Expand Down
12 changes: 12 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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>
Expand Down
8 changes: 8 additions & 0 deletions t/t0301-credential-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down