clamd-win32: WIP#2

0.96
aCaB 16 years ago
parent fdb7b9e926
commit 1c4d9a22fa
  1. 1
      clamd/others.c
  2. 39
      clamd/server-th.c
  3. 2
      win32/clamav-config.h
  4. 60
      win32/clamd.vcproj
  5. 55
      win32/compat/net.c
  6. 1
      win32/compat/net.h
  7. 1
      win32/libclamav.def
  8. 1
      win32/platform.h
  9. 2
      win32/update-win32.pl

@ -59,7 +59,6 @@
#if HAVE_POLL_H
#include <poll.h>
#else /* HAVE_POLL_H */
#undef HAVE_POLL
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif /* HAVE_SYS_SELECT_H */

@ -298,11 +298,20 @@ struct acceptdata {
pthread_cond_t cond_nfds;
int max_queue;
int commandtimeout;
#ifdef _WIN32
HANDLE event_wake_recv;
HANDLE event_wake_accept;
#else
int syncpipe_wake_recv[2];
int syncpipe_wake_accept[2];
#endif
};
#ifdef _WIN32
#define ACCEPTDATA_INIT(mutex1, mutex2) { FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, NULL, NULL}
#else
#define ACCEPTDATA_INIT(mutex1, mutex2) { FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, {-1, -1}, {-1, -1}}
#endif
static void *acceptloop_th(void *arg)
{
@ -339,6 +348,7 @@ static void *acceptloop_th(void *arg)
struct fd_buf *buf = &fds->buf[i];
if (!buf->got_newdata)
continue;
#ifndef _WIN32 // FIXME
if (buf->fd == data->syncpipe_wake_accept[0]) {
/* dummy sync pipe, just to wake us */
if (read(buf->fd, buff, sizeof(buff)) < 0) {
@ -346,6 +356,7 @@ static void *acceptloop_th(void *arg)
}
continue;
}
#endif
if (buf->got_newdata == -1) {
logg("$Acceptloop closed FD: %d\n", buf->fd);
shutdown(buf->fd, 2);
@ -406,10 +417,14 @@ static void *acceptloop_th(void *arg)
}
/* notify recvloop */
#ifdef _WIN32
SetEvent(data->event_wake_recv);
#else
if (write(data->syncpipe_wake_recv[1], "", 1) == -1) {
logg("!write syncpipe failed\n");
continue;
}
#endif
} else if (errno != EINTR) {
/* very bad - need to exit or restart */
#ifdef HAVE_STRERROR_R
@ -446,10 +461,13 @@ static void *acceptloop_th(void *arg)
pthread_mutex_lock(&exit_mutex);
progexit = 1;
pthread_mutex_unlock(&exit_mutex);
#ifdef _WIN32
SetEvent(data->event_wake_recv);
#else
if (write(data->syncpipe_wake_recv[1], "", 1) < 0) {
logg("$Syncpipe write failed\n");
}
#endif
return NULL;
}
@ -1046,14 +1064,16 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
cl_engine_free(engine);
return 1;
}
#ifdef _WIN32
acceptdata.event_wake_accept = CreateEvent(NULL, TRUE, FALSE, NULL);
acceptdata.event_wake_recv = CreateEvent(NULL, TRUE, FALSE, NULL);
#else
if (pipe(acceptdata.syncpipe_wake_recv) == -1 ||
(pipe(acceptdata.syncpipe_wake_accept) == -1)) {
logg("!pipe failed\n");
exit(-1);
}
syncpipe_wake_recv_w = acceptdata.syncpipe_wake_recv[1];
if (fds_add(fds, acceptdata.syncpipe_wake_recv[0], 1, 0) == -1 ||
@ -1061,6 +1081,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
logg("!failed to add pipe fd\n");
exit(-1);
}
#endif
if ((thr_pool = thrmgr_new(max_threads, idletimeout, max_queue, scanner_thread)) == NULL) {
logg("!thrmgr_new failed\n");
@ -1109,6 +1130,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
if (!buf->got_newdata)
continue;
#ifndef _WIN32 //FIXME
if (buf->fd == acceptdata.syncpipe_wake_recv[0]) {
/* dummy sync pipe, just to wake us */
if (read(buf->fd, buff, sizeof(buff)) < 0) {
@ -1116,7 +1138,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
}
continue;
}
#endif
if (buf->got_newdata == -1) {
if (buf->mode == MODE_WAITREPLY) {
logg("$mode WAIT_REPLY -> closed\n");
@ -1288,9 +1310,13 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
pthread_mutex_lock(&exit_mutex);
progexit = 1;
pthread_mutex_unlock(&exit_mutex);
#ifdef _WIN32
SetEvent(acceptdata.event_wake_accept);
#else
if (write(acceptdata.syncpipe_wake_accept[1], "", 1) < 0) {
logg("^Write to syncpipe failed\n");
}
#endif
/* Destroy the thread manager.
* This waits for all current tasks to end
*/
@ -1310,8 +1336,13 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
pthread_join(accept_th, NULL);
fds_free(fds);
#ifdef _WIN32
CloseHandle(acceptdata.event_wake_accept);
CloseHandle(acceptdata.event_wake_recv);
#else
close(acceptdata.syncpipe_wake_accept[1]);
close(acceptdata.syncpipe_wake_recv[1]);
#endif
if(dbstat.entries)
cl_statfree(&dbstat);
logg("*Shutting down the main socket%s.\n", (nsockets > 1) ? "s" : "");

@ -269,7 +269,7 @@
#define HAVE_OPENDIR 1
/* Define to 1 if you have the `poll' function. */
/* #undef HAVE_POLL */
#define HAVE_POLL 1
/* Define to 1 if you have the <poll.h> header file. */
/* #undef HAVE_POLL_H */

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
Keyword="Win32Proj"
ProjectType="Visual C++"
Version="9,00"
Name="clamd"
ProjectGUID="{B3CA73CF-E71E-42F3-95DE-43797A86C798}"
ProjectType="Visual C++"
RootNamespace="clamd"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
Version="9,00"
>
<Platforms>
<Platform
@ -17,11 +17,11 @@
</ToolFiles>
<Configurations>
<Configuration
CharacterSet="2"
ConfigurationType="1"
IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
@ -39,18 +39,18 @@
Name="VCMIDLTool"
/>
<Tool
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
BasicRuntimeChecks="3"
CompileAs="1"
DebugInformationFormat="3"
DisableSpecificWarnings="4996;4244"
MinimalRebuild="true"
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H;_BIND_TO_CURRENT_VCLIBS_VERSION=1"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CompileAs="1"
DisableSpecificWarnings="4996;4244;4090;4018"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@ -62,9 +62,9 @@
Name="VCPreLinkEventTool"
/>
<Tool
GenerateDebugInformation="true"
LinkIncremental="1"
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
@ -91,11 +91,11 @@
/>
</Configuration>
<Configuration
CharacterSet="2"
ConfigurationType="1"
IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
@ -114,18 +114,18 @@
Name="VCMIDLTool"
/>
<Tool
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
CompileAs="1"
DebugInformationFormat="3"
DisableSpecificWarnings="4996;4244"
EnableFunctionLevelLinking="true"
EnableIntrinsicFunctions="true"
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H;_BIND_TO_CURRENT_VCLIBS_VERSION=1"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CompileAs="1"
DisableSpecificWarnings="4996;4244;4090;4018"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@ -137,12 +137,12 @@
Name="VCPreLinkEventTool"
/>
<Tool
EnableCOMDATFolding="2"
GenerateDebugInformation="true"
LinkIncremental="1"
Name="VCLinkerTool"
OptimizeReferences="2"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
@ -172,8 +172,8 @@
</References>
<Files>
<Filter
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
@ -234,14 +234,14 @@
</Filter>
</Filter>
<Filter
Filter="h;hpp;hxx;hm;inl;inc;xsd"
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>

@ -24,6 +24,7 @@
#ifdef W2K_DNSAAPI_COMPAT
#include <Wspiapi.h>
#endif
#include <stdlib.h>
#include "net.h"
#include "w32_errno.h"
@ -348,3 +349,57 @@ int w32_shutdown(int sockfd, int how) {
}
return 0;
}
struct w32polldata {
HANDLE setme;
HANDLE event;
HANDLE waiter;
struct pollfd *polldata;
};
VOID CALLBACK poll_cb(PVOID param, BOOLEAN timedout) {
WSANETWORKEVENTS evt;
struct w32polldata *item = (struct w32polldata *)param;
if(!timedout) {
unsigned int i;
WSAEnumNetworkEvents(item->polldata->fd, item->event, &evt);
for(i=0; i<evt.lNetworkEvents; i++) {
if(evt.iErrorCode[i] & (FD_ACCEPT|FD_READ)) item->polldata->revents |= POLLIN;
if(evt.iErrorCode[i] & FD_CLOSE) item->polldata->revents |= POLLHUP;
}
}
}
int w32_poll(struct pollfd *fds, int nfds, int timeout) {
HANDLE setme = CreateEvent(NULL, TRUE, FALSE, NULL);
struct w32polldata *items;
unsigned int i, ret = 0;
timeout = timeout>=0 ? timeout*1000 : INFINITE;
if(!nfds) {
Sleep(timeout);
return 0;
}
items = malloc(nfds * sizeof(struct w32polldata));
for(i=0; i<nfds; i++) {
items[i].event = CreateEvent(NULL, TRUE, FALSE, NULL);
items[i].polldata = &fds[i];
items[i].setme = setme;
if(WSAEventSelect(fds[i].fd, items[i].event, FD_ACCEPT|FD_READ|FD_CLOSE)) {
/* handle error here */
}
if(RegisterWaitForSingleObject(&items[i].waiter, items[i].event, poll_cb, &items[i], timeout, WT_EXECUTEONLYONCE)) {
/* handle errors here */
}
}
WaitForSingleObject(setme, timeout); /* FIXME - add the pipe here */
for(i=0; i<nfds; i++) {
UnregisterWait(items[i].waiter);
WSAEventSelect(fds[i].fd, items[i].event, 0);
CloseHandle(items[i].event);
ret += (items[i].polldata->revents != 0);
}
free(items);
return ret;
}

@ -39,6 +39,7 @@ void w32_freeaddrinfo(struct addrinfo *res);
const char *w32_inet_ntop(int af, const void *src, char *dst, socklen_t size);
struct hostent *w32_gethostbyname(const char *name);
int w32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
int w32_poll(struct pollfd *fds, int nfds, int timeout);
int w32_accept(int sockfd, const struct sockaddr *addr, socklen_t *addrlen);
int w32_listen(int sockfd, int backlog);
int w32_shutdown(int sockfd, int how);

@ -142,6 +142,7 @@ EXPORTS w32_freeaddrinfo
EXPORTS w32_inet_ntop
EXPORTS w32_gethostbyname
EXPORTS w32_select
EXPORTS w32_poll
EXPORTS w32_stat
EXPORTS w32_strerror
EXPORTS w32_strerror_r

@ -46,6 +46,7 @@ char *strptime(const char *s, const char *format, struct tm *tm);
#define inet_ntop w32_inet_ntop
#define gethostbyname w32_gethostbyname
#define select w32_select
#define poll w32_poll
#define strerror w32_strerror
#define strerror_r w32_strerror_r
#define ftruncate _chsize

@ -104,7 +104,7 @@ my %CONF = (
'HAVE_MMAP' => -1,
'HAVE_NDIR_H' => -1,
'HAVE_OPENDIR' => '1',
'HAVE_POLL' => -1,
'HAVE_POLL' => '1',
'HAVE_POLL_H' => -1,
'HAVE_PRAGMA_PACK' => '1',
'HAVE_PRAGMA_PACK_HPPA' => -1,

Loading…
Cancel
Save