2 # processall dispatches incomming messages to process or service
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
6 # Copyright 2018 by Don Armstrong <don@donarmstrong.com>.
14 use Debbugs::Config qw(:config);
15 use Debbugs::Common qw(:lock);
16 use Filesys::Notify::Simple;
21 processall - dispatches incomming messages to process or service
28 --debug, -d debugging level (Default 0)
29 --help, -h display this help
30 --man, -m display manual
38 Debug verbosity. (Default 0)
42 Display brief usage information.
56 # Uses up: incoming/I<code><bugnum>.nn
57 # Temps: incoming/[GP].nn
58 # Creates: incoming/E.nn
64 my %options = (debug => 0,
70 'debug|d+','help|h|?','man|m');
72 pod2usage() if $options{help};
73 pod2usage({verbose=>2}) if $options{man};
75 $DEBUG = $options{debug};
79 push @USAGE_ERRORS,"This script takes no arguments";
82 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
84 my $lib_path = $config{lib_path};
86 chdir( $config{spool_dir} ) or
87 die "Unable to chdir to spool ($config{spool_dir}): $!\n";
89 if (not lockpid('processall.pid')) {
90 print STDERR "Another processall is running";
96 process_new_incoming();
97 # my $watcher = Filesys::Notify::Simple->new(['incomming']) or
98 # die "Unable to create new filesystem watcher";
101 # wait(\&process_new_incoming);
108 sub process_new_incoming {
110 print(STDERR "stop file created\n") || die $!;
114 opendir($dir,"incoming") or die $!;
116 map {s/^I//?$_:() } readdir($dir);
119 stat($config{maintainer_file}) or
120 die "Unable to stat Maintainer File '$config{maintainer_file}': $!";
121 foreach my $id (@ids) {
123 handle_incoming_message($id) and
132 sub handle_incoming_message {
134 unless (rename("incoming/I$id","incoming/G$id")) {
136 die "$id already fudged once! $!\n";
143 if ($id =~ m/^[RC]/) {
144 $handler = "service";
145 } elsif ($id =~ m/^[BMQFDUL]/) {
148 die "Invalid incomming ID type $id";
151 print(STDOUT "[$nf] $id $handler ...") or
153 my $exit = system("$lib_path/$handler",$id);
155 print STDOUT "failed to execute $lib_path/$handler: $!\n";
158 printf STDOUT "child died with signal %d, %s coredump\n",
159 ($? & 127), ($? & 128) ? 'with' : 'without';
161 printf STDOUT "$id: process failed (%d)\n", $? >> 8;
163 print(STDOUT " done\n") or die $!;
164 rmtree("$config{spool_dir}/mime.tmp",0,1);
169 system("$lib_path/gen-indices",'--quick') == 0 or print STDERR "gen-indices failed\n";
171 if (@{$config{post_processall}//[]}) {
172 system @{$config{post_processall}} == 0 or
173 print STDERR "\@gPostProcessall failed: ".join(' ',@{$config{post_processall}})."\n";
184 # indent-tabs-mode: nil
185 # cperl-indent-level: 4