Re: [Clamav-devel] Sending SCAN command multiple times on th…

Top Page
Attachments:
Message as email
+ (text/plain)
+ (text/html)
+ (text/plain)
Delete this message
Reply to this message
Author: Ramon Amat
Date:  
To: ClamAV Development, dev
Subject: Re: [Clamav-devel] Sending SCAN command multiple times on the same socket fails.
Trog wrote:

>On Wed, 2005-01-26 at 10:36 +0100, Ramon Amat wrote:
>
>
>
>>>>open socket
>>>>
>>>>
>>>>
>>>>
>>>SESSION
>>>
>>>
>>>
>>>
>>>>SCAN filepath-1
>>>>SCAN filepath-2
>>>>SCAN filepath-3
>>>>close socket (I do that and not clamd!!!)
>>>>
>>>>
>
>Did you wait for the result to come back (and read it) between these
>commands?
>

When you talk about (read it) between these commands ? As you can see
below, I just write the SESSION command and that's it.
So far I actually would say that works 30 out of 32 times.

>
>-trog
>


Ok.

I am scanning three files consecutievly. Speed has notably increased
since I am using the SESSION command and creating just one socket.
However, sometimes clamd hangs (I cannot reproduce it on my machine 0.8v
on GNU/LINUX Debian Sarge). It actually will not come back after sWrite
within the scan(...) method. It does not happen very often but it
happens. Some idea what could be done to prevent clamd hanging ?



/// Default Constructor
apevs::ClamavVirusDetector::ClamavVirusDetector(const std::string&
aSocketPath )
: mSocketPath( aSocketPath )
{
try {
mSocket.sCreate();
mSocket.sConnect(mSocketPath.c_str());
mSocket.sWrite("SESSION");
}
catch ( SocketException &e ) { ... }
}


/// Default Destructor
apevs::ClamavVirusDetector::~ClamavVirusDetector()
{
mSocket.sWrite("END");
}

/// Sends a fileName to Clamav and parses response
/// @param aPathName The pathname to the the file to be scanned.
/// @return Returns the name of the virus if the file/pathname is infected.
const std::string apevs::ClamavVirusDetector::scan(
const std::string& aPathName )
{
std::string virusName;
std::string pathName = "SCAN " + aPathName + "\n";

// Scan request
mSocket.sWrite(pathName);
std::string buf;
mSocket.sRead( buf );

// Parse Response
// "FILE IS INFECTED" !!!
int i = 0;
if ( (i = buf.find( "FOUND" )) < buf.length() ) {
int e = i-1;
int b = e;
while ( buf[b-1]!=' ' ) b--;
virusName = buf.substr(b,e-b);

WARNING(
"clamavVirusDetector %s: %s infected by %s",
mSocketPath.c_str(), aPathName.c_str(), virusName.c_str( ));
}
// startsWith("-1"), then "UNKNOWN STATUS" !!!
else if ( !( buf.find( "OK" ) < buf.length() ) ) {

WARNING(
"clamavVirusDetector %s: UNKNOWN STATUS in %s",
mSocketPath.c_str(), aPathName.c_str());
}
return virusName;
}


>_______________________________________________
>http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel
>
>


_______________________________________________
http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel