]> git.pld-linux.org Git - packages/exim.git/blob - exim-exigrep.patch
- rel 3; add -M option (looks for related msgs, too) to exigrep
[packages/exim.git] / exim-exigrep.patch
1 commit 0eb51736637f6c93a2fd6cb65316f8ae11f0a0be
2 Author: Todd Lyons <tlyons@exim.org>
3 Date:   Fri Sep 12 06:22:24 2014 -0700
4
5     Bug 1216: Add -M (related) to exigrep.
6     
7     Thanks to Arkadiusz for pointing out that this was never merged.
8
9 diff --git a/src/src/exigrep.src b/src/src/exigrep.src
10 index 2d3b40c..419fcb5 100644
11 --- a/src/src/exigrep.src
12 +++ b/src/src/exigrep.src
13 @@ -60,6 +60,11 @@ return $seconds;
14  
15  my (%saved, %id_list, $pattern, $queue_time, $insensitive, $invert);
16  
17 +# If using "related" option, have to track extra message IDs
18 +my $related;
19 +my $related_re='';
20 +my @Mids = ();
21 +
22  sub do_line {
23  
24  # Convert syslog lines to mainlog format, as in eximstats.
25 @@ -90,8 +95,16 @@ if (defined $id)
26      }
27    else
28      {
29 -    $id_list{$id} = 1 if defined $id_list{$id} ||
30 -      ($insensitive && /$pattern/io) || /$pattern/o;
31 +    if (defined $id_list{$id} ||
32 +      ($insensitive && /$pattern/io) || /$pattern/o)
33 +      {
34 +      $id_list{$id} = 1;
35 +      get_related_ids($id) if $related;
36 +      }
37 +    elsif ($related && $related_re)
38 +      {
39 +      grep_for_related($_, $id);
40 +      }
41      }
42  
43    # See if this is a completion for some message. If it is interesting,
44 @@ -173,16 +186,30 @@ sub detect_compressor_capable
45    return $cmdline;
46    }
47  
48 +sub grep_for_related {
49 +  my ($line,$id) = @_;
50 +  $id_list{$id} = 1 if $line =~ m/$related_re/;
51 +}
52 +
53 +sub get_related_ids {
54 +  my ($id) = @_;
55 +  push @Mids, $id unless grep /\b$id\b/, @Mids;
56 +  my $re = join '|', @Mids;
57 +  $related_re = qr/$re/;
58 +}
59 +
60  # The main program. Extract the pattern and make sure any relevant characters
61  # are quoted if the -l flag is given. The -t flag gives a time-on-queue value
62 -# which is an additional condition.
63 +# which is an additional condition. The -M flag will also display "related"
64 +# loglines (msgid from matched lines is searched in following lines).
65  
66 -getopts('Ilvt:',\my %args);
67 +getopts('Ilvt:M',\my %args);
68  $queue_time  = $args{'t'}? $args{'t'} : -1;
69  $insensitive = $args{'I'}? 0 : 1;
70  $invert      = $args{'v'}? 1 : 0;
71 +$related     = $args{'M'}? 1 : 0;
72  
73 -die "usage: exigrep [-I] [-l] [-t <seconds>] [-v] <pattern> [<log file>]...\n"
74 +die "usage: exigrep [-I] [-l] [-M] [-t <seconds>] [-v] <pattern> [<log file>]...\n"
75    if ($#ARGV < 0);
76  
77  $pattern = shift @ARGV;
This page took 0.032142 seconds and 3 git commands to generate.