1 commit 0eb51736637f6c93a2fd6cb65316f8ae11f0a0be
2 Author: Todd Lyons <tlyons@exim.org>
3 Date: Fri Sep 12 06:22:24 2014 -0700
5 Bug 1216: Add -M (related) to exigrep.
7 Thanks to Arkadiusz for pointing out that this was never merged.
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;
15 my (%saved, %id_list, $pattern, $queue_time, $insensitive, $invert);
17 +# If using "related" option, have to track extra message IDs
24 # Convert syslog lines to mainlog format, as in eximstats.
25 @@ -90,8 +95,16 @@ if (defined $id)
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)
35 + get_related_ids($id) if $related;
37 + elsif ($related && $related_re)
39 + grep_for_related($_, $id);
43 # See if this is a completion for some message. If it is interesting,
44 @@ -173,16 +186,30 @@ sub detect_compressor_capable
48 +sub grep_for_related {
49 + my ($line,$id) = @_;
50 + $id_list{$id} = 1 if $line =~ m/$related_re/;
53 +sub get_related_ids {
55 + push @Mids, $id unless grep /\b$id\b/, @Mids;
56 + my $re = join '|', @Mids;
57 + $related_re = qr/$re/;
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).
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;
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"
77 $pattern = shift @ARGV;