From d7c68559188410f61a2f6161527fbf75c9e5dccb Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Mon, 12 Aug 2013 20:19:51 +0300 Subject: [PATCH] Remove problems with fishd under Cygwin. Yes, it's an awful hack, but IPC support (and fork support as well - even FAQ mentions that, and suggests "restarting process" to solve the problem (http://cygwin.com/faq/faq.html#faq.using.fixing-fork-failures), but let's ignore that for now) is simply broken in Cygwin. Having to try to do exactly same thing in Cygwin, just so perhaps it will work is a completely normal thing (not). I love Windows. --- fishd.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fishd.cpp b/fishd.cpp index e5edc3da5..edb79c22f 100644 --- a/fishd.cpp +++ b/fishd.cpp @@ -529,6 +529,14 @@ static bool acquire_socket_lock(const std::string &sock_name, std::string *out_l */ static int get_socket(void) { + // Cygwin has random problems involving sockets. When using Cygwin, + // allow 20 attempts at making socket correctly. +#ifdef __CYGWIN__ + int attempts = 0; +repeat: + attempts += 1; +#endif + int s, len, doexit = 0; int exitcode = EXIT_FAILURE; struct sockaddr_un local; @@ -599,6 +607,10 @@ unlock: if (doexit) { + // If Cygwin, only allow normal quit when made lots of attempts. +#ifdef __CYGWIN__ + if (exitcode && attempts < 20) goto repeat; +#endif exit_without_destructors(exitcode); }