]> 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:08:56 +0000 (03:08 +0000)
committerMark Andrews <marka@isc.org>
Mon, 18 Jun 2007 03:08:56 +0000 (03:08 +0000)
                        [RT #16911]

16 files changed:
CHANGES
lib/bind9/win32/DLLMain.c
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
lib/lwres/win32/socket.c [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 3dbedb22bf8c95363dd1df5a98f78e22f7df72f8..02f52e043acaa2fc6afb9a3679ddd95576a3606d 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 80907bcceaf94b55eef432a85d570d819ca64c22..ecd115bda7ffa209b6c250b58d8b71118b5cc69a 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.2 2004/03/05 05:09:14 marka Exp $ */
+/* $Id: DLLMain.c,v 1.2.18.1 2007/06/18 03:08:56 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index d32d4e36da56dd93c5e12ba787dc0480c16020d5..0a77917b636a35fd97ae69f42833583ec30fd5cc 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.4 2004/03/05 05:10:41 marka Exp $ */
+/* $Id: DLLMain.c,v 1.4.18.1 2007/06/18 03:08:56 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
 /*
  * Called when we enter the DLL
  */
index 8a33774f933fd7dc8f757fa0f368df2478ef380e..0b3bcedc184fae3cdff0d40c803d86dd34f6aebf 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.5 2004/03/05 05:11:56 marka Exp $ */
+/* $Id: DLLMain.c,v 1.5.18.1 2007/06/18 03:08:56 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 0cbcd19082276908e1c3854a98858723d483f400..9b59e9a3b8e63bdf162b190ea5987515822fbd05 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: interfaceiter.c,v 1.8 2004/03/05 05:11:57 marka Exp $ */
+/* $Id: interfaceiter.c,v 1.8.18.1 2007/06/18 03:08:56 marka Exp $ */
 
 /*
  * Note that this code will need to be revisited to support IPv6 Interfaces.
@@ -39,6 +39,8 @@
 #include <isc/types.h>
 #include <isc/util.h>
 
+void InitSockets(void);
+
 /* Common utility functions */
 
 /*
@@ -115,6 +117,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 b604f33a732487eed923ee8b9e9af992dbe9cfb8..b2f1201abe9bb512c9f7a93b25cee386c3f8423d 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: net.c,v 1.9.18.3 2005/02/24 00:32:22 marka Exp $ */
+/* $Id: net.c,v 1.9.18.4 2007/06/18 03:08:56 marka Exp $ */
 
 #include <config.h>
 
@@ -42,6 +42,8 @@ static isc_result_t   ipv6_result = ISC_R_NOTFOUND;
 static isc_result_t    ipv6only_result = ISC_R_NOTFOUND;
 static isc_result_t    ipv6pktinfo_result = ISC_R_NOTFOUND;
 
+void InitSockets(void);
+
 static isc_result_t
 try_proto(int domain) {
        SOCKET s;
@@ -121,6 +123,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 7d40b36be566d120eed7c3ac7ba7e1d4350ca9a6..633e94a0904c763ee0d475ce5a7a53a22eb2eda0 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.30.18.17 2007/02/01 23:55:20 marka Exp $ */
+/* $Id: socket.c,v 1.30.18.18 2007/06/18 03:08:56 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>
@@ -904,10 +905,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;
@@ -916,11 +918,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
@@ -2775,6 +2792,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 6fc959c9b261ee43a8c122bb8d4983aab7b39325..f8ea2917df441a39ed78b4cd1dae290ede41c13a 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.4 2004/03/05 05:12:19 marka Exp $ */
+/* $Id: DLLMain.c,v 1.4.18.1 2007/06/18 03:08:56 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index dbfd9393915cfbbfffd6f9231329bc3bf3802c69..5328afde4c2984c846be7f8f15591b97fcb14f6f 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.4 2004/03/05 05:12:42 marka Exp $ */
+/* $Id: DLLMain.c,v 1.4.18.1 2007/06/18 03:08:56 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
 /*
  * Called when we enter the DLL
  */
index 0da426ba5910d3866d53ee4f3de717167e4738a6..eee10c32de3eb10b368b1cd04cf8b6e431a869ed 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: context.c,v 1.45.18.3 2005/04/29 00:17:16 marka Exp $ */
+/* $Id: context.c,v 1.45.18.4 2007/06/18 03:08:56 marka Exp $ */
 
 /*! \file context.c 
    lwres_context_create() creates a #lwres_context_t structure for use in
@@ -209,6 +209,9 @@ lwres_context_destroy(lwres_context_t **contextp) {
        *contextp = NULL;
 
        if (ctx->sock != -1) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                (void)close(ctx->sock);
                ctx->sock = -1;
        }
@@ -315,19 +318,30 @@ 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)
                return (LWRES_R_IOERROR);
 
        ret = connect(s, sa, salen);
        if (ret != 0) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                (void)close(s);
                return (LWRES_R_IOERROR);
        }
 
        MAKE_NONBLOCKING(s, ret);
-       if (ret < 0)
+       if (ret < 0) {
+#ifdef WIN32
+               DestroySockets();
+#endif
+               (void)close(s);
                return (LWRES_R_IOERROR);
+       }
 
        ctx->sock = s;
 
index 46eed144ad035c1f60ed76ea02c2aabc0fb2d844..a708d5aaf2254268898eca6cceb1dd2da052ad62 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: getipnode.c,v 1.37.18.3 2005/04/29 00:17:18 marka Exp $ */
+/* $Id: getipnode.c,v 1.37.18.4 2007/06/18 03:08:56 marka Exp $ */
 
 /*! \file */
 
@@ -671,13 +671,20 @@ scan_interfaces(int *have_v4, int *have_v6) {
        int s, n;
        size_t cpsize;
 
+#ifdef WIN32
+       InitSockets();
+#endif
 #if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR) && \
     !defined(IRIX_EMUL_IOCTL_SIOCGIFCONF) 
        /*
         * Try to scan the interfaces using IPv6 ioctls().
         */
-       if (!scan_interfaces6(have_v4, have_v6))
+       if (!scan_interfaces6(have_v4, have_v6)) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                return (0);
+       }
 #endif
 
        /*
@@ -802,13 +809,21 @@ 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)
+       if (s != -1) {
+#ifdef WIN32
+               DestroySockets();
+#endif
                close(s);
+       }
        return (-1);
 #endif
 }
index cba1adb999a17138e3a5d68b27a00dbe6c8ad652..b3a10d313ac9c583f0e0949c70111d2d0f155290 100644 (file)
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: DLLMain.c,v 1.3 2004/03/05 05:13:20 marka Exp $ */
+/* $Id: DLLMain.c,v 1.3.18.1 2007/06/18 03:08:56 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index 2c58e64ae3bb9a5be669f459aaf917d1d2191b32..da7a98227e1f507854a594817341ceb6a999e709 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: platform.h,v 1.5 2004/03/05 05:13:35 marka Exp $ */
+/* $Id: platform.h,v 1.5.18.1 2007/06/18 03:08:56 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 6764239c62753598dcc6de6cdc89615765b42f89..2b8de773b269bfa562b410b4b6652d5675659bfe 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 63f7ff86235d61a923e6fe254c29ee2d6d2bd18f..44e793b23e77ea9074fb9dde8b2b5d815b713d3d 100644 (file)
@@ -135,6 +135,7 @@ CLEAN :
        -@erase "$(INTDIR)\lwres_noop.obj"
        -@erase "$(INTDIR)\lwresutil.obj"
        -@erase "$(INTDIR)\vc60.idb"
+       -@erase "$(INTDIR)\socket.obj"
        -@erase "$(INTDIR)\version.obj"
        -@erase "$(OUTDIR)\liblwres.exp"
        -@erase "$(OUTDIR)\liblwres.lib"
@@ -174,6 +175,7 @@ LINK32_OBJS= \
        "$(INTDIR)\lwres_grbn.obj" \
        "$(INTDIR)\lwres_noop.obj" \
        "$(INTDIR)\lwresutil.obj" \
+       "$(INTDIR)\socket.obj" \
        "$(INTDIR)\version.obj" \
        "$(INTDIR)\lwconfig.obj"
 
@@ -237,6 +239,8 @@ CLEAN :
        -@erase "$(INTDIR)\lwresutil.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"
@@ -274,6 +278,7 @@ BSC32_SBRS= \
        "$(INTDIR)\lwres_grbn.sbr" \
        "$(INTDIR)\lwres_noop.sbr" \
        "$(INTDIR)\lwresutil.sbr" \
+       "$(INTDIR)\socket.sbr" \
        "$(INTDIR)\version.sbr" \
        "$(INTDIR)\lwconfig.sbr"
 
@@ -306,6 +311,7 @@ LINK32_OBJS= \
        "$(INTDIR)\lwres_grbn.obj" \
        "$(INTDIR)\lwres_noop.obj" \
        "$(INTDIR)\lwresutil.obj" \
+       "$(INTDIR)\socket.obj" \
        "$(INTDIR)\version.obj" \
        "$(INTDIR)\lwconfig.obj"
 
@@ -712,6 +718,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
diff --git a/lib/lwres/win32/socket.c b/lib/lwres/win32/socket.c
new file mode 100644 (file)
index 0000000..e173ce3
--- /dev/null
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <lwres/platform.h>
+#include <Winsock2.h>
+
+void
+InitSockets(void) {
+       WORD wVersionRequested;
+       WSADATA wsaData;
+       int err;
+       wVersionRequested = MAKEWORD(2, 0);
+       err = WSAStartup( wVersionRequested, &wsaData );
+       if (err != 0) {
+               fprintf(stderr, "WSAStartup() failed: %d\n", err);
+               exit(1);
+       }
+}
+
+void
+DestroySockets(void) {
+       WSACleanup();
+}