]> git.ipfire.org Git - thirdparty/git.git/commitdiff
credential-cache: check for windows specific errors
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>
Tue, 14 Sep 2021 07:25:59 +0000 (00:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Sep 2021 16:30:54 +0000 (09:30 -0700)
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>
builtin/credential-cache.c

index e8a74157471948c5b94f897b7cd1b20d2f0c17c2..78c02ad53192323e8237a3b0555b4f4f1b4dbceb 100644 (file)
 #define FLAG_SPAWN 0x1
 #define FLAG_RELAY 0x2
 
+#ifdef GIT_WINDOWS_NATIVE
+
+static int connection_closed(int error)
+{
+       return (error == EINVAL);
+}
+
+static int connection_fatally_broken(int error)
+{
+       return (error != ENOENT) && (error != ENETDOWN);
+}
+
+#else
+
+static int connection_closed(int error)
+{
+       return (error == ECONNRESET);
+}
+
+static int connection_fatally_broken(int error)
+{
+       return (error != ENOENT) && (error != ECONNREFUSED);
+}
+
+#endif
+
 static int send_request(const char *socket, const struct strbuf *out)
 {
        int got_data = 0;
@@ -28,7 +54,7 @@ static int send_request(const char *socket, const struct strbuf *out)
                int r;
 
                r = read_in_full(fd, in, sizeof(in));
-               if (r == 0 || (r < 0 && errno == ECONNRESET))
+               if (r == 0 || (r < 0 && connection_closed(errno)))
                        break;
                if (r < 0)
                        die_errno("read error from cache daemon");
@@ -75,7 +101,7 @@ static void do_cache(const char *socket, const char *action, int timeout,
        }
 
        if (send_request(socket, &buf) < 0) {
-               if (errno != ENOENT && errno != ECONNREFUSED)
+               if (connection_fatally_broken(errno))
                        die_errno("unable to connect to cache daemon");
                if (flags & FLAG_SPAWN) {
                        spawn_daemon(socket);