Execute completion script on mips router linksys wag320n

Feature requests not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
gggsartori
Posts: 1
Joined: Sun Feb 17, 2013 3:18 pm

Execute completion script on mips router linksys wag320n

Post by gggsartori »

I have successfully compiled transmission 2.76+ on mips platform for my router, I had only a problem in executing the script upon torrent completion. I had a bash script that couldn't be executed and I wanted a mail as a notification of torrent completion.
The script works if executed manually but it didn't work if launched by transmission.
I put in settings.json:
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/harddisk/usb_2/Mail/endTorrent"

I discovered that transmission is unable to locate busybox even though it is present in the path so I modified settings.json this way

"script-torrent-done-filename": "/bin/busybox sh /harddisk/usb_2/Mail/endTorrent

To allow transmission to call a script with 2 arguments I changed the code of torrent.c in libtransmission:

from line 2057

//char * cmd[] = { tr_strdup (script), NULL };
char * cmd[5];
char * env[] = {
tr_strdup_printf ("TR_APP_VERSION=%s", SHORT_VERSION_STRING),
tr_strdup_printf ("TR_TIME_LOCALTIME=%s", timeStr),
tr_strdup_printf ("TR_TORRENT_DIR=%s", tor->currentDir),
tr_strdup_printf ("TR_TORRENT_ID=%d", tr_torrentId (tor)),
tr_strdup_printf ("TR_TORRENT_HASH=%s", tor->info.hashString),
tr_strdup_printf ("TR_TORRENT_NAME=%s", tr_torrentName (tor)),
NULL };

for (i=0,j=0,k=0;scriptTmp!='\0' && i<(int) sizeof(scriptTmp);i++)
{
if (scriptTmp==' ')
{
scriptTmp='\0';
cmd[k]=tr_strdup (&scriptTmp[j]);
j=i+1;
k++;
}
}
cmd[k]=tr_strdup (&scriptTmp[j]);
k++;
cmd[k]=NULL;

tr_logAddTorInfo (tor, "Calling script \"%s\"", script);

#ifdef WIN32
if (_spawnvpe (_P_NOWAIT, script, (const char*)cmd, env) == -1)
tr_logAddTorErr (tor, "error executing script \"%s\": %s", cmd[0], tr_strerror (errno));
#else
signal (SIGCHLD, onSigCHLD);

if (!fork ())
{
for (i=0; env; ++i)
putenv (env);

if (execvp (cmd[0], &cmd[1]) == -1)
//if (execvp (script, cmd) == -1)
tr_logAddTorErr (tor, "error executing script \"%s\": %s", cmd[0], tr_strerror (errno));
_exit (0);
}
#endif


Is it possible to execute script with parameters without changing the source code ?
Post Reply