Changeset 11534


Ignore:
Timestamp:
Dec 15, 2010, 4:35:41 AM (11 years ago)
Author:
charles
Message:

(trunk libT) #3764 "script-torrent-done shouldn't block libtransmission" -- fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r11529 r11534  
    18511851
    18521852static void
    1853 tr_setenv( const char * name, const char * value, tr_bool override )
    1854 {
    1855 #ifdef WIN32
    1856     putenv( tr_strdup_printf( "%s=%s", name, value ) ); /* leaks memory... */
    1857 #else
    1858     setenv( name, value, override );
    1859 #endif
    1860 }
    1861 
    1862 static void
    1863 torrentCallScript( tr_torrent * tor, const char * script )
    1864 {
    1865     assert( tr_isTorrent( tor ) );
     1853torrentCallScript( const tr_torrent * tor, const char * script )
     1854{
     1855    char timeStr[128];
     1856    const time_t now = tr_time( );
     1857
     1858    assert( tr_isTorrent( tor ) );
     1859
     1860    tr_strlcpy( timeStr, ctime( &now ), sizeof( timeStr ) );
     1861    *strchr( timeStr,'\n' ) = '\0';
    18661862
    18671863    if( script && *script )
    18681864    {
    1869         char buf[128];
    1870         const time_t now = tr_time( );
    1871 
    1872         tr_setenv( "TR_APP_VERSION", SHORT_VERSION_STRING, 1 );
    1873 
    1874         tr_snprintf( buf, sizeof( buf ), "%d", tr_torrentId( tor ) );
    1875         tr_setenv( "TR_TORRENT_ID", buf, 1 );
    1876         tr_setenv( "TR_TORRENT_NAME", tr_torrentName( tor ), 1 );
    1877         tr_setenv( "TR_TORRENT_DIR", tor->currentDir, 1 );
    1878         tr_setenv( "TR_TORRENT_HASH", tor->info.hashString, 1 );
    1879         tr_strlcpy( buf, ctime( &now ), sizeof( buf ) );
    1880         *strchr( buf,'\n' ) = '\0';
    1881         tr_setenv( "TR_TIME_LOCALTIME", buf, 1 );
    1882         tr_torinf( tor, "Calling script \"%s\"", script );
    1883         system( script );
     1865        char * cmd[] = { tr_strdup( script ), NULL };
     1866        char * env[] = { tr_strdup_printf( "TR_APP_VERSION=%s", SHORT_VERSION_STRING ),
     1867                         tr_strdup_printf( "TR_TIME_LOCALTIME=%s", timeStr ),
     1868                         tr_strdup_printf( "TR_TORRENT_DIR=%s", tor->currentDir ),
     1869                         tr_strdup_printf( "TR_TORRENT_ID=%d", tr_torrentId( tor ) ),
     1870                         tr_strdup_printf( "TR_TORRENT_HASH=%s", tor->info.hashString ),
     1871                         tr_strdup_printf( "TR_TORRENT_NAME=%s", tr_torrentName( tor ) ),
     1872                         NULL };
     1873        if( !fork( ) )
     1874        {
     1875            execve( script, cmd, env );
     1876            tr_torerr( tor, _( "Script failed with errno %d (%s)" ), errno, strerror(errno) );
     1877            _exit( 0 );
     1878        }
    18841879    }
    18851880}
Note: See TracChangeset for help on using the changeset viewer.