From 2df09905f5540fee096d48a92cb0c42558498a12 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Fri, 2 Jan 2009 08:57:53 +0000 Subject: * opentracker now drops permissions in correct order and really chroots() if ran as root * lock passing between add_peer_to_torrent and return_peers_for_torrent is now avoided by providing a more general add_peer_to_torrent_and_return_peers function that can be used with NULL parameters to not return any peers (in sync case) * in order to keep a fast overview how many torrents opentracker maintains, every mutex_bucket_unlock operation expects an additional integer parameter that tells ot_mutex.c how many torrents have been added or removed. A function mutex_get_torrent_count has been introduced. --- ot_stats.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'ot_stats.c') diff --git a/ot_stats.c b/ot_stats.c index a4596c6..dbab275 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -187,7 +187,7 @@ size_t stats_top10_txt( char * reply ) { top10s[idx].torrent = (ot_torrent*)(torrents_list->data) + j; } } - mutex_bucket_unlock( bucket ); + mutex_bucket_unlock( bucket, 0 ); if( !g_opentracker_running ) return 0; } @@ -241,7 +241,7 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) if( !count ) { count = malloc( sizeof(uint32_t) * NUM_S24S ); if( !count ) { - mutex_bucket_unlock( bucket ); + mutex_bucket_unlock( bucket, 0 ); goto bailout_cleanup; } byte_zero( count, sizeof( uint32_t ) * NUM_S24S ); @@ -251,7 +251,7 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) } } } - mutex_bucket_unlock( bucket ); + mutex_bucket_unlock( bucket, 0 ); if( !g_opentracker_running ) goto bailout_cleanup; } @@ -384,7 +384,7 @@ static size_t stats_peers_mrtg( char * reply ) { ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; peer_count += peer_list->peer_count; seed_count += peer_list->seed_count; } - mutex_bucket_unlock( bucket ); + mutex_bucket_unlock( bucket, 0 ); if( !g_opentracker_running ) return 0; } @@ -397,17 +397,7 @@ static size_t stats_peers_mrtg( char * reply ) { static size_t stats_startstop_mrtg( char * reply ) { - size_t torrent_count = 0; - int bucket; - - for( bucket=0; bucketsize; - mutex_bucket_unlock( bucket ); - if( !g_opentracker_running ) - return 0; - } + size_t torrent_count = mutex_get_torrent_count(); return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker", (size_t)0, @@ -429,7 +419,7 @@ static size_t stats_toraddrem_mrtg( char * reply ) ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; peer_count += peer_list->peer_count; } - mutex_bucket_unlock( bucket ); + mutex_bucket_unlock( bucket, 0 ); if( !g_opentracker_running ) return 0; } @@ -443,15 +433,7 @@ static size_t stats_toraddrem_mrtg( char * reply ) static size_t stats_torrents_mrtg( char * reply ) { - size_t torrent_count = 0; - int bucket; - - for( bucket=0; bucketsize; - mutex_bucket_unlock( bucket ); - } + size_t torrent_count = mutex_get_torrent_count(); return sprintf( reply, "%zd\n%zd\nopentracker serving %zd torrents\nopentracker", torrent_count, -- cgit v1.2.3