]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2199. [bug] win32: don't call WSAStartup() while loading dlls.
authorMark Andrews <marka@isc.org>
Mon, 18 Jun 2007 03:30:31 +0000 (03:30 +0000)
committerMark Andrews <marka@isc.org>
Mon, 18 Jun 2007 03:30:31 +0000 (03:30 +0000)
                        [RT #16911]

14 files changed:
CHANGES
lib/dns/win32/DLLMain.c
lib/isc/win32/DLLMain.c
lib/isc/win32/interfaceiter.c
lib/isc/win32/net.c
lib/isc/win32/socket.c
lib/isccc/win32/DLLMain.c
lib/isccfg/win32/DLLMain.c
lib/lwres/context.c
lib/lwres/getipnode.c
lib/lwres/win32/DLLMain.c
lib/lwres/win32/include/lwres/platform.h
lib/lwres/win32/liblwres.dsp
lib/lwres/win32/liblwres.mak

diff --git a/CHANGES b/CHANGES
index 2db02df30ceeb917cc6a407500c752841417314d..724c1164050518e6cd87bdec4b2829f692dcf09b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+2199.  [bug]           win32: don't call WSAStartup() while loading dlls.
+                       [RT #16911]
+
 2198.  [bug]           win32: RegCloseKey() could be called when
                        RegOpenKeyEx() failed. [RT #16911]
 
index aa05e28f0f308f51281fdca1c300616f6585d5da..aed78c7038c61d3720e5fcf94f36e828b5b58810 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.3.2.1 2004/03/09 06:11:43 marka Exp $ */
+/* $Id: DLLMain.c,v 1.3.2.2 2007/06/18 03:30:31 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
 /*
  * Called when we enter the DLL
  */
index 1009912eeeec407eae7c91584889122e8d11db2f..6767cef5b0a77cf52a07dcf73088852b3342bafb 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.3.2.2 2004/03/09 06:12:16 marka Exp $ */
+/* $Id: DLLMain.c,v 1.3.2.3 2007/06/18 03:30:31 marka Exp $ */
 
 #include <windows.h>
 #include <stdio.h>
 
-BOOL InitSockets(void);
 /*
  * Called when we enter the DLL
  */
@@ -35,8 +33,6 @@ __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL,
         * initialization or a call to LoadLibrary. 
         */
        case DLL_PROCESS_ATTACH: 
-               if (!InitSockets())
-                       return (FALSE);
                break; 
  
        /* The attached process creates a new thread.  */
index 550ba71922f27896613b11bdbda60e68e0b31519..e7c8017ceb936c555106326a8c86e2efb1981740 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: interfaceiter.c,v 1.4.2.1 2004/03/09 06:12:18 marka Exp $ */
+/* $Id: interfaceiter.c,v 1.4.2.2 2007/06/18 03:30:31 marka Exp $ */
 
 /*
  * Note that this code will need to be revisited to support IPv6 Interfaces.
@@ -39,6 +39,8 @@
 #include <isc/util.h>
 #include "errno2result.h"
 
+void InitSockets(void);
+
 /* Common utility functions */
 
 /*
@@ -114,6 +116,8 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
        if (iter == NULL)
                return (ISC_R_NOMEMORY);
 
+       InitSockets();
+
        iter->mctx = mctx;
        iter->buf = NULL;
 
index 6abe5cfb12f2ed54b724f7b36f71d8c8108d02aa..b58a3837b8e08dddac3d89e773a121cc7b860ff0 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: net.c,v 1.3.2.3 2004/03/09 06:12:18 marka Exp $ */
+/* $Id: net.c,v 1.3.2.4 2007/06/18 03:30:31 marka Exp $ */
 
 #include <config.h>
 
@@ -37,6 +37,8 @@ static isc_once_t     once = ISC_ONCE_INIT;
 static isc_result_t    ipv4_result = ISC_R_NOTFOUND;
 static isc_result_t    ipv6_result = ISC_R_NOTFOUND;
 
+void InitSockets(void);
+
 static isc_result_t
 try_proto(int domain) {
        SOCKET s;
@@ -112,6 +114,7 @@ try_proto(int domain) {
 
 static void
 initialize_action(void) {
+       InitSockets();
        ipv4_result = try_proto(PF_INET);
 #ifdef ISC_PLATFORM_HAVEIPV6
 #ifdef WANT_IPV6
index 2068c4c7c954166cc5faa4184f3a2bd184cb0788..72f7a7964f45617868c54a8c999982c382cd318e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.5.2.32 2007/02/01 23:55:18 marka Exp $ */
+/* $Id: socket.c,v 1.5.2.33 2007/06/18 03:30:31 marka Exp $ */
 
 /* This code has been rewritten to take advantage of Windows Sockets
  * I/O Completion Ports and Events. I/O Completion Ports is ONLY
@@ -77,6 +77,7 @@
 #include <isc/msgs.h>
 #include <isc/mutex.h>
 #include <isc/net.h>
+#include <isc/once.h>
 #include <isc/os.h>
 #include <isc/platform.h>
 #include <isc/print.h>
@@ -899,10 +900,11 @@ socket_close(isc_socket_t *sock) {
        }
 }
 
-/*
- * Initialize socket services
- */
-BOOL InitSockets() {
+static isc_once_t initialise_once = ISC_ONCE_INIT;
+static isc_boolean_t initialised = ISC_FALSE;
+
+static void
+initialise(void) {
        WORD wVersionRequested;
        WSADATA wsaData;
        int err;
@@ -911,11 +913,26 @@ BOOL InitSockets() {
        wVersionRequested = MAKEWORD(2, 0);
 
        err = WSAStartup(wVersionRequested, &wsaData);
-       if ( err != 0 ) {
-               /* Tell the user that we could not find a usable Winsock DLL */
-               return(FALSE);
-       }
-       return(TRUE);
+       if (err != 0) {
+               char strbuf[ISC_STRERRORSIZE];
+               isc__strerror(err, strbuf, sizeof(strbuf));
+               FATAL_ERROR(__FILE__, __LINE__, "WSAStartup() %s: %s",
+                           isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
+                                          ISC_MSG_FAILED, "failed"),
+                           strbuf);
+       } else
+               initialised = ISC_TRUE;
+}
+
+/*
+ * Initialize socket services
+ */
+void
+InitSockets(void) {
+       RUNTIME_CHECK(isc_once_do(&initialise_once,
+                                  initialise) == ISC_R_SUCCESS);
+       if (!initialised)
+               exit(1);
 }
 
 int
@@ -2746,6 +2763,8 @@ isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) {
        if (manager == NULL)
                return (ISC_R_NOMEMORY);
 
+       InitSockets();
+
        manager->magic = SOCKET_MANAGER_MAGIC;
        manager->mctx = NULL;
        ISC_LIST_INIT(manager->socklist);
index 1d8d11d360d0eea729e12ea60a6f3e834189aa69..b4a15c320558c3a5cb200d1510432b28f51a10a3 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.3.2.1 2004/03/09 06:12:29 marka Exp $ */
+/* $Id: DLLMain.c,v 1.3.2.2 2007/06/18 03:30:31 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index 3ada9977f05ef501308f2fa9e27221394393f5ed..defb570e31b461c18b34b15689ebce40c6f5bff9 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.3.2.1 2004/03/09 06:12:32 marka Exp $ */
+/* $Id: DLLMain.c,v 1.3.2.2 2007/06/18 03:30:31 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
 /*
  * Called when we enter the DLL
  */
index f80f294f66604be1428e35d4d427f3a3bcc9568e..12d5afe75fbaf9a70c031d30b1acbcef4bed834e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: context.c,v 1.41.2.4 2004/09/17 05:57:20 marka Exp $ */
+/* $Id: context.c,v 1.41.2.5 2007/06/18 03:30:31 marka Exp $ */
 
 #include <config.h>
 
@@ -128,6 +128,9 @@ lwres_context_destroy(lwres_context_t **contextp) {
        *contextp = NULL;
 
        if (ctx->sock != -1) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                close(ctx->sock);
                ctx->sock = -1;
        }
@@ -231,19 +234,34 @@ context_connect(lwres_context_t *ctx) {
        } else
                return (LWRES_R_IOERROR);
 
+#ifdef WIN32
+       InitSockets();
+#endif
+
        s = socket(domain, SOCK_DGRAM, IPPROTO_UDP);
-       if (s < 0)
+       if (s < 0) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                return (LWRES_R_IOERROR);
+       }
 
        ret = connect(s, sa, salen);
        if (ret != 0) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                close(s);
                return (LWRES_R_IOERROR);
        }
 
        MAKE_NONBLOCKING(s, ret);
-       if (ret < 0)
+       if (ret < 0) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                return (LWRES_R_IOERROR);
+       }
 
        ctx->sock = s;
 
index fc5f61148dbf7e57a3180e2753c248cf2f44336b..6610bf79f0df6412fc659eb78f713e2a1c238fa2 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: getipnode.c,v 1.30.2.8 2005/04/28 23:59:13 marka Exp $ */
+/* $Id: getipnode.c,v 1.30.2.9 2007/06/18 03:30:31 marka Exp $ */
 
 #include <config.h>
 
@@ -399,6 +399,9 @@ scan_interfaces(int *have_v4, int *have_v6) {
        static int bufsiz = 4095;
        int s, cpsize, n;
 
+#ifdef WIN32
+       InitSockets();
+#endif
        /*
         * Set to zero.  Used as loop terminators below.
         */
@@ -519,13 +522,20 @@ scan_interfaces(int *have_v4, int *have_v6) {
        }
        if (buf != NULL)
                free(buf);
+#ifdef WIN32
+       DestroySockets();
+#endif
        close(s);
        return (0);
+
  err_ret:
        if (buf != NULL)
                free(buf);
        if (s != -1)
                close(s);
+#ifdef WIN32
+       DestroySockets();
+#endif
        return (-1);
 #endif
 }
index 0519bcaedfeb711ccbe926c2758a3d44774e2663..d613e80b0a180d2efd604b0fbf83d18385ebf903 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.2.2.1 2004/03/09 06:12:42 marka Exp $ */
+/* $Id: DLLMain.c,v 1.2.2.2 2007/06/18 03:30:31 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index 89539afce98c2fab8ba30129294891a9610be140..b2b32bd127f844a63772c196470b3aefd61c8f18 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: platform.h,v 1.4.2.1 2004/03/09 06:12:44 marka Exp $ */
+/* $Id: platform.h,v 1.4.2.2 2007/06/18 03:30:31 marka Exp $ */
 
 #ifndef LWRES_PLATFORM_H
 #define LWRES_PLATFORM_H 1
@@ -92,4 +92,11 @@ do { \
 #undef  close
 #define close closesocket
 
+/*
+ * Internal to liblwres.
+ */
+void InitSockets(void);
+
+void DestroySockets(void);
+
 #endif /* LWRES_PLATFORM_H */
index b0a5b78e6cfc7ab9f7fd2c1acc1c8fc270c98f53..c6be9b74b4664fd6e1fda24bf1e9cd9066f6f524 100644 (file)
@@ -174,6 +174,10 @@ SOURCE=..\lwresutil.c
 # End Source File
 # Begin Source File
 
+SOURCE=.\socket.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\version.c
 # End Source File
 # End Group
index b641a79a3b36bc0a3c86a060ccda50106a65572a..a0f16566550b1eb1b7a3b601ec9c4730bb97c4aa 100644 (file)
@@ -129,7 +129,9 @@ CLEAN :
        -@erase "$(INTDIR)\lwres_grbn.obj"
        -@erase "$(INTDIR)\lwres_noop.obj"
        -@erase "$(INTDIR)\lwresutil.obj"
+       -@erase "$(INTDIR)\socket.obj"
        -@erase "$(INTDIR)\vc60.idb"
+       -@erase "$(INTDIR)\socket.obj"
        -@erase "$(INTDIR)\version.obj"
        -@erase "$(OUTDIR)\liblwres.exp"
        -@erase "$(OUTDIR)\liblwres.lib"
@@ -204,6 +206,7 @@ LINK32_OBJS= \
        "$(INTDIR)\lwres_grbn.obj" \
        "$(INTDIR)\lwres_noop.obj" \
        "$(INTDIR)\lwresutil.obj" \
+       "$(INTDIR)\socket.obj" \
        "$(INTDIR)\version.obj"
 
 "..\..\..\Build\Release\liblwres.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
@@ -264,8 +267,12 @@ CLEAN :
        -@erase "$(INTDIR)\lwres_noop.sbr"
        -@erase "$(INTDIR)\lwresutil.obj"
        -@erase "$(INTDIR)\lwresutil.sbr"
+       -@erase "$(INTDIR)\socket.obj"
+       -@erase "$(INTDIR)\socket.sbr"
        -@erase "$(INTDIR)\vc60.idb"
        -@erase "$(INTDIR)\vc60.pdb"
+       -@erase "$(INTDIR)\socket.obj"
+       -@erase "$(INTDIR)\socket.sbr"
        -@erase "$(INTDIR)\version.obj"
        -@erase "$(INTDIR)\version.sbr"
        -@erase "$(OUTDIR)\liblwres.bsc"
@@ -370,6 +377,7 @@ LINK32_OBJS= \
        "$(INTDIR)\lwres_grbn.obj" \
        "$(INTDIR)\lwres_noop.obj" \
        "$(INTDIR)\lwresutil.obj" \
+       "$(INTDIR)\socket.obj" \
        "$(INTDIR)\version.obj"
 
 "..\..\..\Build\Debug\liblwres.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
@@ -747,6 +755,22 @@ SOURCE=..\lwresutil.c
        $(CPP) $(CPP_PROJ) $(SOURCE)
 
 
+!ENDIF 
+
+SOURCE=.\socket.c
+
+!IF  "$(CFG)" == "liblwres - Win32 Release"
+
+
+"$(INTDIR)\socket.obj" : $(SOURCE) "$(INTDIR)"
+
+
+!ELSEIF  "$(CFG)" == "liblwres - Win32 Debug"
+
+
+"$(INTDIR)\socket.obj" "$(INTDIR)\socket.sbr" : $(SOURCE) "$(INTDIR)"
+
+
 !ENDIF 
 
 SOURCE=.\version.c