]> 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:36:51 +0000 (03:36 +0000)
committerMark Andrews <marka@isc.org>
Mon, 18 Jun 2007 03:36:51 +0000 (03:36 +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 04d9a75b9c39f51cde63b92a58ba8e9bf5a70306..54ebab16cd85de903c5a0631b0d167fc74edb1a6 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..9f6f2fad3a95e236185af7efdd776ca3709421d6 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.3 2007/06/18 03:36:50 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index d32d4e36da56dd93c5e12ba787dc0480c16020d5..08801b562a9653ffa36db223a699fe2b1931488c 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.5 2007/06/18 03:36:50 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
 /*
  * Called when we enter the DLL
  */
index 8a33774f933fd7dc8f757fa0f368df2478ef380e..d01282e06ebebe8a52a94d83630385fcde509a6e 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.6 2007/06/18 03:36:50 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..16f7a5c6e22befea1e24e4277c4ce5af62e21e0f 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.9 2007/06/18 03:36:50 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 20b5e25ac0e3c7513143b135bb2e0feae78e6f2d..736650bcc2a6a32410574eb7e422b87aee09253e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: net.c,v 1.12 2005/02/24 00:33:35 marka Exp $ */
+/* $Id: net.c,v 1.13 2007/06/18 03:36:50 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 988df39bfb8523382f31a9651006cb0037bdceef..db59807c2f0093d30470c880ef9188c7d613f88e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: socket.c,v 1.49 2007/03/06 01:50:48 marka Exp $ */
+/* $Id: socket.c,v 1.50 2007/06/18 03:36:50 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>
@@ -911,10 +912,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;
@@ -923,11 +925,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
@@ -2782,6 +2799,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..c79558468c258493ae2daea6e2953f3d1bcf2f9c 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.5 2007/06/18 03:36:50 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index dbfd9393915cfbbfffd6f9231329bc3bf3802c69..27d2597de6bab183285912f5827f6c8c11b51f91 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.5 2007/06/18 03:36:51 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
 /*
  * Called when we enter the DLL
  */
index da70ebac2dcd9e783cd75ff8af3d78667ded6efa..2fa6fb23bb9d03833b3df44f424f8c78a8661f17 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: context.c,v 1.48 2005/04/29 00:24:04 marka Exp $ */
+/* $Id: context.c,v 1.49 2007/06/18 03:36:51 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,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
                (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 5521c378d00fec6d50f723dae79b59cb4cf70008..a2084d80bd5f60002aecae0364c81b10797b3f1b 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: getipnode.c,v 1.40 2005/04/29 00:24:05 marka Exp $ */
+/* $Id: getipnode.c,v 1.41 2007/06/18 03:36:51 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,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 cba1adb999a17138e3a5d68b27a00dbe6c8ad652..f5545d73d6620e28f08411667c3a8b5cd98c102a 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.4 2007/06/18 03:36:51 marka Exp $ */
 
 #include <windows.h>
 #include <signal.h>
 
-BOOL InitSockets(void);
-
 /*
  * Called when we enter the DLL
  */
index 2c58e64ae3bb9a5be669f459aaf917d1d2191b32..d4360d5275fbf72422f3251009da4e83494abee5 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.6 2007/06/18 03:36:51 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 c67b36847f3aa3db98e87da4ad88fb645f74b0d5..13c153b43b29f9cf740f816d49b9ca7112bfe41b 100644 (file)
@@ -134,6 +134,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"
@@ -173,6 +174,7 @@ LINK32_OBJS= \
        "$(INTDIR)\lwres_grbn.obj" \
        "$(INTDIR)\lwres_noop.obj" \
        "$(INTDIR)\lwresutil.obj" \
+       "$(INTDIR)\socket.obj" \
        "$(INTDIR)\version.obj" \
        "$(INTDIR)\lwconfig.obj"
 
@@ -236,6 +238,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"
@@ -273,6 +277,7 @@ BSC32_SBRS= \
        "$(INTDIR)\lwres_grbn.sbr" \
        "$(INTDIR)\lwres_noop.sbr" \
        "$(INTDIR)\lwresutil.sbr" \
+       "$(INTDIR)\socket.sbr" \
        "$(INTDIR)\version.sbr" \
        "$(INTDIR)\lwconfig.sbr"
 
@@ -305,6 +310,7 @@ LINK32_OBJS= \
        "$(INTDIR)\lwres_grbn.obj" \
        "$(INTDIR)\lwres_noop.obj" \
        "$(INTDIR)\lwresutil.obj" \
+       "$(INTDIR)\socket.obj" \
        "$(INTDIR)\version.obj" \
        "$(INTDIR)\lwconfig.obj"
 
@@ -711,6 +717,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();
+}