Handle program end more politely

dynamic-accesslists
erdgeist 16 years ago
parent ad8c9ee1ef
commit c6947b160f

@ -37,6 +37,7 @@
time_t g_now_seconds;
char * g_redirecturl = NULL;
uint32_t g_tracker_id;
volatile int g_opentracker_running = 1;
static char * g_serverdir = NULL;
@ -51,6 +52,7 @@ static void panic( const char *routine ) {
static void signal_handler( int s ) {
if( s == SIGINT ) {
signal( SIGINT, SIG_IGN);
g_opentracker_running = 0;
trackerlogic_deinit();
exit( 0 );

@ -23,6 +23,10 @@
char *g_accesslist_filename = NULL;
static ot_vector accesslist;
static void access_list_deinit( void ) {
accesslist_reset( );
}
static void accesslist_reset( void ) {
free( accesslist.data );
byte_zero( &accesslist, sizeof( accesslist ) );

@ -13,12 +13,14 @@
#if defined ( WANT_ACCESSLIST_BLACK ) || defined (WANT_ACCESSLIST_WHITE )
#define WANT_ACCESSLIST
void accesslist_init( );
void accesslist_deinit( );
int accesslist_hashisvalid( ot_hash *hash );
extern char *g_accesslist_filename;
#else
#define accesslist_init( accesslist_filename )
#define accesslist_deinit( )
#define accesslist_hashisvalid( hash ) 1
#endif

@ -114,6 +114,8 @@ static void * clean_worker( void * args ) {
}
}
mutex_bucket_unlock( bucket );
if( !g_opentracker_running )
return NULL;
usleep( OT_CLEAN_SLEEP );
}
}

@ -65,6 +65,8 @@ static void * fullscrape_worker( void * args ) {
fullscrape_make( &iovec_entries, &iovector, tasktype );
if( mutex_workqueue_pushresult( taskid, iovec_entries, iovector ) )
iovec_free( &iovec_entries, &iovector );
if( !g_opentracker_running )
return NULL;
}
return NULL;
}
@ -202,8 +204,12 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
IF_COMPRESSION( r = compress_buffer; )
}
/* All torrents done: release lock on currenct bucket */
/* All torrents done: release lock on current bucket */
mutex_bucket_unlock( bucket );
/* Parent thread died? */
if( !g_opentracker_running )
return;
}
if( ( mode & TASK_TASK_MASK ) == TASK_FULLSCRAPE )

@ -8,6 +8,7 @@
#include <sys/uio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
/* Libowfat */
#include "socket.h"
@ -57,6 +58,11 @@ void livesync_init( ) {
}
void livesync_deinit() {
if( g_livesync_socket_in != -1 )
close( g_livesync_socket_in );
if( g_livesync_socket_out != -1 )
close( g_livesync_socket_out );
pthread_cancel( thread_id );
}
@ -147,6 +153,9 @@ static void * livesync_worker( void * args ) {
ot_peer *peer = (ot_peer*)(livesync_inbuffer + off + sizeof(ot_hash));
ot_hash *hash = (ot_hash*)(livesync_inbuffer + off);
if( !g_opentracker_running )
return NULL;
if( OT_PEERFLAG(peer) & PEER_FLAG_STOPPED )
remove_peer_from_torrent(hash, peer, NULL, FLAG_MCA);
else

@ -62,6 +62,7 @@ void handle_livesync( const int64 serversocket );
/* If no syncing is required, save calling code from #ifdef
constructions */
#define livesync_deinit()
#define livesync_init()
#define livesync_ticker()
#define handle_livesync(a)

@ -188,6 +188,8 @@ size_t stats_top10_txt( char * reply ) {
}
}
mutex_bucket_unlock( bucket );
if( !g_opentracker_running )
return 0;
}
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 )
}
}
mutex_bucket_unlock( bucket );
if( !g_opentracker_running )
goto bailout_cleanup;
}
#endif
@ -381,6 +385,8 @@ static size_t stats_peers_mrtg( char * reply ) {
peer_count += peer_list->peer_count; seed_count += peer_list->seed_count;
}
mutex_bucket_unlock( bucket );
if( !g_opentracker_running )
return 0;
}
return sprintf( reply, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker",
peer_count,
@ -399,6 +405,8 @@ static size_t stats_startstop_mrtg( char * reply )
ot_vector *torrents_list = mutex_bucket_lock( bucket );
torrent_count += torrents_list->size;
mutex_bucket_unlock( bucket );
if( !g_opentracker_running )
return 0;
}
return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker",
@ -422,6 +430,8 @@ static size_t stats_toraddrem_mrtg( char * reply )
peer_count += peer_list->peer_count;
}
mutex_bucket_unlock( bucket );
if( !g_opentracker_running )
return 0;
}
return sprintf( reply, "%zd\n%zd\nopentracker handling %zd peers\nopentracker",

@ -376,13 +376,6 @@ void trackerlogic_deinit( void ) {
int bucket;
size_t j;
/* Deinitialise background worker threads */
stats_deinit( );
livesync_init( );
accesslist_init( );
fullscrape_deinit( );
clean_deinit( );
/* Free all torrents... */
for(bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
ot_vector *torrents_list = mutex_bucket_lock( bucket );
@ -396,6 +389,12 @@ void trackerlogic_deinit( void ) {
mutex_bucket_unlock( bucket );
}
/* Deinitialise background worker threads */
stats_deinit( );
livesync_deinit( );
accesslist_deinit( );
fullscrape_deinit( );
clean_deinit( );
/* Release mutexes */
mutex_deinit( );
}

@ -50,6 +50,7 @@ typedef time_t ot_time;
/* From opentracker.c */
extern time_t g_now_seconds;
extern volatile int g_opentracker_running;
#define g_now_minutes (g_now_seconds/60)
extern uint32_t g_tracker_id;

Loading…
Cancel
Save