]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
Logic now actually initialized and deinitialized
authorerdgeist <>
Fri, 8 Dec 2006 22:53:32 +0000 (22:53 +0000)
committererdgeist <>
Fri, 8 Dec 2006 22:53:32 +0000 (22:53 +0000)
opentracker.c
trackerlogic.c

index 10b7d87b881c069fb14a270650fb1db668fa6fca..ac3fda1b9ddfa5c637f3c02cd185a74182362313 100644 (file)
@@ -224,8 +224,11 @@ bailout:
 }
 
 void graceful( int s ) {
-  signal( SIGINT, SIG_IGN );
-  deinit_logic();
+  if( s == SIGINT ) {
+    signal( SIGINT, SIG_IGN);
+    deinit_logic();
+    exit( 0 );
+  }
 }
 
 int main()
@@ -245,7 +248,8 @@ int main()
         panic("io_fd");
 
     signal( SIGINT, graceful );
-    init_logic( "." );
+    if( init_logic( "." ) == -1 )
+      panic("Logic not started");
 
     io_wantread(s);
 
index ab1f419fa0269992e6aab40a3bc34f3ee5850ae3..1407522a9f5b792c8f0f6a66821a5409a25a7791 100644 (file)
@@ -212,7 +212,7 @@ void heal_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 ) );
   MEMMOVE( torrent, torrent + 1, ( torrents_list + torrents_count ) - ( torrent + 1 ) );
   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);
     if( file_desc < 0) return 0;
     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);
     close(file_desc);
   } 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;
 }
@@ -259,13 +259,15 @@ int init_logic( char *directory ) {
   if( directory )
    chdir( directory );
 
-  scratch_space    = map_file( "" );
-  torrents_list    = map_file( "" );
+  scratch_space    = map_file( NULL );
+  torrents_list    = map_file( NULL );
   torrents_count   = 0;
 
+  printf( "%08x  %08x\n", 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;
   }
 
@@ -308,6 +310,6 @@ void deinit_logic( ) {
   // For all torrents... blablabla
   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( "", torrents_list, 0 );
-  unmap_file( "", scratch_space, 0 );
+  unmap_file( NULL, torrents_list, 0 );
+  unmap_file( NULL, scratch_space, 0 );
 }