]> granicus.if.org Git - transmission/commitdiff
#3686 "add rpc command to cleanly shutdown daemon" -- added for libT, tr-daemon,...
authorJordan Lee <jordan@transmissionbt.com>
Sat, 15 Jan 2011 18:12:45 +0000 (18:12 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 15 Jan 2011 18:12:45 +0000 (18:12 +0000)
daemon/daemon.c
daemon/remote.c
daemon/transmission-remote.1
extras/rpc-spec.txt
gtk/main.c
libtransmission/rpcimpl.c
libtransmission/transmission.h

index ab47db3c5e90b2834a6f7eaecbf4c0b06f066189..dffd54b329889ef4e924eff47c7507d124e2ba6f 100644 (file)
@@ -329,6 +329,17 @@ pumpLogMessages( FILE * logfile )
     tr_freeMessageList( list );
 }
 
+static tr_rpc_callback_status
+on_rpc_callback( tr_session            * session UNUSED,
+                 tr_rpc_callback_type    type,
+                 struct tr_torrent     * tor UNUSED,
+                 void                  * user_data UNUSED )
+{
+    if( type == TR_RPC_SESSION_CLOSE )
+        closing = TRUE;
+    return TR_RPC_OK;
+}
+
 int
 main( int argc, char ** argv )
 {
@@ -483,6 +494,7 @@ main( int argc, char ** argv )
     tr_formatter_size_init( DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR );
     tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR );
     mySession = tr_sessionInit( "daemon", configDir, TRUE, &settings );
+    tr_sessionSetRPCCallback( mySession, on_rpc_callback, NULL );
     tr_ninf( NULL, "Using settings from \"%s\"", configDir );
     tr_sessionSaveSettings( mySession, configDir, &settings );
 
index 0f14d5bc4719c08b825402dbcdcd7c89f7cbfc6f..f6143fa1ed10c16b38cc4b98a2db19cd68732191 100644 (file)
@@ -241,7 +241,7 @@ static tr_option opts[] =
     { 'e', "cache",                  "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", 1, "<size>" },
     { 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 },
+    { 850, "exit",                   "Tell the transmission session to shut down", NULL, 0, NULL },
     { 940, "files",                  "List the current torrent(s)' files", "f",  0, NULL },
     { 'g', "get",                    "Mark files for download", "g",  1, "<files>" },
     { 'G', "no-get",                 "Mark files for not downloading", "G",  1, "<files>" },
@@ -341,8 +341,9 @@ enum
     MODE_SESSION_SET           = (1<<9),
     MODE_SESSION_GET           = (1<<10),
     MODE_SESSION_STATS         = (1<<11),
-    MODE_BLOCKLIST_UPDATE      = (1<<12),
-    MODE_PORT_TEST             = (1<<13)
+    MODE_SESSION_CLOSE         = (1<<12),
+    MODE_BLOCKLIST_UPDATE      = (1<<13),
+    MODE_PORT_TEST             = (1<<14)
 };
 
 static int
@@ -445,6 +446,9 @@ getOptMode( int val )
         case 'w': /* download-dir */
             return MODE_SESSION_SET | MODE_TORRENT_ADD;
 
+        case 850: /* session-close */
+            return MODE_SESSION_CLOSE;
+
         case 963: /* blocklist-update */
             return MODE_BLOCKLIST_UPDATE;
 
@@ -2181,6 +2185,14 @@ processArgs( const char * rpcurl, int argc, const char ** argv )
                 tr_free( path );
                 break;
             }
