=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/NewTorrents.pl,v retrieving revision 1.1 retrieving revision 1.4 diff -u -r1.1 -r1.4 --- openbsd/OpenBSDTorrents/NewTorrents.pl 2005/03/24 05:28:08 1.1 +++ openbsd/OpenBSDTorrents/NewTorrents.pl 2005/03/28 23:36:44 1.4 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -#$Id: NewTorrents.pl,v 1.1 2005/03/24 05:28:08 andrew Exp $ +#$Id: NewTorrents.pl,v 1.4 2005/03/28 23:36:44 andrew Exp $ use strict; use warnings; use diagnostics; @@ -7,10 +7,14 @@ use lib 'lib'; use OpenBSDTorrents; +use POSIX 'setsid'; + %ENV = (); use YAML; +# *** This requires --log-format="%t [%p] %o %f %l" on the rsync command + my $last_dir = ''; while (<>) { chomp; @@ -20,12 +24,46 @@ my ($dir, $file) = $file =~ m#^(.*)/([^/]+)#; #print "$dir - $file\n"; if ($last_dir && $last_dir ne $dir) { - # This actually needs to be a sub that forks off - # the generation of this, and the running of the update script. - print "MakeTorrent.pl $BaseName/$dir\n"; + StartTorrent($last_dir); } $last_dir = $dir; } else { #print $_; } +} +StartTorrent($last_dir); + +sleep(300); + +StartTorrent('skip'); + + +sub StartTorrent +{ + my $dir = shift; + return undef unless $dir; + + if ($dir ne 'skip') { + $dir = "$BaseName/$dir"; + } else { + $dir = ''; + } + + # This actually needs to be a sub that forks off + # the generation of this, and the running of the update script. + + defined(my $pid = fork) or die "Can't fork: $!"; + + return if $pid; + + chdir $HomeDir or die "Can't chdir to $HomeDir: $!"; + + setsid or die "Can't start a new session: $!"; + #open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; + #open STDOUT, '>/dev/null' + # or die "Can't write /dev/null: $!"; + #open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; + + print "Making torrents for $dir\n"; + exec($HomeDir . '/regen.sh', "$dir"); }