]> git.donarmstrong.com Git - debbugs.git/blob - scripts/processall.in
[project @ 2002-10-06 22:54:48 by cjwatson]
[debbugs.git] / scripts / processall.in
1 #!/usr/bin/perl
2 # $Id: processall.in,v 1.8 2002/10/06 22:54:48 cjwatson Exp $
3 #
4 # Usage: processall
5 #
6 # Uses up: incoming/I<code><bugnum>.nn
7 # Temps:   incoming/[GP].nn
8 # Creates: incoming/E.nn
9 # Stop;    process/stop
10
11 $config_path = '/org/bugs.debian.org/etc';
12 $lib_path = '/org/bugs.debian.org/scripts';
13
14 require "$config_path/config";
15 require "$lib_path/errorlib";
16 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
17
18 use File::Path;
19
20 chdir( "$gSpoolDir" ) || die 'chdir spool: $!\n';
21 push( @INC, "$lib_path" );
22
23 #open(DEBUG,">&4");
24
25 umask(002);
26
27 $|=1;
28 undef %fudged;
29
30 &filelock('incoming-cleaner');
31 for (;;) {
32     if (-f 'stop') {
33         print(STDERR "stop file created\n") || die $!;
34         last;
35     }
36     if (!@ids) {
37         opendir(DIR,"incoming") || die $!;
38         while ( defined( $_= readdir(DIR) )) { push(@ids,$_) if s/^I//; }
39         last unless @ids;
40         @ids= sort(@ids);
41     }
42     stat("$gMaintainerFile") || die "stat $gMaintainerFile: $!\n";
43     $nf= @ids;
44     $id= shift(@ids);
45     unless (rename("incoming/I$id","incoming/G$id")) {
46         if ($fudged{$id}) {
47             die "$id already fudged once! $!\n";
48         }
49         $fudged{$id}= 1;
50         next;
51     }
52     if ($id =~ m/^[RC]/) {
53         print(STDOUT "[$nf] $id service ...") || die $!;
54         defined($c=fork) || die $!;
55         if (!$c) { exec("$lib_path/service",$id); die $!; }
56     } elsif ($id =~ m/^[BMQFDU]/) {
57         print(STDOUT "[$nf] $id process ...") || die $!;
58         defined($c=fork) || die $!;
59         if (!$c) { exec("$lib_path/process",$id); die $!; }
60     } else {
61         die "bad name $id";
62     }
63     $cc=waitpid($c,0); $cc == $c || die "$cc $c $!";
64     $status=$?;
65     if ($status) {
66         print(STDERR "$id: process failed ($status $!) - now in [PG]$id\n") || die $!;
67     }
68     print(STDOUT " done\n") || die $!;
69     rmtree("$gSpoolDir/mime.tmp",0,1);
70     $ndone++;
71 }
72 &unfilelock;
73
74 exit(0);