package: haproxy
[packages.git] / net / haproxy / patches / 0012-BUG-halog-fix-broken-output-limitation-1.4.22.diff
1 From e1e14b5d2a0ff3097c93f4605f33b38df1e3e266 Mon Sep 17 00:00:00 2001
2 From: Willy Tarreau <w@1wt.eu>
3 Date: Tue, 13 Nov 2012 20:48:15 +0100
4 Subject: BUG: halog: fix broken output limitation
5
6 Commit 667c905f introduced parameter -m to halog which limits the size
7 of the output. Unfortunately it is completely broken in that it doesn't
8 check that the limit was previously set or not, and also prevents a
9 simple counting operation from returning anything if a limit is not set.
10
11 Note that the -gt and -pct outputs behave differently in face of this
12 limit, since they count the valid output lines BEFORE actually producing
13 the data, so the limit really applies to valid input lines.
14 (cherry picked from commit a1629a59d17208897622d4e0d8ecddf157d55074)
15 ---
16  contrib/halog/halog.c |   26 +++++++++++---------------
17  1 files changed, 11 insertions(+), 15 deletions(-)
18
19 diff --git a/contrib/halog/halog.c b/contrib/halog/halog.c
20 index 7e16cd5..61034ec 100644
21 --- a/contrib/halog/halog.c
22 +++ b/contrib/halog/halog.c
23 @@ -708,11 +708,11 @@ int main(int argc, char **argv)
24         posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL);
25  #endif
26  
27 -       if (!line_filter && lines_max >= 0 &&
28 +       if (!line_filter && /* FILT_COUNT_ONLY ( see above), and no input filter (see below) */
29             !(filter & (FILT_HTTP_ONLY|FILT_TIME_RESP|FILT_ERRORS_ONLY|FILT_HTTP_STATUS|FILT_QUEUE_ONLY|FILT_QUEUE_SRV_ONLY|FILT_TERM_CODE_NAME))) {
30 -               /* read the whole file at once first */
31 +               /* read the whole file at once first, ignore it if inverted output */
32                 if (!filter_invert)
33 -                       while (fgets2(stdin) != NULL)
34 +                       while ((lines_max < 0 || lines_out < lines_max) && fgets2(stdin) != NULL)
35                                 lines_out++;
36  
37                 goto skip_filters;
38 @@ -872,8 +872,8 @@ int main(int argc, char **argv)
39                 if (line_filter)
40                         line_filter(accept_field, time_field, &t);
41                 else
42 -                       lines_out++; /* we're just counting lines */
43 -               if (lines_out >= lines_max)
44 +                       lines_out++; /* FILT_COUNT_ONLY was used, so we're just counting lines */
45 +               if (lines_max >= 0 && lines_out >= lines_max)
46                         break;
47         }
48  
49 @@ -914,7 +914,7 @@ int main(int argc, char **argv)
50                                 m = h % 60; h = h / 60;
51                                 printf("%02d:%02d:%02d.%03d %d %d %d\n", h, m, s, ms, last, d, t->count);
52                                 lines_out++;
53 -                               if (lines_out >= lines_max)
54 +                               if (lines_max >= 0 && lines_out >= lines_max)
55                                         break;
56                         }
57                         n = eb32_next(n);
58 @@ -944,12 +944,8 @@ int main(int argc, char **argv)
59                                 else
60                                         d = val;
61  
62 -                               if (d > 0.0) {
63 +                               if (d > 0.0)
64                                         printf("%d %d %f\n", f, last, d+1.0);
65 -                                       lines_out++;
66 -                                       if (lines_out >= lines_max)
67 -                                               break;
68 -                               }
69  
70                                 n = eb32_next(n);
71                         }
72 @@ -1006,7 +1002,7 @@ int main(int argc, char **argv)
73                         t = container_of(n, struct timer, node);
74                         printf("%d %d\n", n->key, t->count);
75                         lines_out++;
76 -                       if (lines_out >= lines_max)
77 +                       if (lines_max >= 0 && lines_out >= lines_max)
78                                 break;
79                         n = eb32_next(n);
80                 }
81 @@ -1035,7 +1031,7 @@ int main(int argc, char **argv)
82                                (int)(srv->cum_ct / (srv->nb_ct?srv->nb_ct:1)), (int)(srv->cum_rt / (srv->nb_rt?srv->nb_rt:1)));
83                         srv_node = ebmb_next(srv_node);
84                         lines_out++;
85 -                       if (lines_out >= lines_max)
86 +                       if (lines_max >= 0 && lines_out >= lines_max)
87                                 break;
88                 }
89         }
90 @@ -1046,7 +1042,7 @@ int main(int argc, char **argv)
91                         t = container_of(n, struct timer, node);
92                         printf("%c%c %d\n", (n->key >> 8), (n->key) & 255, t->count);
93                         lines_out++;
94 -                       if (lines_out >= lines_max)
95 +                       if (lines_max >= 0 && lines_out >= lines_max)
96                                 break;
97                         n = eb32_next(n);
98                 }
99 @@ -1110,7 +1106,7 @@ int main(int argc, char **argv)
100  
101                         node = eb_prev(node);
102                         lines_out++;
103 -                       if (lines_out >= lines_max)
104 +                       if (lines_max >= 0 && lines_out >= lines_max)
105                                 break;
106                 }
107         }
108 -- 
109 1.7.1
110