2 # $Id: errorlib.in,v 1.19 2003/05/03 20:01:20 doogie Exp $
4 sub F_SETLK { 6; } sub F_WRLCK{ 1; }
5 $flockstruct= 'sslll'; # And there ought to be something for this too.
8 return "" if ( $_[ 0 ] < 0 );
9 return sprintf "%02d", $_[ 0 ] % 100;
12 sub unlockreadbugmerge {
14 &unfilelock if $rv >= 2;
15 &unfilelock if $rv >= 1;
18 sub lockreadbugmerge {
19 local ($lref, $location) = @_;
21 if (!($data = &lockreadbug($lref, $location))) { return ( 0, undef ); }
22 if (!length($data{mergedwith})) { return ( 1, $data ); }
24 &filelock('lock/merge');
25 if (!&lockreadbug($lref, $location)) { &unfilelock; return ( 0, undef ); }
30 local ($lref, $location) = @_;
31 my $hash = get_hashname($lref);
32 if ($location eq 'archive') {
37 if (!open(S,"$path/$hash/$lref.status")) { &unfilelock; return undef; }
39 chop($data{originator}= <S>);
40 chop($data{date}= <S>);
41 chop($data{subject}= <S>);
42 chop($data{msgid}= <S>);
43 chop($data{package}= <S>);
44 chop($data{keywords}= <S>);
45 chop($data{done}= <S>);
46 chop($data{forwarded}= <S>);
47 chop($data{mergedwith}= <S>);
48 chop($data{severity}= <S>);
49 chop($data{versions}= <S>);
50 chop($data{fixed_versions}= <S>);
52 $data{severity} = 'normal' if $data{severity} eq '';
57 local ($lref, $location) = @_;
58 &filelock("lock/$lref");
59 return readbug($lref, $location);
63 local ($ref, $data, $location) = @_;
64 my $hash = get_hashname($ref);
66 if ($location eq 'archive') {
71 open(S,">$path/$hash/$ref.status.new") || &quit("opening $path/$hash/$ref.status.new: $!");
73 "$data->{originator}\n".
78 "$data->{keywords}\n".
80 "$data->{forwarded}\n".
81 "$data->{mergedwith}\n".
82 "$data->{severity}\n".
83 "$data->{versions}\n".
84 "$data->{fixed_versions}\n") || &quit("writing $path/$hash/$ref.status.new: $!");
85 close(S) || &quit("closing $path/$hash/$ref.status.new: $!");
86 if (-e "$path/$hash/$ref.status") {
91 rename("$path/$hash/$ref.status.new","$path/$hash/$ref.status") ||
92 &quit("installing new $path/$hash/$ref.status: $!");
93 &bughook($change,$ref,
94 "$data->{originator}\n".
99 "$data->{keywords}\n".
101 "$data->{forwarded}\n".
102 "$data->{mergedwith}\n".
103 "$data->{severity}\n".
104 "$data->{versions}\n".
105 "$data->{fixed_versions}\n");
110 # NB - NOT COMPATIBLE WITH `with-lock'
111 local ($lockfile,$flockpushno,$evalstring,$count,$errors,@s1,@s2) = @_;
112 $flockpushno= $#filelocks+1;
113 $count= 10; $errors= '';
116 open(FLOCK${flockpushno},\"> \$lockfile\") || die \"open: \$!\";
117 \$flockwant= pack(\$flockstruct,&F_WRLCK,0,0,1,0);".
119 fcntl(FLOCK$flockpushno,&F_SETLK,\$flockwant) || die \"setlk: \$!\";" : "
120 \$z= syscall(&SYS_fcntl,fileno(FLOCK$flockpushno),&F_SETLK,\$flockwant) < 0
121 && die \"syscall fcntl setlk: \$!\";") ."
122 (\@s1= lstat(\$lockfile)) || die \"lstat: \$!\";
123 (\@s2= stat(FLOCK$flockpushno)) || die \"fstat: \$!\";
124 join(',',\@s1) eq join(',',\@s2) || die \"file switched\";
127 last if eval $evalstring;
129 eval "close(FLOCK$flockpushno);";
132 &quit("failed to get lock on file $lockfile: $errors // $evalstring");
136 push(@cleanups,'unfilelock');
137 push(@filelocks,$lockfile);
141 local ($lockfile) = pop(@filelocks);
143 eval 'close(FLOCK'.($#filelocks+1).');' || warn "failed to close lock file: $!";
144 unlink($lockfile) || warn "failed to remove lock file: $!";
148 print DEBUG "quitting >$_[0]<\n";
150 while ($u= $cleanups[$#cleanups]) { &$u; }
154 %saniarray= ('<','lt', '>','gt', '&','amp', '"','quot');
159 while ($in =~ m/[<>&"]/) {
160 $out.= $`. '&'. $saniarray{$&}. ';';
167 sub update_realtime {
168 my ($file, $bug, $new) = @_;
170 # update realtime index.db
172 open(IDXDB, "<$file") or die "Couldn't open $file";
173 open(IDXNEW, ">$file.new");
176 while($line = <IDXDB>) {
177 my @line = split /\s/, $line;
178 last if ($line[1] == $ref);
182 if ($new eq "NOCHANGE") {
184 } elsif ($new eq "REMOVE") {
190 print IDXNEW while(<IDXDB>);
195 rename("$file.new", $file);
200 sub bughook_archive {
202 &filelock("debbugs.trace.lock");
203 &appendfile("debbugs.trace","archive $ref\n");
204 my $line = update_realtime(
205 "$gSpoolDir/index.db.realtime",
208 update_realtime("$gSpoolDir/index.archive.realtime",
214 my ( $type, $ref ) = ( shift, shift );
215 &filelock("debbugs.trace.lock");
217 &appendfile("debbugs.trace","$type $ref\n",@_);
219 my @stuff=split /\n/, "$_[0]\n\n\n\n\n\n\n";
222 my $whendone = "open";
223 my $severity = $gDefaultSeverity;
224 ($firstpkg = $stuff[4]) =~ s/[,\s].*$//;
225 $whendone = "forwarded" if length $stuff[7];
226 $whendone = "done" if length $stuff[6];
227 $severity = $stuff[9] if length $stuff[9];
229 my $k = sprintf "%s %d %d %s [%s] %s %s\n",
230 $firstpkg, $ref, $stuff[1], $whendone, $stuff[0],
231 $severity, $stuff[5];
233 update_realtime("$gSpoolDir/index.db.realtime", $ref, $k);
240 if (!open(AP,">>$file")) {
241 print DEBUG "failed open log<\n";
242 print DEBUG "failed open log err $!<\n";
243 &quit("opening $file (appendfile): $!");
245 print(AP @_) || &quit("writing $file (appendfile): $!");
246 close(AP) || &quit("closing $file (appendfile): $!");
251 my $type = $entity->effective_type;
252 if ($type eq 'text/plain' or
253 ($type =~ m#text/# and $type ne 'text/html') or
254 $type eq 'application/pgp') {
255 return $entity->bodyhandle;
256 } elsif ($type eq 'multipart/alternative') {
257 # RFC 2046 says we should use the last part we recognize.
258 for my $part (reverse $entity->parts) {
259 my $ret = getmailbody($part);
263 # For other multipart types, we just pretend they're
264 # multipart/mixed and run through in order.
265 for my $part ($entity->parts) {
266 my $ret = getmailbody($part);
275 map { s/^([\01-\07\030])/\030$1/gm } @log;
280 @severities= grep { not exists $gObsoleteSeverities{$_} } @gSeverityList;
281 @showseverities= @severities;
282 grep ($_= $_ eq '' ? $gDefaultSeverity : $_, @showseverities);
283 @strongseverities= @gStrongSeverities;
284 %displayshowseverities= %gSeverityDisplay;