diff -Nur opentracker-20160728.orig/opentracker.c opentracker-20160728/opentracker.c --- opentracker-20160728.orig/opentracker.c 2014-10-06 16:32:28.000000000 -0600 +++ opentracker-20160728/opentracker.c 2016-07-28 14:35:00.232095930 -0600 @@ -103,7 +103,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 ) @@ -122,8 +122,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 ) @@ -552,7 +553,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; @@ -569,7 +570,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 ) @@ -605,6 +606,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]; @@ -617,6 +619,7 @@ } } + bound += parse_configfile( "INPUTCONFFILEHERE" ); /* Bind to our default tcp/udp ports */ if( !bound) { ot_try_bind( serverip, 6969, FLAG_TCP ); @@ -628,9 +631,21 @@ setlogmask(LOG_UPTO(LOG_INFO)); #endif - 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