]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #3961 "Support for running scripts when a torrent finishes downloading...
authorJordan Lee <jordan@transmissionbt.com>
Sun, 30 Jan 2011 01:41:48 +0000 (01:41 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sun, 30 Jan 2011 01:41:48 +0000 (01:41 +0000)
The changes to torrentCallScript() weren't portable to Windows, so rb07 has provided a patch.

libtransmission/torrent.c

index c4d49cf161a773a0dc1f52ed11e1956425380c18..9ba64f04057c81ad81584b253f4023a74243be48 100644 (file)
 
 #include <sys/types.h> /* stat */
 #include <sys/stat.h> /* stat */
-#include <sys/wait.h> /* wait() */
+#ifndef WIN32
+ #include <sys/wait.h> /* wait() */
+#else
+ #include <process.h>
+ #define waitpid(pid, status, options) _cwait(status, pid, WAIT_CHILD)
+#endif
 #include <unistd.h> /* stat */
 #include <dirent.h>
 
@@ -1941,7 +1946,7 @@ tr_torrentClearIdleLimitHitCallback( tr_torrent * torrent )
 static void
 onSigCHLD( int i UNUSED )
 {
-    waitpid( -1, 0, WNOHANG );
+    waitpid( -1, NULL, WNOHANG );
 }
 
 static void
@@ -1969,6 +1974,10 @@ torrentCallScript( const tr_torrent * tor, const char * script )
             NULL };
 
         tr_torinf( tor, "Calling script \"%s\"", script ); 
+
+#ifdef WIN32
+        _spawnvpe( _P_NOWAIT, script, (const char*)cmd, env );
+#else
         signal( SIGCHLD, onSigCHLD );
 
         if( !fork( ) )
@@ -1976,6 +1985,7 @@ torrentCallScript( const tr_torrent * tor, const char * script )
             execve( script, cmd, env );
             _exit( 0 );
         }
+#endif
 
         for( i=0; cmd[i]; ++i ) tr_free( cmd[i] );
         for( i=0; env[i]; ++i ) tr_free( env[i] );