summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crawlingwolf.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/crawlingwolf.cpp b/src/crawlingwolf.cpp
index 583d754..c34b345 100644
--- a/src/crawlingwolf.cpp
+++ b/src/crawlingwolf.cpp
@@ -14,12 +14,30 @@
#include <vector>
#include <list>
+#include <signal.h>
+
using namespace std;
+static bool term = false;
+
+static void terminate_func( int sig )
+{
+ (void)sig;
+ term = true;
+}
+
int main( void )
{
FILELog::reportingLevel( ) = logINFO;
-
+
+ struct sigaction sa;
+ memset( &sa, 0, sizeof( struct sigaction ) );
+ sa.sa_handler = terminate_func;
+ sa.sa_flags = SA_RESTART;
+ if( sigaction( SIGINT, &sa, NULL ) < 0 ) {
+ cerr << "Unable to install termianation signal handler" << endl;
+ }
+
vector<string> normalizerModules;
normalizerModules.push_back( "./modules/urlnormalizer/simpleurl/mod_urlnormalizer_simple.so" );
normalizerModules.push_back( "./modules/urlnormalizer/googleurl/mod_urlnormalizer_googleurl.so" );
@@ -83,7 +101,7 @@ int main( void )
frontier->addUrl( normalizer->parseUrl( "http://www.andreasbaumann.cc" ) );
URL url;
- while( ( url = frontier->getNextUrl( ) ) != URL::Null ) {
+ while( !term && ( url = frontier->getNextUrl( ) ) != URL::Null ) {
LOG( logINFO ) << "Got URL " << url;
RewindInputStream *s = fetcher->fetch( url );