Blob Blame History Raw
diff -Naur opentracker-0.orig/opentracker.c opentracker-0/opentracker.c
--- opentracker-0.orig/opentracker.c	2010-08-18 02:43:12.000000000 +0200
+++ opentracker-0/opentracker.c	2010-11-14 16:11:23.342340079 +0100
@@ -94,7 +94,7 @@
 }
 
 static void usage( char *name ) {
-  fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-r redirect] [-d dir] [-u user] [-A ip] [-f config] [-s livesyncport]"
+  fprintf( stderr, "Usage: %s [-i ip] [-p port] [-P port] [-r redirect] [-d dir] [-u user] [-A ip] [-f config] [-s livesyncport] [-m run as daemon]"
 #ifdef WANT_ACCESSLIST_BLACK
   " [-b blacklistfile]"
 #elif defined ( WANT_ACCESSLIST_WHITE )
@@ -113,8 +113,9 @@
   HELPLINE("-P port","specify udp port to bind to (default: 6969, you may specify more than one)");
   HELPLINE("-r redirecturl","specify url where / should be redirected to (default none)");
   HELPLINE("-d dir","specify directory to try to chroot to (default: \".\")");
-  HELPLINE("-u user","specify user under whose priviliges opentracker should run (default: \"nobody\")");
+  HELPLINE("-u user","specify user under whose priviliges opentracker should run (default: \"opentracker\")");
   HELPLINE("-A ip","bless an ip address as admin address (e.g. to allow syncs from this address)");
+  HELPLINE("-m ","run as deamon");
 #ifdef WANT_ACCESSLIST_BLACK
   HELPLINE("-b file","specify blacklist file.");
 #elif defined( WANT_ACCESSLIST_WHITE )
@@ -535,7 +536,7 @@
 
 int main( int argc, char **argv ) {
   ot_ip6 serverip, tmpip;
-  int bound = 0, scanon = 1;
+  int bound = 0, scanon = 1, pid = 0;
   uint16_t tmpport;
   char * statefile = 0;
 
@@ -546,7 +547,7 @@
 #endif
 
   while( scanon ) {
-    switch( getopt( argc, argv, ":i:p:A:P:d:u:r:s:f:l:v"
+    switch( getopt( argc, argv, ":i:p:A:P:d:u:r:s:f:l:v:m"
 #ifdef WANT_ACCESSLIST_BLACK
 "b:"
 #elif defined( WANT_ACCESSLIST_WHITE )
@@ -582,6 +583,7 @@
         accesslist_blessip( tmpip, 0xffff ); /* Allow everything for now */
         break;
       case 'f': bound += parse_configfile( optarg ); break;
+      case 'm': pid = 1; break;
       case 'h': help( argv[0] ); exit( 0 );
       case 'v': {
         char buffer[8192];
@@ -594,15 +596,28 @@
     }
   }
 
+  bound += parse_configfile( "INPUTCONFFILEHERE" );
   /* Bind to our default tcp/udp ports */
   if( !bound) {
     ot_try_bind( serverip, 6969, FLAG_TCP );
     ot_try_bind( serverip, 6969, FLAG_UDP );
   }
 
-  if( drop_privileges( g_serveruser ? g_serveruser : "nobody", g_serverdir ) == -1 )
+  if( drop_privileges( g_serveruser ? g_serveruser : "opentracker", g_serverdir ) == -1 )
     panic( "drop_privileges failed, exiting. Last error");
 
+  if (pid) {
+    pid = fork();
+	if (pid == -1) {
+      perror("fork");
+      exit(EXIT_FAILURE);
+	} else if (pid != 0) {
+      exit(EXIT_SUCCESS);
+	}
+	freopen("/dev/null", "a+", stdout);
+	freopen("/dev/null", "a+", stderr);
+  }
+
   g_now_seconds = time( NULL );
 
   /* Create our self pipe which allows us to interrupt mainloops