diff options
author | erdgeist <> | 2009-01-02 08:57:53 +0000 |
---|---|---|
committer | erdgeist <> | 2009-01-02 08:57:53 +0000 |
commit | 2df09905f5540fee096d48a92cb0c42558498a12 (patch) | |
tree | 68eab61d29719400972485de395dd0465467aea6 /ot_clean.c | |
parent | 548e2b8338b5ee8d24fa928e833f345bb5cb6f0e (diff) |
* 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.
Diffstat (limited to 'ot_clean.c')
-rw-r--r-- | ot_clean.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -20,7 +20,7 @@ | |||
20 | static ssize_t clean_single_bucket( ot_peer *peers, size_t peer_count, time_t timedout, int *removed_seeders ) { | 20 | static ssize_t clean_single_bucket( ot_peer *peers, size_t peer_count, time_t timedout, int *removed_seeders ) { |
21 | ot_peer *last_peer = peers + peer_count, *insert_point; | 21 | ot_peer *last_peer = peers + peer_count, *insert_point; |
22 | time_t timediff; | 22 | time_t timediff; |
23 | 23 | ||
24 | /* Two scan modes: unless there is one peer removed, just increase ot_peertime */ | 24 | /* Two scan modes: unless there is one peer removed, just increase ot_peertime */ |
25 | while( peers < last_peer ) { | 25 | while( peers < last_peer ) { |
26 | if( ( timediff = timedout + OT_PEERTIME( peers ) ) >= OT_PEER_TIMEOUT ) | 26 | if( ( timediff = timedout + OT_PEERTIME( peers ) ) >= OT_PEER_TIMEOUT ) |
@@ -105,17 +105,19 @@ static void * clean_worker( void * args ) { | |||
105 | while( bucket-- ) { | 105 | while( bucket-- ) { |
106 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 106 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |
107 | size_t toffs; | 107 | size_t toffs; |
108 | int delta_torrentcount = 0; | ||
108 | 109 | ||
109 | for( toffs=0; toffs<torrents_list->size; ++toffs ) { | 110 | for( toffs=0; toffs<torrents_list->size; ++toffs ) { |
110 | ot_torrent *torrent = ((ot_torrent*)(torrents_list->data)) + toffs; | 111 | ot_torrent *torrent = ((ot_torrent*)(torrents_list->data)) + toffs; |
111 | if( clean_single_torrent( torrent ) ) { | 112 | if( clean_single_torrent( torrent ) ) { |
112 | vector_remove_torrent( torrents_list, torrent ); | 113 | vector_remove_torrent( torrents_list, torrent ); |
114 | delta_torrentcount -= 1; | ||
113 | --toffs; continue; | 115 | --toffs; continue; |
114 | } | 116 | } |
115 | } | 117 | } |
116 | mutex_bucket_unlock( bucket ); | 118 | mutex_bucket_unlock( bucket, delta_torrentcount ); |
117 | if( !g_opentracker_running ) | 119 | if( !g_opentracker_running ) |
118 | return NULL; | 120 | return NULL; |
119 | usleep( OT_CLEAN_SLEEP ); | 121 | usleep( OT_CLEAN_SLEEP ); |
120 | } | 122 | } |
121 | } | 123 | } |