2008-05-18 16:44:30 +00:00
|
|
|
/*
|
2009-01-10 23:09:07 +00:00
|
|
|
* This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
|
2007-04-18 16:39:10 +00:00
|
|
|
*
|
2008-05-18 16:44:30 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2008-05-18 16:44:30 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2007-04-18 16:39:10 +00:00
|
|
|
*
|
2008-05-19 16:16:38 +00:00
|
|
|
* $Id$
|
2008-05-18 16:44:30 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-18 16:39:10 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2008-09-23 19:11:04 +00:00
|
|
|
#include <stdio.h> /* printf */
|
2008-05-18 16:44:30 +00:00
|
|
|
#include <stdlib.h> /* exit, atoi */
|
|
|
|
#include <string.h> /* strcmp */
|
|
|
|
|
2008-12-25 22:06:48 +00:00
|
|
|
#include <sys/types.h> /* umask*/
|
|
|
|
#include <sys/stat.h> /* umask*/
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
#include <fcntl.h> /* open */
|
2007-04-18 16:39:10 +00:00
|
|
|
#include <signal.h>
|
2008-10-13 22:26:02 +00:00
|
|
|
#include <unistd.h> /* daemon */
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2008-12-30 22:07:39 +00:00
|
|
|
#include <event.h>
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/bencode.h>
|
2008-07-08 16:50:34 +00:00
|
|
|
#include <libtransmission/tr-getopt.h>
|
2008-05-22 19:24:11 +00:00
|
|
|
#include <libtransmission/utils.h>
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/version.h>
|
|
|
|
|
2009-03-01 15:38:58 +00:00
|
|
|
#include "watch.h"
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
#define MY_NAME "transmission-daemon"
|
2007-04-18 16:39:10 +00:00
|
|
|
|
2009-02-27 21:49:31 +00:00
|
|
|
#define PREF_KEY_DIR_WATCH "watch-dir"
|
|
|
|
#define PREF_KEY_DIR_WATCH_ENABLED "watch-dir-enabled"
|
|
|
|
|
|
|
|
|
2009-03-01 15:38:58 +00:00
|
|
|
static tr_bool closing = FALSE;
|
|
|
|
static tr_session * mySession = NULL;
|
2008-06-11 20:09:36 +00:00
|
|
|
|
2008-06-12 16:25:36 +00:00
|
|
|
/***
|
|
|
|
**** Config File
|
|
|
|
***/
|
2008-06-11 20:09:36 +00:00
|
|
|
|
2008-07-08 16:50:34 +00:00
|
|
|
static const char *
|
|
|
|
getUsage( void )
|
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
return "Transmission " LONG_VERSION_STRING
|
|
|
|
" http://www.transmissionbt.com/\n"
|
2008-07-08 16:50:34 +00:00
|
|
|
"A fast and easy BitTorrent client\n"
|
|
|
|
"\n"
|
2008-09-23 19:11:04 +00:00
|
|
|
MY_NAME " is a headless Transmission session\n"
|
2008-12-16 15:27:07 +00:00
|
|
|
"that can be controlled via transmission-remote or Clutch.\n"
|
|
|
|
"\n"
|
|
|
|
"Usage: " MY_NAME " [options]";
|
2008-07-08 16:50:34 +00:00
|
|
|
}
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
static const struct tr_option options[] =
|
|
|
|
{
|
2008-12-13 23:17:36 +00:00
|
|
|
{ 'a', "allowed", "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", 1, "<list>" },
|
|
|
|
{ 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL },
|
|
|
|
{ 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL },
|
2009-02-27 21:49:31 +00:00
|
|
|
{ 'c', "watch-dir", "Directory to watch for new .torrent files", "c", 1, "<directory>" },
|
|
|
|
{ 'C', "no-watch-dir", "Disable the watch-dir", "C", 0, NULL },
|
2008-12-14 01:22:06 +00:00
|
|
|
{ 'd', "dump-settings", "Dump the settings and exit", "d", 0, NULL },
|
2008-12-13 23:17:36 +00:00
|
|
|
{ 'f', "foreground", "Run in the foreground instead of daemonizing", "f", 0, NULL },
|
|
|
|
{ 'g', "config-dir", "Where to look for configuration files", "g", 1, "<path>" },
|
|
|
|
{ 'p', "port", "RPC port (Default: " TR_DEFAULT_RPC_PORT_STR ")", "p", 1, "<port>" },
|
|
|
|
{ 't', "auth", "Require authentication", "t", 0, NULL },
|
|
|
|
{ 'T', "no-auth", "Don't require authentication", "T", 0, NULL },
|
|
|
|
{ 'u', "username", "Set username for authentication", "u", 1, "<username>" },
|
|
|
|
{ 'v', "password", "Set password for authentication", "v", 1, "<password>" },
|
2009-01-23 19:36:34 +00:00
|
|
|
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
|
2008-12-13 23:17:36 +00:00
|
|
|
{ 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" },
|
2008-12-30 18:18:34 +00:00
|
|
|
{ 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", 1, "<port>" },
|
|
|
|
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL },
|
|
|
|
{ 'M', "no-portmap", "Disable portmapping", "M", 0, NULL },
|
|
|
|
{ 'L', "peerlimit-global", "Maximum overall number of peers (Default: " TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ")", "L", 1, "<limit>" },
|
|
|
|
{ 'l', "peerlimit-torrent", "Maximum number of peers per torrent (Default: " TR_DEFAULT_PEER_LIMIT_TORRENT_STR ")", "l", 1, "<limit>" },
|
|
|
|
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
|
|
|
|
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
|
|
|
|
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
|
2008-12-13 23:17:36 +00:00
|
|
|
{ 0, NULL, NULL, NULL, 0, NULL }
|
2008-07-08 16:50:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
static void
|
2008-07-08 16:50:34 +00:00
|
|
|
showUsage( void )
|
2008-05-18 16:44:30 +00:00
|
|
|
{
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_getopt_usage( MY_NAME, getUsage( ), options );
|
2007-04-18 16:39:10 +00:00
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
static void
|
|
|
|
gotsig( int sig UNUSED )
|
2008-02-28 19:06:23 +00:00
|
|
|
{
|
2008-05-18 16:44:30 +00:00
|
|
|
closing = TRUE;
|
|
|
|
}
|
2008-02-28 19:06:23 +00:00
|
|
|
|
2008-12-26 01:36:32 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
#define USE_NO_DAEMON
|
2009-01-12 20:01:37 +00:00
|
|
|
#elif !defined(HAVE_DAEMON) || defined(__UCLIBC__)
|
2008-12-26 01:36:32 +00:00
|
|
|
#define USE_TR_DAEMON
|
|
|
|
#else
|
|
|
|
#define USE_OS_DAEMON
|
|
|
|
#endif
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
static int
|
2008-12-25 22:06:48 +00:00
|
|
|
tr_daemon( int nochdir, int noclose )
|
2008-05-18 16:44:30 +00:00
|
|
|
{
|
2008-12-26 01:36:32 +00:00
|
|
|
#if defined(USE_OS_DAEMON)
|
2008-12-25 22:06:48 +00:00
|
|
|
return daemon( nochdir, noclose );
|
2008-12-26 01:36:32 +00:00
|
|
|
#elif defined(USE_TR_DAEMON)
|
2008-12-25 22:06:48 +00:00
|
|
|
pid_t pid = fork( );
|
|
|
|
if( pid < 0 )
|
2007-04-18 16:39:10 +00:00
|
|
|
return -1;
|
2008-12-25 22:06:48 +00:00
|
|
|
else if( pid > 0 )
|
|
|
|
_exit( 0 );
|
|
|
|
else {
|
|
|
|
pid = setsid( );
|
|
|
|
if( pid < 0 )
|
2008-05-18 16:44:30 +00:00
|
|
|
return -1;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-12-25 22:06:48 +00:00
|
|
|
pid = fork( );
|
|
|
|
if( pid < 0 )
|
|
|
|
return -1;
|
|
|
|
else if( pid > 0 )
|
2008-09-23 19:11:04 +00:00
|
|
|
_exit( 0 );
|
2008-12-25 22:06:48 +00:00
|
|
|
else {
|
|
|
|
|
|
|
|
if( !nochdir )
|
|
|
|
if( chdir( "/" ) < 0 )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
umask( (mode_t)0 );
|
|
|
|
|
|
|
|
if( !noclose ) {
|
|
|
|
/* send stdin, stdout, and stderr to /dev/null */
|
|
|
|
int i;
|
|
|
|
int fd = open( "/dev/null", O_RDWR, 0 );
|
|
|
|
for( i=0; i<3; ++i ) {
|
|
|
|
if( close( i ) )
|
|
|
|
return -1;
|
|
|
|
dup2( fd, i );
|
|
|
|
}
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-04-18 16:39:10 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-26 01:36:32 +00:00
|
|
|
#else /* USE_NO_DAEMON */
|
|
|
|
return 0;
|
2008-05-18 16:44:30 +00:00
|
|
|
#endif
|
2008-12-25 22:06:48 +00:00
|
|
|
}
|
2007-04-18 16:39:10 +00:00
|
|
|
|
2008-12-13 23:17:36 +00:00
|
|
|
static const char*
|
|
|
|
getConfigDir( int argc, const char ** argv )
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
const char * configDir = NULL;
|
|
|
|
const char * optarg;
|
|
|
|
const int ind = tr_optind;
|
|
|
|
|
2009-01-09 19:16:52 +00:00
|
|
|
while(( c = tr_getopt( getUsage( ), argc, argv, options, &optarg ))) {
|
|
|
|
if( c == 'g' ) {
|
2008-12-13 23:17:36 +00:00
|
|
|
configDir = optarg;
|
2009-01-09 19:16:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-13 23:17:36 +00:00
|
|
|
|
|
|
|
tr_optind = ind;
|
|
|
|
|
|
|
|
if( configDir == NULL )
|
|
|
|
configDir = tr_getDefaultConfigDir( MY_NAME );
|
|
|
|
|
|
|
|
return configDir;
|
|
|
|
}
|
|
|
|
|
2009-02-27 21:49:31 +00:00
|
|
|
static void
|
2009-03-01 15:38:58 +00:00
|
|
|
onFileAdded( tr_session * session, const char * dir, const char * file )
|
2009-02-27 21:49:31 +00:00
|
|
|
{
|
2009-03-01 15:38:58 +00:00
|
|
|
if( strstr( file, ".torrent" ) != NULL )
|
2009-02-27 21:49:31 +00:00
|
|
|
{
|
2009-03-01 15:38:58 +00:00
|
|
|
char * filename = tr_buildPath( dir, file, NULL );
|
|
|
|
tr_ctor * ctor = tr_ctorNew( session );
|
2009-02-28 15:27:39 +00:00
|
|
|
|
2009-03-01 15:38:58 +00:00
|
|
|
int err = tr_ctorSetMetainfoFromFile( ctor, filename );
|
|
|
|
if( !err )
|
|
|
|
tr_torrentNew( session, ctor, &err );
|
2009-02-28 14:43:37 +00:00
|
|
|
|
2009-03-01 15:38:58 +00:00
|
|
|
tr_ctorFree( ctor );
|
|
|
|
tr_free( filename );
|
2009-02-27 21:49:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
int
|
2009-02-27 21:49:31 +00:00
|
|
|
main( int argc, char ** argv )
|
2007-04-18 16:39:10 +00:00
|
|
|
{
|
2008-12-13 23:17:36 +00:00
|
|
|
int c;
|
2008-12-14 01:22:06 +00:00
|
|
|
int64_t i;
|
2008-12-13 23:17:36 +00:00
|
|
|
const char * optarg;
|
|
|
|
tr_benc settings;
|
|
|
|
tr_bool foreground = FALSE;
|
2008-12-14 01:22:06 +00:00
|
|
|
tr_bool dumpSettings = FALSE;
|
2008-07-08 16:50:34 +00:00
|
|
|
const char * configDir = NULL;
|
2009-03-01 15:38:58 +00:00
|
|
|
dtr_watchdir * watchdir = NULL;
|
2008-05-18 16:44:30 +00:00
|
|
|
|
|
|
|
signal( SIGINT, gotsig );
|
|
|
|
signal( SIGTERM, gotsig );
|
2008-10-13 22:26:02 +00:00
|
|
|
#ifndef WIN32
|
|
|
|
signal( SIGQUIT, gotsig );
|
2007-04-18 16:39:10 +00:00
|
|
|
signal( SIGPIPE, SIG_IGN );
|
|
|
|
signal( SIGHUP, SIG_IGN );
|
2008-10-13 22:26:02 +00:00
|
|
|
#endif
|
2007-04-18 16:39:10 +00:00
|
|
|
|
2008-12-13 23:17:36 +00:00
|
|
|
/* load settings from defaults + config file */
|
|
|
|
tr_bencInitDict( &settings, 0 );
|
|
|
|
configDir = getConfigDir( argc, (const char**)argv );
|
|
|
|
tr_sessionLoadSettings( &settings, configDir, MY_NAME );
|
2008-12-16 15:27:07 +00:00
|
|
|
tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_ENABLED, 1 );
|
2008-12-13 23:17:36 +00:00
|
|
|
|
|
|
|
/* overwrite settings from the comamndline */
|
|
|
|
tr_optind = 1;
|
|
|
|
while(( c = tr_getopt( getUsage(), argc, (const char**)argv, options, &optarg ))) {
|
|
|
|
switch( c ) {
|
|
|
|
case 'a': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_WHITELIST, optarg );
|
|
|
|
tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, 1 );
|
|
|
|
break;
|
|
|
|
case 'b': tr_bencDictAddInt( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, 1 );
|
|
|
|
break;
|
|
|
|
case 'B': tr_bencDictAddInt( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, 0 );
|
|
|
|
break;
|
2009-02-27 21:49:31 +00:00
|
|
|
case 'c': tr_bencDictAddStr( &settings, PREF_KEY_DIR_WATCH, optarg );
|
|
|
|
tr_bencDictAddInt( &settings, PREF_KEY_DIR_WATCH_ENABLED, 1 );
|
|
|
|
break;
|
|
|
|
case 'C': tr_bencDictAddInt( &settings, PREF_KEY_DIR_WATCH_ENABLED, 0 );
|
|
|
|
break;
|
2008-12-14 01:22:06 +00:00
|
|
|
case 'd': dumpSettings = TRUE;
|
|
|
|
break;
|
2008-12-13 23:17:36 +00:00
|
|
|
case 'f': foreground = TRUE;
|
|
|
|
break;
|
|
|
|
case 'g': /* handled above */
|
|
|
|
break;
|
2009-01-23 19:36:34 +00:00
|
|
|
case 'V': /* version */
|
|
|
|
fprintf(stderr, "Transmission %s\n", LONG_VERSION_STRING);
|
|
|
|
exit( 0 );
|
2008-12-13 23:17:36 +00:00
|
|
|
case 'p': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_PORT, atoi( optarg ) );
|
|
|
|
break;
|
2008-12-30 01:55:43 +00:00
|
|
|
case 't': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, 1 );
|
2008-12-13 23:17:36 +00:00
|
|
|
break;
|
2008-12-30 01:55:43 +00:00
|
|
|
case 'T': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, 0 );
|
2008-12-13 23:17:36 +00:00
|
|
|
break;
|
|
|
|
case 'u': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_USERNAME, optarg );
|
|
|
|
break;
|
|
|
|
case 'v': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_PASSWORD, optarg );
|
|
|
|
break;
|
|
|
|
case 'w': tr_bencDictAddStr( &settings, TR_PREFS_KEY_DOWNLOAD_DIR, optarg );
|
|
|
|
break;
|
2008-12-30 18:18:34 +00:00
|
|
|
case 'P': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_PORT, atoi( optarg ) );
|
|
|
|
break;
|
|
|
|
case 'm': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PORT_FORWARDING, 1 );
|
|
|
|
break;
|
|
|
|
case 'M': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PORT_FORWARDING, 0 );
|
|
|
|
break;
|
|
|
|
case 'L': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi( optarg ) );
|
|
|
|
break;
|
|
|
|
case 'l': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, atoi( optarg ) );
|
|
|
|
break;
|
|
|
|
case 910: tr_bencDictAddInt( &settings, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_REQUIRED );
|
|
|
|
break;
|
2008-12-30 22:26:05 +00:00
|
|
|
case 911: tr_bencDictAddInt( &settings, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_PREFERRED );
|
2008-12-30 18:18:34 +00:00
|
|
|
break;
|
2008-12-30 22:26:05 +00:00
|
|
|
case 912: tr_bencDictAddInt( &settings, TR_PREFS_KEY_ENCRYPTION, TR_CLEAR_PREFERRED );
|
2008-12-30 18:18:34 +00:00
|
|
|
break;
|
2008-12-13 23:17:36 +00:00
|
|
|
default: showUsage( );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-18 16:39:10 +00:00
|
|
|
|
2008-12-14 01:22:06 +00:00
|
|
|
if( dumpSettings )
|
|
|
|
{
|
2008-12-30 22:07:39 +00:00
|
|
|
struct evbuffer * buf = tr_getBuffer( );
|
|
|
|
|
|
|
|
tr_bencSaveAsJSON( &settings, buf );
|
|
|
|
fprintf( stderr, "%s", (char*)EVBUFFER_DATA(buf) );
|
|
|
|
|
|
|
|
tr_releaseBuffer( buf );
|
2008-12-14 01:22:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-26 01:36:32 +00:00
|
|
|
if( !foreground && tr_daemon( TRUE, FALSE ) < 0 )
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2008-12-26 01:36:32 +00:00
|
|
|
fprintf( stderr, "failed to daemonize: %s\n", strerror( errno ) );
|
|
|
|
exit( 1 );
|
2007-04-18 16:39:10 +00:00
|
|
|
}
|
2007-08-14 04:02:50 +00:00
|
|
|
|
2008-12-13 23:17:36 +00:00
|
|
|
/* start the session */
|
|
|
|
mySession = tr_sessionInit( "daemon", configDir, FALSE, &settings );
|
|
|
|
|
2008-12-14 01:22:06 +00:00
|
|
|
if( tr_bencDictFindInt( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, &i ) && i!=0 )
|
2008-12-13 23:17:36 +00:00
|
|
|
tr_ninf( MY_NAME, "requiring authentication" );
|
|
|
|
|
2009-02-27 21:49:31 +00:00
|
|
|
/* maybe add a watchdir */
|
|
|
|
{
|
|
|
|
int64_t doWatch;
|
2009-03-01 15:38:58 +00:00
|
|
|
const char * dir;
|
|
|
|
|
2009-02-27 21:49:31 +00:00
|
|
|
if( tr_bencDictFindInt( &settings, PREF_KEY_DIR_WATCH_ENABLED, &doWatch )
|
|
|
|
&& doWatch
|
2009-03-01 15:38:58 +00:00
|
|
|
&& tr_bencDictFindStr( &settings, PREF_KEY_DIR_WATCH, &dir )
|
|
|
|
&& dir
|
|
|
|
&& *dir )
|
2009-02-27 21:49:31 +00:00
|
|
|
{
|
2009-03-01 15:38:58 +00:00
|
|
|
tr_inf( "Watching \"%s\" for new .torrent files", dir );
|
|
|
|
watchdir = dtr_watchdir_new( mySession, dir, onFileAdded );
|
2009-02-27 21:49:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-13 23:17:36 +00:00
|
|
|
/* load the torrents */
|
|
|
|
{
|
|
|
|
tr_ctor * ctor = tr_ctorNew( mySession );
|
|
|
|
tr_torrent ** torrents = tr_sessionLoadTorrents( mySession, ctor, NULL );
|
|
|
|
tr_free( torrents );
|
|
|
|
tr_ctorFree( ctor );
|
|
|
|
}
|
2007-08-14 04:02:50 +00:00
|
|
|
|
2009-02-28 14:43:37 +00:00
|
|
|
while( !closing )
|
|
|
|
{
|
2008-10-13 22:26:02 +00:00
|
|
|
tr_wait( 1000 ); /* sleep one second */
|
2009-03-01 15:38:58 +00:00
|
|
|
dtr_watchdir_update( watchdir );
|
2009-02-27 21:49:31 +00:00
|
|
|
}
|
2007-08-14 04:02:50 +00:00
|
|
|
|
2008-12-13 23:17:36 +00:00
|
|
|
/* shutdown */
|
2008-05-18 16:44:30 +00:00
|
|
|
printf( "Closing transmission session..." );
|
2008-12-13 23:17:36 +00:00
|
|
|
tr_sessionSaveSettings( mySession, configDir, &settings );
|
2009-03-01 15:38:58 +00:00
|
|
|
dtr_watchdir_free( watchdir );
|
2008-05-22 19:24:11 +00:00
|
|
|
tr_sessionClose( mySession );
|
2008-05-18 16:44:30 +00:00
|
|
|
printf( " done.\n" );
|
2007-08-14 04:02:50 +00:00
|
|
|
|
2008-12-13 23:17:36 +00:00
|
|
|
/* cleanup */
|
|
|
|
tr_bencFree( &settings );
|
2007-08-14 04:02:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|