Browse Source

Logic now actually initialized and deinitialized

dynamic-accesslists
erdgeist 18 years ago
parent
commit
932242eee7
  1. 6
      opentracker.c
  2. 18
      trackerlogic.c

6
opentracker.c

@ -224,8 +224,11 @@ bailout:
} }
void graceful( int s ) { void graceful( int s ) {
if( s == SIGINT ) {
signal( SIGINT, SIG_IGN); signal( SIGINT, SIG_IGN);
deinit_logic(); deinit_logic();
exit( 0 );
}
} }
int main() int main()
@ -245,7 +248,8 @@ int main()
panic("io_fd"); panic("io_fd");
signal( SIGINT, graceful ); signal( SIGINT, graceful );
init_logic( "." ); if( init_logic( "." ) == -1 )
panic("Logic not started");
io_wantread(s); io_wantread(s);

18
trackerlogic.c

@ -212,7 +212,7 @@ void heal_torrent( ot_torrent torrent ) {
} }
void dispose_torrent( ot_torrent torrent ) { void dispose_torrent( ot_torrent torrent ) {
unmap_file( "", torrent->peer_list, 0 ); unmap_file( NULL, torrent->peer_list, 0 );
unlink( to_hex( torrent->hash ) ); unlink( to_hex( torrent->hash ) );
MEMMOVE( torrent, torrent + 1, ( torrents_list + torrents_count ) - ( torrent + 1 ) ); MEMMOVE( torrent, torrent + 1, ( torrents_list + torrents_count ) - ( torrent + 1 ) );
torrents_count--; torrents_count--;
@ -229,11 +229,11 @@ void *map_file( char *file_name ) {
int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644); int file_desc=open(file_name,O_RDWR|O_CREAT|O_NDELAY,0644);
if( file_desc < 0) return 0; if( file_desc < 0) return 0;
lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET ); lseek( file_desc, OT_HUGE_FILESIZE, SEEK_SET );
write( file_desc, "_", 1 );
map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_SHARED,file_desc,0); map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_SHARED,file_desc,0);
close(file_desc); close(file_desc);
} else } else
map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_ANON,-1,0); map=mmap(0,OT_HUGE_FILESIZE,PROT_READ|PROT_WRITE,MAP_ANON|MAP_PRIVATE,-1,0);
return (map == (char*)-1) ? 0 : map; return (map == (char*)-1) ? 0 : map;
} }
@ -259,13 +259,15 @@ int init_logic( char *directory ) {
if( directory ) if( directory )
chdir( directory ); chdir( directory );
scratch_space = map_file( "" ); scratch_space = map_file( NULL );
torrents_list = map_file( "" ); torrents_list = map_file( NULL );
torrents_count = 0; torrents_count = 0;
printf( "%08x %08x\n", scratch_space, torrents_list );
if( !scratch_space || !torrents_list ) { if( !scratch_space || !torrents_list ) {
if( scratch_space || torrents_list ) if( scratch_space || torrents_list )
unmap_file( "", scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 ); unmap_file( NULL, scratch_space ? (void*)scratch_space : (void*)torrents_list, 0 );
return -1; return -1;
} }
@ -308,6 +310,6 @@ void deinit_logic( ) {
// For all torrents... blablabla // For all torrents... blablabla
while( torrents_count-- ) while( torrents_count-- )
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) ); 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) );
unmap_file( "", torrents_list, 0 ); unmap_file( NULL, torrents_list, 0 );
unmap_file( "", scratch_space, 0 ); unmap_file( NULL, scratch_space, 0 );
} }

Loading…
Cancel
Save