diff options
-rw-r--r-- | opentracker.c | 8 | ||||
-rw-r--r-- | ot_accesslist.c | 4 | ||||
-rw-r--r-- | ot_accesslist.h | 2 | ||||
-rw-r--r-- | ot_clean.c | 2 | ||||
-rw-r--r-- | ot_fullscrape.c | 10 | ||||
-rw-r--r-- | ot_livesync.c | 9 | ||||
-rw-r--r-- | ot_livesync.h | 1 | ||||
-rw-r--r-- | ot_stats.c | 10 | ||||
-rw-r--r-- | trackerlogic.c | 13 | ||||
-rw-r--r-- | trackerlogic.h | 1 |
10 files changed, 48 insertions, 12 deletions
diff --git a/opentracker.c b/opentracker.c index 022f561..1e996d9 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -34,9 +34,10 @@ | |||
34 | #include "ot_livesync.h" | 34 | #include "ot_livesync.h" |
35 | 35 | ||
36 | /* Globals */ | 36 | /* Globals */ |
37 | time_t g_now_seconds; | 37 | time_t g_now_seconds; |
38 | char * g_redirecturl = NULL; | 38 | char * g_redirecturl = NULL; |
39 | uint32_t g_tracker_id; | 39 | uint32_t g_tracker_id; |
40 | volatile int g_opentracker_running = 1; | ||
40 | 41 | ||
41 | static char * g_serverdir = NULL; | 42 | static char * g_serverdir = NULL; |
42 | 43 | ||
@@ -51,6 +52,7 @@ static void panic( const char *routine ) { | |||
51 | static void signal_handler( int s ) { | 52 | static void signal_handler( int s ) { |
52 | if( s == SIGINT ) { | 53 | if( s == SIGINT ) { |
53 | signal( SIGINT, SIG_IGN); | 54 | signal( SIGINT, SIG_IGN); |
55 | g_opentracker_running = 0; | ||
54 | 56 | ||
55 | trackerlogic_deinit(); | 57 | trackerlogic_deinit(); |
56 | exit( 0 ); | 58 | exit( 0 ); |
diff --git a/ot_accesslist.c b/ot_accesslist.c index f4c21c5..3b8e8a9 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c | |||
@@ -23,6 +23,10 @@ | |||
23 | char *g_accesslist_filename = NULL; | 23 | char *g_accesslist_filename = NULL; |
24 | static ot_vector accesslist; | 24 | static ot_vector accesslist; |
25 | 25 | ||
26 | static void access_list_deinit( void ) { | ||
27 | accesslist_reset( ); | ||
28 | } | ||
29 | |||
26 | static void accesslist_reset( void ) { | 30 | static void accesslist_reset( void ) { |
27 | free( accesslist.data ); | 31 | free( accesslist.data ); |
28 | byte_zero( &accesslist, sizeof( accesslist ) ); | 32 | byte_zero( &accesslist, sizeof( accesslist ) ); |
diff --git a/ot_accesslist.h b/ot_accesslist.h index 9c93187..15a21f2 100644 --- a/ot_accesslist.h +++ b/ot_accesslist.h | |||
@@ -13,12 +13,14 @@ | |||
13 | #if defined ( WANT_ACCESSLIST_BLACK ) || defined (WANT_ACCESSLIST_WHITE ) | 13 | #if defined ( WANT_ACCESSLIST_BLACK ) || defined (WANT_ACCESSLIST_WHITE ) |
14 | #define WANT_ACCESSLIST | 14 | #define WANT_ACCESSLIST |
15 | void accesslist_init( ); | 15 | void accesslist_init( ); |
16 | void accesslist_deinit( ); | ||
16 | int accesslist_hashisvalid( ot_hash *hash ); | 17 | int accesslist_hashisvalid( ot_hash *hash ); |
17 | 18 | ||
18 | extern char *g_accesslist_filename; | 19 | extern char *g_accesslist_filename; |
19 | 20 | ||
20 | #else | 21 | #else |
21 | #define accesslist_init( accesslist_filename ) | 22 | #define accesslist_init( accesslist_filename ) |
23 | #define accesslist_deinit( ) | ||
22 | #define accesslist_hashisvalid( hash ) 1 | 24 | #define accesslist_hashisvalid( hash ) 1 |
23 | #endif | 25 | #endif |
24 | 26 | ||
@@ -114,6 +114,8 @@ static void * clean_worker( void * args ) { | |||
114 | } | 114 | } |
115 | } | 115 | } |
116 | mutex_bucket_unlock( bucket ); | 116 | mutex_bucket_unlock( bucket ); |
117 | if( !g_opentracker_running ) | ||
118 | return NULL; | ||
117 | usleep( OT_CLEAN_SLEEP ); | 119 | usleep( OT_CLEAN_SLEEP ); |
118 | } | 120 | } |
119 | } | 121 | } |
diff --git a/ot_fullscrape.c b/ot_fullscrape.c index 5f61afd..9a6effb 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c | |||
@@ -65,6 +65,8 @@ static void * fullscrape_worker( void * args ) { | |||
65 | fullscrape_make( &iovec_entries, &iovector, tasktype ); | 65 | fullscrape_make( &iovec_entries, &iovector, tasktype ); |
66 | if( mutex_workqueue_pushresult( taskid, iovec_entries, iovector ) ) | 66 | if( mutex_workqueue_pushresult( taskid, iovec_entries, iovector ) ) |
67 | iovec_free( &iovec_entries, &iovector ); | 67 | iovec_free( &iovec_entries, &iovector ); |
68 | if( !g_opentracker_running ) | ||
69 | return NULL; | ||
68 | } | 70 | } |
69 | return NULL; | 71 | return NULL; |
70 | } | 72 | } |
@@ -150,7 +152,7 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas | |||
150 | /* Get exclusive access to that bucket */ | 152 | /* Get exclusive access to that bucket */ |
151 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 153 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |
152 | size_t tor_offset; | 154 | size_t tor_offset; |
153 | 155 | ||
154 | /* For each torrent in this bucket.. */ | 156 | /* For each torrent in this bucket.. */ |
155 | for( tor_offset=0; tor_offset<torrents_list->size; ++tor_offset ) { | 157 | for( tor_offset=0; tor_offset<torrents_list->size; ++tor_offset ) { |
156 | /* Address torrents members */ | 158 | /* Address torrents members */ |
@@ -202,8 +204,12 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas | |||
202 | IF_COMPRESSION( r = compress_buffer; ) | 204 | IF_COMPRESSION( r = compress_buffer; ) |
203 | } | 205 | } |
204 | 206 | ||
205 | /* All torrents done: release lock on currenct bucket */ | 207 | /* All torrents done: release lock on current bucket */ |
206 | mutex_bucket_unlock( bucket ); | 208 | mutex_bucket_unlock( bucket ); |
209 | |||
210 | /* Parent thread died? */ | ||
211 | if( !g_opentracker_running ) | ||
212 | return; | ||
207 | } | 213 | } |
208 | 214 | ||
209 | if( ( mode & TASK_TASK_MASK ) == TASK_FULLSCRAPE ) | 215 | if( ( mode & TASK_TASK_MASK ) == TASK_FULLSCRAPE ) |
diff --git a/ot_livesync.c b/ot_livesync.c index b447e83..f61f0ec 100644 --- a/ot_livesync.c +++ b/ot_livesync.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <sys/uio.h> | 8 | #include <sys/uio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
10 | #include <pthread.h> | 10 | #include <pthread.h> |
11 | #include <unistd.h> | ||
11 | 12 | ||
12 | /* Libowfat */ | 13 | /* Libowfat */ |
13 | #include "socket.h" | 14 | #include "socket.h" |
@@ -57,6 +58,11 @@ void livesync_init( ) { | |||
57 | } | 58 | } |
58 | 59 | ||
59 | void livesync_deinit() { | 60 | void livesync_deinit() { |
61 | if( g_livesync_socket_in != -1 ) | ||
62 | close( g_livesync_socket_in ); | ||
63 | if( g_livesync_socket_out != -1 ) | ||
64 | close( g_livesync_socket_out ); | ||
65 | |||
60 | pthread_cancel( thread_id ); | 66 | pthread_cancel( thread_id ); |
61 | } | 67 | } |
62 | 68 | ||
@@ -147,6 +153,9 @@ static void * livesync_worker( void * args ) { | |||
147 | ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash)); | 153 | ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash)); |
148 | ot_hash *hash = (ot_hash*)(livesync_inbuffer + off); | 154 | ot_hash *hash = (ot_hash*)(livesync_inbuffer + off); |
149 | 155 | ||
156 | if( !g_opentracker_running ) | ||
157 | return NULL; | ||
158 | |||
150 | if( OT_PEERFLAG(peer) & PEER_FLAG_STOPPED ) | 159 | if( OT_PEERFLAG(peer) & PEER_FLAG_STOPPED ) |
151 | remove_peer_from_torrent(hash, peer, NULL, FLAG_MCA); | 160 | remove_peer_from_torrent(hash, peer, NULL, FLAG_MCA); |
152 | else | 161 | else |
diff --git a/ot_livesync.h b/ot_livesync.h index c534f59..153dbac 100644 --- a/ot_livesync.h +++ b/ot_livesync.h | |||
@@ -62,6 +62,7 @@ void handle_livesync( const int64 serversocket ); | |||
62 | 62 | ||
63 | /* If no syncing is required, save calling code from #ifdef | 63 | /* If no syncing is required, save calling code from #ifdef |
64 | constructions */ | 64 | constructions */ |
65 | #define livesync_deinit() | ||
65 | #define livesync_init() | 66 | #define livesync_init() |
66 | #define livesync_ticker() | 67 | #define livesync_ticker() |
67 | #define handle_livesync(a) | 68 | #define handle_livesync(a) |
@@ -188,6 +188,8 @@ size_t stats_top10_txt( char * reply ) { | |||
188 | } | 188 | } |
189 | } | 189 | } |
190 | mutex_bucket_unlock( bucket ); | 190 | mutex_bucket_unlock( bucket ); |
191 | if( !g_opentracker_running ) | ||
192 | return 0; | ||
191 | } | 193 | } |
192 | 194 | ||
193 | r += sprintf( r, "Top 10 torrents by peers:\n" ); | 195 | r += sprintf( r, "Top 10 torrents by peers:\n" ); |
@@ -250,6 +252,8 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) | |||
250 | } | 252 | } |
251 | } | 253 | } |
252 | mutex_bucket_unlock( bucket ); | 254 | mutex_bucket_unlock( bucket ); |
255 | if( !g_opentracker_running ) | ||
256 | goto bailout_cleanup; | ||
253 | } | 257 | } |
254 | #endif | 258 | #endif |
255 | 259 | ||
@@ -381,6 +385,8 @@ static size_t stats_peers_mrtg( char * reply ) { | |||
381 | peer_count += peer_list->peer_count; seed_count += peer_list->seed_count; | 385 | peer_count += peer_list->peer_count; seed_count += peer_list->seed_count; |
382 | } | 386 | } |
383 | mutex_bucket_unlock( bucket ); | 387 | mutex_bucket_unlock( bucket ); |
388 | if( !g_opentracker_running ) | ||
389 | return 0; | ||
384 | } | 390 | } |
385 | return sprintf( reply, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", | 391 | return sprintf( reply, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", |
386 | peer_count, | 392 | peer_count, |
@@ -399,6 +405,8 @@ static size_t stats_startstop_mrtg( char * reply ) | |||
399 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 405 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |
400 | torrent_count += torrents_list->size; | 406 | torrent_count += torrents_list->size; |
401 | mutex_bucket_unlock( bucket ); | 407 | mutex_bucket_unlock( bucket ); |
408 | if( !g_opentracker_running ) | ||
409 | return 0; | ||
402 | } | 410 | } |
403 | 411 | ||
404 | return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker", | 412 | return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker", |
@@ -422,6 +430,8 @@ static size_t stats_toraddrem_mrtg( char * reply ) | |||
422 | peer_count += peer_list->peer_count; | 430 | peer_count += peer_list->peer_count; |
423 | } | 431 | } |
424 | mutex_bucket_unlock( bucket ); | 432 | mutex_bucket_unlock( bucket ); |
433 | if( !g_opentracker_running ) | ||
434 | return 0; | ||
425 | } | 435 | } |
426 | 436 | ||
427 | return sprintf( reply, "%zd\n%zd\nopentracker handling %zd peers\nopentracker", | 437 | return sprintf( reply, "%zd\n%zd\nopentracker handling %zd peers\nopentracker", |
diff --git a/trackerlogic.c b/trackerlogic.c index d7fca69..9366cd1 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -376,13 +376,6 @@ void trackerlogic_deinit( void ) { | |||
376 | int bucket; | 376 | int bucket; |
377 | size_t j; | 377 | size_t j; |
378 | 378 | ||
379 | /* Deinitialise background worker threads */ | ||
380 | stats_deinit( ); | ||
381 | livesync_init( ); | ||
382 | accesslist_init( ); | ||
383 | fullscrape_deinit( ); | ||
384 | clean_deinit( ); | ||
385 | |||
386 | /* Free all torrents... */ | 379 | /* Free all torrents... */ |
387 | for(bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { | 380 | for(bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { |
388 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 381 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |
@@ -396,6 +389,12 @@ void trackerlogic_deinit( void ) { | |||
396 | mutex_bucket_unlock( bucket ); | 389 | mutex_bucket_unlock( bucket ); |
397 | } | 390 | } |
398 | 391 | ||
392 | /* Deinitialise background worker threads */ | ||
393 | stats_deinit( ); | ||
394 | livesync_deinit( ); | ||
395 | accesslist_deinit( ); | ||
396 | fullscrape_deinit( ); | ||
397 | clean_deinit( ); | ||
399 | /* Release mutexes */ | 398 | /* Release mutexes */ |
400 | mutex_deinit( ); | 399 | mutex_deinit( ); |
401 | } | 400 | } |
diff --git a/trackerlogic.h b/trackerlogic.h index 1705928..c7e2e97 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -50,6 +50,7 @@ typedef time_t ot_time; | |||
50 | 50 | ||
51 | /* From opentracker.c */ | 51 | /* From opentracker.c */ |
52 | extern time_t g_now_seconds; | 52 | extern time_t g_now_seconds; |
53 | extern volatile int g_opentracker_running; | ||
53 | #define g_now_minutes (g_now_seconds/60) | 54 | #define g_now_minutes (g_now_seconds/60) |
54 | 55 | ||
55 | extern uint32_t g_tracker_id; | 56 | extern uint32_t g_tracker_id; |