--- rss-tl.pl	2005-04-16 08:59:37.436127872 -0700
+++ /home/nemesis/bin/rss-tl.pl	2005-04-16 09:12:26.000000000 -0700
@@ -24,6 +24,7 @@ use XML::RAI;
 my $rss_url = 'http://www.btefnet.org/backend.php';
 my $refreshtime = 30;
 my $dir = '/tmp';
+my $dest = '.';
 my $regexps = '';
 my $debug;
 my $client;
@@ -41,12 +42,13 @@ sub load_options
 {
     open(OPTIONS,"<$cfg_file") or 0;
     while (<OPTIONS>) {
-        if ($_ =~ /dir=/) { ($null,$dir) = split(/=/); chop($dir); }
-        if ($_ =~ /rss_url=/) { ($null,$rss_url) = split(/=/); chop($rss_url); }
-        if ($_ =~ /refreshtime=/) { ($null,$refreshtime) = split(/=/); chop($refreshtime); }
-        if ($_ =~ /client=/) { ($null,$client) = split(/=/); chop($client); }
-        if ($_ =~ /regexps=/) { ($null,$regexps) = split(/=/); chop($regexps); }
-        if ($_ =~ /debug=/) { ($null,$debug) = split(/=/); chop($debug); }
+        if ($_ =~ /^dir=/) { ($null,$dir) = split(/=/,$_,2); chomp($dir); }
+        if ($_ =~ /^dest=/) { ($null,$dest) = split(/=/,$_,2); chomp($dest); }
+        if ($_ =~ /^rss_url=/) { ($null,$rss_url) = split(/=/,$_,2); chomp($rss_url); }
+        if ($_ =~ /^refreshtime=/) { ($null,$refreshtime) = split(/=/,$_,2); chomp($refreshtime); }
+        if ($_ =~ /^client=/) { ($null,$client) = split(/=/,$_,2); chomp($client); }
+        if ($_ =~ /^regexps=/) { ($null,$regexps) = split(/=/,$_,2); chomp($regexps); }
+        if ($_ =~ /^debug=/) { ($null,$debug) = split(/=/,$_,2); chomp($debug); }
     }
     close(OPTIONS);
     1;
@@ -75,6 +77,28 @@ sub dnl_file {
 	return ($rc);
 }
 
+sub dnl_start {
+	@_ == 1 || die "wrong number of args";
+	my ($file) = @_;
+
+	my $pid = fork();
+	if ($pid < 0) {
+		die "fork failed: $!\n";
+	}
+	elsif ($pid > 0) {
+		return;
+	}
+
+	close STDIN;
+	close STDOUT;
+	close STDERR;
+
+	exec $client, $file;
+	
+	warn "exec failed: $!\n";
+	exit(0);
+}
+
 sub dnl_torrents {
 	my $feed = XML::RAI->parsefile($xml_file);
 	my $count = $feed->item_count();
@@ -111,7 +135,7 @@ sub dnl_torrents {
 								if ($client) {
 									if ( -x $client) {
 										printf $fmt, "Run", "Starting $client $file";
-										system("$client $file >/dev/null 2>&1 &");
+										dnl_start($file);
 									} else {
 										printf STDERR $fmt, "Run", "Error \"$client\" is not an executable file.";
 									}
@@ -130,6 +154,7 @@ sub dnl_torrents {
 }
 
 sub rss_refresh {
+	chdir($dest);
 	if ($rss_url =~ /^$/) { die "rss_url was empty." }
 	printf $fmt, "Time", scalar localtime;
 	if (dnl_file($rss_url,$xml_file) == 0) {
@@ -187,7 +212,11 @@ Show the version number and exit.
 
 =item dir=
 
-Directory where to save downladed Torrents.
+Directory where to save downloaded .torrent files.
+
+=item dest=
+
+Directory where to save downloaded media.
 
 =item rss_url=
 
