Skip to content

Commit 245670c

Browse files
carenasgitster
authored andcommitted
credential-cache: check for windows specific errors
Connect and reset errors aren't what will be expected by POSIX but are instead compatible with the ones used by WinSock. To avoid any possibility of confusion with other systems, checks for disconnection and availability had been abstracted into helper functions that are platform specific. Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0fdcfa2 commit 245670c

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

builtin/credential-cache.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@
1111
#define FLAG_SPAWN 0x1
1212
#define FLAG_RELAY 0x2
1313

14+
#ifdef GIT_WINDOWS_NATIVE
15+
16+
static int connection_closed(int error)
17+
{
18+
return (error == EINVAL);
19+
}
20+
21+
static int connection_fatally_broken(int error)
22+
{
23+
return (error != ENOENT) && (error != ENETDOWN);
24+
}
25+
26+
#else
27+
28+
static int connection_closed(int error)
29+
{
30+
return (error == ECONNRESET);
31+
}
32+
33+
static int connection_fatally_broken(int error)
34+
{
35+
return (error != ENOENT) && (error != ECONNREFUSED);
36+
}
37+
38+
#endif
39+
1440
static int send_request(const char *socket, const struct strbuf *out)
1541
{
1642
int got_data = 0;
@@ -28,7 +54,7 @@ static int send_request(const char *socket, const struct strbuf *out)
2854
int r;
2955

3056
r = read_in_full(fd, in, sizeof(in));
31-
if (r == 0 || (r < 0 && errno == ECONNRESET))
57+
if (r == 0 || (r < 0 && connection_closed(errno)))
3258
break;
3359
if (r < 0)
3460
die_errno("read error from cache daemon");
@@ -75,7 +101,7 @@ static void do_cache(const char *socket, const char *action, int timeout,
75101
}
76102

77103
if (send_request(socket, &buf) < 0) {
78-
if (errno != ENOENT && errno != ECONNREFUSED)
104+
if (connection_fatally_broken(errno))
79105
die_errno("unable to connect to cache daemon");
80106
if (flags & FLAG_SPAWN) {
81107
spawn_daemon(socket);

0 commit comments

Comments
 (0)