mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
DEV: haring: add a new option "-r" to automatically repair broken files
In case a file-backed ring was not properly synced before being dumped, the output can look bogus due to the head pointer not being perfectly up to date. In this case, passing "-r" will make haring automatically skip entries not starting with a zero, and resynchronize with the rest of the messages. This should be backported to 2.6.
This commit is contained in:
parent
fb9a4765b7
commit
e06ba90318
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
int force = 0; // force access to a different layout
|
int force = 0; // force access to a different layout
|
||||||
int lfremap = 0; // remap LF in traces
|
int lfremap = 0; // remap LF in traces
|
||||||
|
int repair = 0; // repair file
|
||||||
|
|
||||||
|
|
||||||
/* display the message and exit with the code */
|
/* display the message and exit with the code */
|
||||||
@ -61,6 +62,7 @@ __attribute__((noreturn)) void usage(int code, const char *arg0)
|
|||||||
"options :\n"
|
"options :\n"
|
||||||
" -f : force accessing a non-matching layout for 'ring struct'\n"
|
" -f : force accessing a non-matching layout for 'ring struct'\n"
|
||||||
" -l : replace LF in contents with CR VT\n"
|
" -l : replace LF in contents with CR VT\n"
|
||||||
|
" -r : \"repair\" corrupted file (actively search for message boundaries)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"", arg0);
|
"", arg0);
|
||||||
}
|
}
|
||||||
@ -146,6 +148,14 @@ int dump_ring(struct ring *ring, size_t ofs, int flags)
|
|||||||
* stop before the end.
|
* stop before the end.
|
||||||
*/
|
*/
|
||||||
while (ofs + 1 < b_data(&buf)) {
|
while (ofs + 1 < b_data(&buf)) {
|
||||||
|
if (unlikely(repair && *b_peek(&buf, ofs))) {
|
||||||
|
/* in repair mode we consider that we could have landed
|
||||||
|
* in the middle of a message so we skip all bytes till
|
||||||
|
* the next zero.
|
||||||
|
*/
|
||||||
|
ofs++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
cnt = 1;
|
cnt = 1;
|
||||||
len = b_peek_varint(&buf, ofs + cnt, &msg_len);
|
len = b_peek_varint(&buf, ofs + cnt, &msg_len);
|
||||||
if (!len)
|
if (!len)
|
||||||
@ -219,6 +229,8 @@ int main(int argc, char **argv)
|
|||||||
force = 1;
|
force = 1;
|
||||||
else if (strcmp(argv[0], "-l") == 0)
|
else if (strcmp(argv[0], "-l") == 0)
|
||||||
lfremap = 1;
|
lfremap = 1;
|
||||||
|
else if (strcmp(argv[0], "-r") == 0)
|
||||||
|
repair = 1;
|
||||||
else if (strcmp(argv[0], "--") == 0)
|
else if (strcmp(argv[0], "--") == 0)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user