]> git.pld-linux.org Git - packages/exim.git/blob - exim-bug-659.patch
- rel 13; exigrep patch updated
[packages/exim.git] / exim-bug-659.patch
1 diff --git a/src/src/exigrep.src b/src/src/exigrep.src
2 index 0950b58..9e0ced3 100644
3 --- a/src/src/exigrep.src
4 +++ b/src/src/exigrep.src
5 @@ -124,6 +124,60 @@ elsif ( ($invert && (($insensitive && !/$pattern/io) || !/$pattern/o)) ||
6    { print "$_\n"; }
7  }
8  
9 +# Rotated log files are frequently compressed and there are a variety of
10 +# formats it could be compressed with. Rather than use just one that is
11 +# detected and hardcoded at Exim compile time, detect and use what the
12 +# logfile is compressed with on the fly.
13 +#
14 +# List of known compression extensions and their associated commands:
15 +my $compressors = {
16 +  gz   => { cmd => 'zcat',  args => '' },
17 +  bz2  => { cmd => 'bzcat', args => '' },
18 +  xz   => { cmd => 'xzcat', args => '' },
19 +  lzma => { cmd => 'lzma',  args => '-dc' }
20 +};
21 +my $csearch = 0;
22 +
23 +sub detect_compressor_bin
24 +  {
25 +  my $ext = shift();
26 +  my $c = $compressors->{$ext}->{cmd};
27 +  $compressors->{$ext}->{bin} = `which $c 2>/dev/null`;
28 +  chomp($compressors->{$ext}->{bin});
29 +  }
30 +
31 +sub detect_compressor_capable
32 +  {
33 +  my $filename = shift();
34 +  map { &detect_compressor_bin($_) } keys %$compressors
35 +    if (!$csearch);
36 +  $csearch = 1;
37 +  return undef
38 +    unless (grep {$filename =~ /\.(?:$_)$/} keys %$compressors);
39 +  # Loop through them, figure out which one it detected,
40 +  # and build the commandline.
41 +  my $cmdline = undef;
42 +  foreach my $ext (keys %$compressors)
43 +    {
44 +    if ($filename =~ /\.(?:$ext)$/)
45 +      {
46 +      # Undecided:
47 +      # 1) Better to just print the error and return...
48 +      if ($compressors->{$ext}->{bin} eq '')
49 +        {
50 +        warn("Didn't find $ext decompressor for $filename\n");
51 +        return undef;
52 +        }
53 +      # 2) ...or just return undef that will result in no output
54 +      $cmdline = ($compressors->{$ext}->{bin} eq '') ?
55 +                 undef :
56 +                 $compressors->{$ext}->{bin} ." ".
57 +                   $compressors->{$ext}->{args};
58 +      last;
59 +      }
60 +    }
61 +  return $cmdline;
62 +  }
63  
64  # The main program. Extract the pattern and make sure any relevant characters
65  # are quoted if the -l flag is given. The -t flag gives a time-on-queue value
66 @@ -154,6 +208,11 @@ if (@ARGV)
67        open(LOG, "ZCAT_COMMAND $filename |") ||
68          die "Unable to zcat $filename: $!\n";
69        }
70 +    elsif (my $cmdline = &detect_compressor_capable($filename))
71 +      {
72 +      open(LOG, "$cmdline $filename |") ||
73 +        die "Unable to decompress $filename: $!\n";
74 +      }
75      else
76        {
77        open(LOG, "<$filename") || die "Unable to open $filename: $!\n";
This page took 0.038962 seconds and 4 git commands to generate.