Skip to content

Instantly share code, notes, and snippets.

@bramswenson
Created May 21, 2010 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramswenson/408798 to your computer and use it in GitHub Desktop.
Save bramswenson/408798 to your computer and use it in GitHub Desktop.
--- transmission-1.92/daemon/daemon.orig.c.v1.92 2010-05-20 23:15:45.686493465 -0400
+++ transmission-1.92/daemon/daemon.c 2010-05-20 23:39:59.187742392 -0400
@@ -43,6 +43,7 @@
static tr_bool paused = FALSE;
static tr_bool closing = FALSE;
static tr_session * mySession = NULL;
+static const char * pid_filename = NULL;
/***
**** Config File
@@ -98,6 +99,7 @@
{ 'r', "rpc-bind-address", "Where to listen for RPC connections", "r", 1, "<ipv4 address>" },
{ 953, "global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio", "gsr", 1, "ratio" },
{ 954, "no-global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio", "GSR", 0, NULL },
+ { 'x', "pid-file", "Enable PID file", "x", 1, "<pid-file>" },
{ 0, NULL, NULL, NULL, 0, NULL }
};
@@ -288,6 +290,7 @@
const char * configDir = NULL;
dtr_watchdir * watchdir = NULL;
FILE * logfile = NULL;
+ tr_bool pidfile_created = FALSE;
signal( SIGINT, gotsig );
signal( SIGTERM, gotsig );
@@ -388,6 +391,8 @@
case 954:
tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, FALSE );
break;
+ case 'x': pid_filename = optarg;
+ break;
default: showUsage( );
break;
}
@@ -423,6 +428,20 @@
tr_ninf( NULL, "Using settings from \"%s\"", configDir );
tr_sessionSaveSettings( mySession, configDir, &settings );
+ /* create the pidfile */
+ if( pid_filename != NULL ) {
+ FILE * fp = fopen( pid_filename, "w+" );
+ if( fp != NULL )
+ {
+ fprintf( fp, "%d", (int)getpid() );
+ fclose( fp );
+ tr_inf( "Saved pidfile \"%s\"", pid_filename );
+ pidfile_created = TRUE;
+ }
+ else
+ tr_err( "Unable to save pidfile \"%s\": %s", pid_filename, strerror( errno ) );
+ }
+
if( tr_bencDictFindBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &boolVal ) && boolVal )
tr_ninf( MY_NAME, "requiring authentication" );
@@ -454,7 +473,7 @@
#ifdef HAVE_SYSLOG
if( !foreground )
- openlog( MY_NAME, LOG_CONS, LOG_DAEMON );
+ openlog( MY_NAME, LOG_CONS|LOG_PID, LOG_DAEMON );
#endif
while( !closing ) {
@@ -479,6 +498,8 @@
printf( " done.\n" );
/* cleanup */
+ if( pidfile_created )
+ remove( pid_filename );
tr_bencFree( &settings );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment