Browse Source

Handle program end more politely

master
Dirk Engling 13 years ago
parent
commit
04e5bac4c3
  1. 12
      opentracker.c
  2. 6
      ot_accesslist.c
  3. 2
      ot_accesslist.h
  4. 4
      ot_clean.c
  5. 12
      ot_fullscrape.c
  6. 11
      ot_livesync.c
  7. 1
      ot_livesync.h
  8. 12
      ot_stats.c
  9. 15
      trackerlogic.c
  10. 1
      trackerlogic.h

12
opentracker.c

@ -2,7 +2,7 @@
It is considered beerware. Prost. Skol. Cheers or whatever.
Some of the stuff below is stolen from Fefes example libowfat httpd.
$Id: opentracker.c,v 1.204 2008/12/06 20:21:15 erdgeist Exp $ */
$Id: opentracker.c,v 1.205 2008/12/07 03:50:51 erdgeist Exp $ */
/* System */
#include <stdlib.h>
@ -34,9 +34,10 @@
#include "ot_livesync.h"
/* Globals */
time_t g_now_seconds;
char * g_redirecturl = NULL;
uint32_t g_tracker_id;
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 );
@ -429,4 +431,4 @@ while( scanon ) {
return 0;
}
const char *g_version_opentracker_c = "$Source: /home/cvsroot/opentracker/opentracker.c,v $: $Revision: 1.204 $\n";
const char *g_version_opentracker_c = "$Source: /home/cvsroot/opentracker/opentracker.c,v $: $Revision: 1.205 $\n";

6
ot_accesslist.c

@ -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 ) );
@ -126,4 +130,4 @@ int accesslist_isblessed( char *ip, ot_permissions permissions ) {
return 0;
}
const char *g_version_accesslist_c = "$Source: /home/cvsroot/opentracker/ot_accesslist.c,v $: $Revision: 1.11 $\n";
const char *g_version_accesslist_c = "$Source: /home/cvsroot/opentracker/ot_accesslist.c,v $: $Revision: 1.12 $\n";

2
ot_accesslist.h

@ -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

4
ot_clean.c

@ -114,6 +114,8 @@ static void * clean_worker( void * args ) {
}
}
mutex_bucket_unlock( bucket );
if( !g_opentracker_running )
return NULL;
usleep( OT_CLEAN_SLEEP );
}
}
@ -129,4 +131,4 @@ void clean_deinit( void ) {
pthread_cancel( thread_id );
}
const char *g_version_clean_c = "$Source: /home/cvsroot/opentracker/ot_clean.c,v $: $Revision: 1.14 $\n";
const char *g_version_clean_c = "$Source: /home/cvsroot/opentracker/ot_clean.c,v $: $Revision: 1.15 $\n";

12
ot_fullscrape.c

@ -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;
}
@ -150,7 +152,7 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
/* Get exclusive access to that bucket */
ot_vector *torrents_list = mutex_bucket_lock( bucket );
size_t tor_offset;
/* For each torrent in this bucket.. */
for( tor_offset=0; tor_offset<torrents_list->size; ++tor_offset ) {
/* Address torrents members */
@ -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 )
@ -229,4 +235,4 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas
}
#endif
const char *g_version_fullscrape_c = "$Source: /home/cvsroot/opentracker/ot_fullscrape.c,v $: $Revision: 1.25 $\n";
const char *g_version_fullscrape_c = "$Source: /home/cvsroot/opentracker/ot_fullscrape.c,v $: $Revision: 1.26 $\n";

11
ot_livesync.c

@ -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
@ -162,4 +171,4 @@ static void * livesync_worker( void * args ) {
}
#endif
const char *g_version_livesync_c = "$Source: /home/cvsroot/opentracker/ot_livesync.c,v $: $Revision: 1.8 $\n";
const char *g_version_livesync_c = "$Source: /home/cvsroot/opentracker/ot_livesync.c,v $: $Revision: 1.9 $\n";

1
ot_livesync.h

@ -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)

12
ot_stats.c

@ -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",
@ -624,4 +634,4 @@ void stats_deinit( ) {
pthread_cancel( thread_id );
}
const char *g_version_stats_c = "$Source: /home/cvsroot/opentracker/ot_stats.c,v $: $Revision: 1.32 $\n";
const char *g_version_stats_c = "$Source: /home/cvsroot/opentracker/ot_stats.c,v $: $Revision: 1.33 $\n";

15
trackerlogic.c

@ -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,8 +389,14 @@ 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( );
}
const char *g_version_trackerlogic_c = "$Source: /home/cvsroot/opentracker/trackerlogic.c,v $: $Revision: 1.114 $\n";
const char *g_version_trackerlogic_c = "$Source: /home/cvsroot/opentracker/trackerlogic.c,v $: $Revision: 1.115 $\n";

1
trackerlogic.h

@ -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