summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opentracker.c10
-rw-r--r--trackerlogic.c18
2 files changed, 17 insertions, 11 deletions
diff --git a/opentracker.c b/opentracker.c
index 10b7d87..ac3fda1 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -224,8 +224,11 @@ bailout:
224} 224}
225 225
226void graceful( int s ) { 226void graceful( int s ) {
227 signal( SIGINT, SIG_IGN ); 227 if( s == SIGINT ) {
228 deinit_logic(); 228 signal( SIGINT, SIG_IGN);
229 deinit_logic();
230 exit( 0 );
231 }
229} 232}
230 233
231int main() 234int main()
@@ -245,7 +248,8 @@ int main()
245 panic("io_fd"); 248 panic("io_fd");
246 249
247 signal( SIGINT, graceful ); 250 signal( SIGINT, graceful );
248 init_logic( "." ); 251 if( init_logic( "." ) == -1 )
252 panic("Logic not started");
249 253
250 io_wantread(s); 254 io_wantread(s);
251 255
diff --git a/trackerlogic.c b/trackerlogic.c
index ab1f419..1407522 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -212,7 +212,7 @@ void heal_torrent( ot_torrent torrent ) {
212} 212}
213 213
214void dispose_torrent( ot_torrent torrent ) { 214void dispose_torrent( ot_torrent torrent ) {
215 unmap_file( "", torrent->peer_list, 0 ); 215 unmap_file( NULL, torrent->peer_list, 0 );
216 unlink( to_hex( torrent->hash ) ); 216 unlink( to_hex( torrent->hash ) );
217 MEMMOVE( torrent, torrent + 1, ( torrents_list + torrents_count ) - ( torrent + 1 ) ); 217 MEMMOVE( torrent, torrent + 1, ( torrents_list + torrents_count ) - ( torrent + 1 ) );
218 torrents_count--; 218 torrents_count--;
@@ -229,11 +229,11 @@ void *map_file( char *file_name ) {
229 int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644); 229 int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644);
230 if( file_desc < 0) return 0; 230 if( file_desc < 0) return 0;
231 lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET ); 231 lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET );
232 232 write( file_desc, "_", 1 );
233 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_SHARED,file_desc,0); 233 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_SHARED,file_desc,0);
234 close(file_desc); 234 close(file_desc);
235 } else 235 } else
236 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_ANON,-1,0); 236 map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_ANON|MAP_PRIVATE,-1,0);
237 237
238 return (map == (char*)-1) ? 0 : map; 238 return (map == (char*)-1) ? 0 : map;
239} 239}
@@ -259,13 +259,15 @@ int init_logic( char *directory ) {
259 if( directory ) 259 if( directory )
260 chdir( directory ); 260 chdir( directory );
261 261
262 scratch_space = map_file( "" ); 262 scratch_space = map_file( NULL );
263 torrents_list = map_file( "" ); 263 torrents_list = map_file( NULL );
264 torrents_count = 0; 264 torrents_count = 0;
265 265
266 printf( "%08x %08x\n", scratch_space, torrents_list );
267
266 if( !scratch_space || !torrents_list ) { 268 if( !scratch_space || !torrents_list ) {
267 if( scratch_space || torrents_list ) 269 if( scratch_space || torrents_list )
268 unmap_file( "", scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 ); 270 unmap_file( NULL, scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 );
269 return -1; 271 return -1;
270 } 272 }
271 273
@@ -308,6 +310,6 @@ void deinit_logic( ) {
308 // For all torrents... blablabla 310 // For all torrents... blablabla
309 while( torrents_count-- ) 311 while( torrents_count-- )
310 unmap_file( to_hex(torrents_list[torrents_count].hash), torrents_list[torrents_count].peer_list, torrents_list[torrents_count].peer_count * sizeof(struct ot_peer) ); 312 unmap_file( to_hex(torrents_list[torrents_count].hash), torrents_list[torrents_count].peer_list, torrents_list[torrents_count].peer_count * sizeof(struct ot_peer) );
311 unmap_file( "", torrents_list, 0 ); 313 unmap_file( NULL, torrents_list, 0 );
312 unmap_file( "", scratch_space, 0 ); 314 unmap_file( NULL, scratch_space, 0 );
313} 315}