+            case 850:
+            {
+                tr_benc * top = tr_new0( tr_benc, 1 );
+                tr_bencInitDict( top, 1 );
+                tr_bencDictAddStr( top, "method", "session-close" );
+                status |= flush( rpcurl, &top );
+                break;
+            }
             case 963:
             {
                 tr_benc * top = tr_new0( tr_benc, 1 );
index f103affd3229fb714fd57ea596dca5d31ccaf6db..7a43d8c6efe1149e167cd466853f93195e11d23d 100644 (file)
@@ -23,6 +23,7 @@ and
 .Op Fl d Ar number | Fl D
 .Op Fl e Ar size
 .Op Fl er | ep | et
+.Op Fl -exit
 .Op Fl f
 .Op Fl g Ar files
 .Op Fl G Ar files
@@ -134,6 +135,8 @@ Encrypt all peer connections.
 Prefer encrypted peer connections.
 .It Fl et Fl -encryption-tolerated
 Prefer unencrypted peer connections.
+.It Fl -exit
+Tell the Transmission to initiate a shutdown.
 .It Fl f Fl -files
 Get a file list for the current torrent(s)
 .It Fl g Fl -get Ar all | file-index | files
index e3bb811215adf2295964fc4947429eef1b0d7127..35ba35d81e78477b9bd81cdfe8587af270c16e0f 100644 (file)
    Request arguments: none
    Response arguments: a bool, "port-is-open"
 
+4.5.  Session shutdown
+
+   This method tells the transmission session to shut down.
+
+   Method-name: "session-close"
+   Request arguments: none
+   Response arguments: none
+
 5.0.  Protocol Versions
 
   The following changes have been made to the RPC interface:
          |         | yes       | session-set    | new arg "blocklist-url"
    ------+---------+-----------+----------------+-------------------------------
    12    | 2.20    | yes       | session-get    | new arg "download-dir-free-space"
+         |         | yes       | session-close  | new method
index 334f701def1cca439400fc83b33ff9248781c1e4..c7c867944b939dd757c60651c2139b67d9504311 100644 (file)
@@ -481,6 +481,10 @@ onRPCChanged( tr_session            * session,
 
     switch( type )
     {
+        case TR_RPC_SESSION_CLOSE:
+            gtr_action_activate( "quit" );
+            break;
+
         case TR_RPC_TORRENT_ADDED:
             tr_core_add_torrent( cbdata->core, tr_torrent_new_preexisting( tor ), TRUE );
             break;
index 19cfabdfc5d2ec0b5bd27498f28d3e62153260b6..bf2905c3aac3806e4c095e61e62d2f6d717d8ba9 100644 (file)
@@ -1624,6 +1624,20 @@ sessionGet( tr_session               * s,
 ****
 ***/
 
+static const char*
+sessionClose( tr_session               * session,
+              tr_benc                  * args_in UNUSED,
+              tr_benc                  * args_out UNUSED,
+              struct tr_rpc_idle_data  * idle_data UNUSED )
+{
+    notify( session, TR_RPC_SESSION_CLOSE, NULL );
+    return NULL;
+}
+
+/***
+****
+***/
+
 typedef const char* ( *handler )( tr_session*, tr_benc*, tr_benc*, struct tr_rpc_idle_data * );
 
 static struct method
@@ -1636,6 +1650,7 @@ methods[] =
 {
     { "port-test",             FALSE, portTest            },
     { "blocklist-update",      FALSE, blocklistUpdate     },
+    { "session-close",         TRUE,  sessionClose        },
     { "session-get",           TRUE,  sessionGet          },
     { "session-set",           TRUE,  sessionSet          },
     { "session-stats",         TRUE,  sessionStats        },
index 5b24a39141c4363096a3a6390b1068544fc609a4..aa9aa57475a5805a505ef23a4ab091ad3a84d02c 100644 (file)
@@ -498,7 +498,8 @@ typedef enum
     TR_RPC_TORRENT_REMOVING,
     TR_RPC_TORRENT_CHANGED, /* catch-all for the "torrent-set" rpc method */
     TR_RPC_TORRENT_MOVED,
-    TR_RPC_SESSION_CHANGED
+    TR_RPC_SESSION_CHANGED,
+    TR_RPC_SESSION_CLOSE
 }
 tr_rpc_callback_type;