[BACK]Return to NewTorrents.pl CVS log [TXT][DIR] Up to [local] / openbsd / OpenBSDTorrents

Annotation of openbsd/OpenBSDTorrents/NewTorrents.pl, Revision 1.4

1.1       andrew      1: #!/usr/bin/perl -T
1.4     ! andrew      2: #$Id: NewTorrents.pl,v 1.3 2005/03/25 03:13:45 andrew Exp andrew $
1.1       andrew      3: use strict;
                      4: use warnings;
                      5: use diagnostics;
                      6:
                      7: use lib 'lib';
                      8: use OpenBSDTorrents;
                      9:
1.3       andrew     10: use POSIX 'setsid';
                     11:
1.1       andrew     12: %ENV = ();
                     13:
                     14: use YAML;
                     15:
1.3       andrew     16: # *** This requires --log-format="%t [%p] %o %f %l" on the rsync command
                     17:
1.1       andrew     18: my $last_dir = '';
                     19: while (<>) {
                     20:        chomp;
                     21:        if (my ($year,  $mon,  $mday,   $time,               $pid,   $oper, $file, $size) =
                     22:            m#^(\d{4})/(\d{2})/(\d{2}) (\d{2}:\d{2}:\d{2}) \[(\d+)\] (\S+) (.+) (\d+)$# ) {
                     23:                #print "($year, $mon, $mday, $time, $pid, $oper, $file, $size)\n";
                     24:                my ($dir, $file) = $file =~ m#^(.*)/([^/]+)#;
                     25:                #print "$dir - $file\n";
                     26:                if ($last_dir && $last_dir ne $dir) {
1.2       andrew     27:                        StartTorrent($last_dir);
1.1       andrew     28:                }
                     29:                $last_dir = $dir;
                     30:        } else {
                     31:                #print $_;
                     32:        }
1.2       andrew     33: }
                     34: StartTorrent($last_dir);
                     35:
1.4     ! andrew     36: sleep(300);
1.3       andrew     37:
                     38: StartTorrent('skip');
                     39:
                     40:
1.2       andrew     41: sub StartTorrent
                     42: {
                     43:        my $dir = shift;
1.3       andrew     44:        return undef unless $dir;
1.2       andrew     45:
1.3       andrew     46:        if ($dir ne 'skip') {
                     47:                $dir = "$BaseName/$dir";
1.4     ! andrew     48:        } else {
        !            49:                $dir = '';
1.3       andrew     50:        }
                     51:
1.2       andrew     52:        # This actually needs to be a sub that forks off
                     53:        # the generation of this, and the running of the update script.
1.3       andrew     54:
                     55:        defined(my $pid = fork) or die "Can't fork: $!";
                     56:
                     57:        return if $pid;
                     58:
                     59:        chdir $HomeDir          or die "Can't chdir to $HomeDir: $!";
                     60:
                     61:        setsid                  or die "Can't start a new session: $!";
                     62:        #open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
                     63:        #open STDOUT, '>/dev/null'
                     64:        #                        or die "Can't write /dev/null: $!";
                     65:        #open STDERR, '>&STDOUT'        or die "Can't dup stdout: $!";
                     66:
1.4     ! andrew     67:        print "Making torrents for $dir\n";
        !            68:        exec($HomeDir . '/regen.sh', "$dir");
1.1       andrew     69: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>