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_clean.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ot_clean.c') diff --git a/ot_clean.c b/ot_clean.c index 4adeee6..11c85ab 100644 --- a/ot_clean.c +++ b/ot_clean.c @@ -20,7 +20,7 @@ static ssize_t clean_single_bucket( ot_peer *peers, size_t peer_count, time_t timedout, int *removed_seeders ) { ot_peer *last_peer = peers + peer_count, *insert_point; time_t timediff; - + /* Two scan modes: unless there is one peer removed, just increase ot_peertime */ while( peers < last_peer ) { if( ( timediff = timedout + OT_PEERTIME( peers ) ) >= OT_PEER_TIMEOUT ) @@ -105,17 +105,19 @@ static void * clean_worker( void * args ) { while( bucket-- ) { ot_vector *torrents_list = mutex_bucket_lock( bucket ); size_t toffs; + int delta_torrentcount = 0; for( toffs=0; toffssize; ++toffs ) { ot_torrent *torrent = ((ot_torrent*)(torrents_list->data)) + toffs; if( clean_single_torrent( torrent ) ) { vector_remove_torrent( torrents_list, torrent ); + delta_torrentcount -= 1; --toffs; continue; } } - mutex_bucket_unlock( bucket ); + mutex_bucket_unlock( bucket, delta_torrentcount ); if( !g_opentracker_running ) - return NULL; + return NULL; usleep( OT_CLEAN_SLEEP ); } } -- cgit v1.2.3