Commit 47ee25b1 authored by Mark Andrews's avatar Mark Andrews
Browse files

2199. [bug] win32: don't call WSAStartup() while loading dlls.

                        [RT #16911]
parent 32391301
2199. [bug] win32: don't call WSAStartup() while loading dlls.
[RT #16911]
2198. [bug] win32: RegCloseKey() could be called when
RegOpenKeyEx() failed. [RT #16911]
......
......@@ -15,13 +15,11 @@
* 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
*/
......
......@@ -15,13 +15,11 @@
* 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
*/
......
......@@ -15,13 +15,11 @@
* 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. */
......
......@@ -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;
......
......@@ -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
......
......@@ -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);
......
......@@ -15,13 +15,11 @@
* 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
*/
......
......@@ -15,13 +15,11 @@
* 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
*/
......
......@@ -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;
......
......@@ -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
}
......
......@@ -15,13 +15,11 @@
* 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
*/
......
......@@ -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 */
......@@ -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
......
......@@ -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
......
#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();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment