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>
Carlo Marcelo Arenas Belón committed
Sep 14, 2021 at 00:25 UTC
245670cd46c4713818b5fbca2c084ce2e19f4ed8
1 file changed
+28
-2
builtin/credential-cache.c
+28
-2
@@ -11,6 +11,32 @@
11
#define FLAG_SPAWN 0x1
12
#define FLAG_RELAY 0x2
13
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
+
40
static int send_request(const char *socket, const struct strbuf *out)
41
{
42
int got_data = 0;
@@ -28,7 +54,7 @@ static int send_request(const char *socket, const struct strbuf *out)
54
int r;
55
56
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)))
58
break;
59
if (r < 0)
60
die_errno("read error from cache daemon");
@@ -75,7 +101,7 @@ static void do_cache(const char *socket, const char *action, int timeout,
101
}
102
103
if (send_request(socket, &buf) < 0) {
78
- if (errno != ENOENT && errno != ECONNREFUSED)
104
+ if (connection_fatally_broken(errno))
105
die_errno("unable to connect to cache daemon");
106
if (flags & FLAG_SPAWN) {
107
spawn_daemon(socket);