!53 [sync] PR-49: Fix location tracking in gdbmtool. Fix the recover command
From: @openeuler-sync-bot Reviewed-by: @liuzhiqiang26 Signed-off-by: @liuzhiqiang26
This commit is contained in:
commit
2defeb2242
453
0002-Fix-location-tracking-in-gdbmtool.-Fix-the-recover-c.patch
Normal file
453
0002-Fix-location-tracking-in-gdbmtool.-Fix-the-recover-c.patch
Normal file
@ -0,0 +1,453 @@
|
||||
From b8271d89db991558e10c26d45d960bbc0257fa31 Mon Sep 17 00:00:00 2001
|
||||
From: Sergey Poznyakoff <gray@gnu.org>
|
||||
Date: Sat, 18 Jun 2022 17:18:05 +0300
|
||||
Subject: [PATCH] Fix location tracking in gdbmtool. Fix the recover command.
|
||||
|
||||
In particular, this addresses https://puszcza.gnu.org.ua/bugs/?566
|
||||
|
||||
* src/gdbmtool.c: Fix parameter parsing failure
|
||||
(recover_handler): Accept varargs
|
||||
(command_tab): Use argdoc to provide help for varargs
|
||||
(help_handler): Handle argdoc
|
||||
* src/gram.y: Accept a single unadorned key=value pair as argument.
|
||||
|
||||
Conflict: Fix only the part that caused the problem
|
||||
Origin Patch: https://git.gnu.org.ua/gdbm.git/commit/?id=b8271d89db991558e10c26d45d960bbc0257fa31
|
||||
---
|
||||
src/gdbmtool.c | 178 +++++++++++++++++++++++++++++++++++++++------------------
|
||||
src/gram.y | 8 +++
|
||||
2 files changed, 131 insertions(+), 55 deletions(-)
|
||||
|
||||
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
|
||||
index 03ba482..cdfe61d 100644
|
||||
--- a/src/gdbmtool.c
|
||||
+++ b/src/gdbmtool.c
|
||||
@@ -579,64 +579,98 @@ recover_handler (struct handler_param *param)
|
||||
gdbm_recovery rcvr;
|
||||
int flags = 0;
|
||||
int rc;
|
||||
- int i;
|
||||
char *p;
|
||||
int summary = 0;
|
||||
|
||||
- for (i = 0; i < param->argc; i++)
|
||||
+ if (param->vararg)
|
||||
{
|
||||
- char *arg = PARAM_STRING (param, i);
|
||||
- if (strcmp (arg, "verbose") == 0)
|
||||
- {
|
||||
- rcvr.errfun = err_printer;
|
||||
- flags |= GDBM_RCVR_ERRFUN;
|
||||
- }
|
||||
- else if (strcmp (arg, "force") == 0)
|
||||
- {
|
||||
- flags |= GDBM_RCVR_FORCE;
|
||||
- }
|
||||
- else if (strcmp (arg, "summary") == 0)
|
||||
- {
|
||||
- summary = 1;
|
||||
- }
|
||||
- else if (strcmp (arg, "backup") == 0)
|
||||
- {
|
||||
- flags |= GDBM_RCVR_BACKUP;
|
||||
- }
|
||||
- else if (strncmp (arg, "max-failures=", 13) == 0)
|
||||
+ struct gdbmarg *arg;
|
||||
+ int i;
|
||||
+
|
||||
+ for (arg = param->vararg, i = 0; arg; arg = arg->next, i++)
|
||||
{
|
||||
- rcvr.max_failures = strtoul (arg + 13, &p, 10);
|
||||
- if (*p)
|
||||
+ if (arg->type == GDBM_ARG_STRING)
|
||||
{
|
||||
- printf (_("not a number (stopped near %s)\n"), p);
|
||||
- return;
|
||||
+ if (strcmp(arg->v.string, "verbose") == 0)
|
||||
+ {
|
||||
+ rcvr.errfun = err_printer;
|
||||
+ flags |= GDBM_RCVR_ERRFUN;
|
||||
+ }
|
||||
+ else if (strcmp (arg->v.string, "force") == 0)
|
||||
+ {
|
||||
+ flags |= GDBM_RCVR_FORCE;
|
||||
+ }
|
||||
+ else if (strcmp (arg->v.string, "summary") == 0)
|
||||
+ {
|
||||
+ summary = 1;
|
||||
+ }
|
||||
+ else if (strcmp (arg->v.string, "backup") == 0)
|
||||
+ {
|
||||
+ flags |= GDBM_RCVR_BACKUP;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ lerror (&arg->loc, _("unrecognized argument: %s"), arg->v.string);
|
||||
+ return;
|
||||
+ }
|
||||
}
|
||||
- flags |= GDBM_RCVR_MAX_FAILURES;
|
||||
- }
|
||||
- else if (strncmp (arg, "max-failed-keys=", 16) == 0)
|
||||
- {
|
||||
- rcvr.max_failed_keys = strtoul (arg + 16, &p, 10);
|
||||
- if (*p)
|
||||
+ else if (arg->type == GDBM_ARG_KVPAIR)
|
||||
{
|
||||
- printf (_("not a number (stopped near %s)\n"), p);
|
||||
- return;
|
||||
+ if (arg->v.kvpair->type != KV_STRING)
|
||||
+ {
|
||||
+ lerror (&arg->loc, _("%s: bad argument type"), arg->v.kvpair->key);
|
||||
+ return;
|
||||
+ }
|
||||
+ else if (arg->v.kvpair->next)
|
||||
+ {
|
||||
+ lerror (&arg->loc, _("unexpected compound statement"));
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ if (strcmp (arg->v.kvpair->key, "max-failures") == 0)
|
||||
+ {
|
||||
+ rcvr.max_failures = strtoul (arg->v.kvpair->val.s, &p, 10);
|
||||
+
|
||||
+ if (*p)
|
||||
+ {
|
||||
+ lerror (&arg->loc, _("not a number (stopped near %s)"), p);
|
||||
+ return;
|
||||
+ }
|
||||
+ flags |= GDBM_RCVR_MAX_FAILURES;
|
||||
+ }
|
||||
+ else if (strcmp (arg->v.kvpair->key, "max-failed-keys") == 0)
|
||||
+ {
|
||||
+ rcvr.max_failed_keys = strtoul (arg->v.kvpair->val.s, &p, 10);
|
||||
+
|
||||
+ if (*p)
|
||||
+ {
|
||||
+ lerror (&arg->loc, _("not a number (stopped near %s)"), p);
|
||||
+ return;
|
||||
+ }
|
||||
+ flags |= GDBM_RCVR_MAX_FAILED_KEYS;
|
||||
+ }
|
||||
+ else if (strcmp (arg->v.kvpair->key, "max-failed-buckets") == 0)
|
||||
+ {
|
||||
+ rcvr.max_failures = strtoul (arg->v.kvpair->val.s, &p, 10);
|
||||
+
|
||||
+ if (*p)
|
||||
+ {
|
||||
+ lerror (&arg->loc, _("not a number (stopped near %s)"), p);
|
||||
+ return;
|
||||
+ }
|
||||
+ flags |= GDBM_RCVR_MAX_FAILED_BUCKETS;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ lerror (&arg->loc, _("unrecognized argument: %s"), arg->v.kvpair->key);
|
||||
+ return;
|
||||
+ }
|
||||
}
|
||||
- flags |= GDBM_RCVR_MAX_FAILED_KEYS;
|
||||
- }
|
||||
- else if (strncmp (arg, "max-failed-buckets=", 19) == 0)
|
||||
- {
|
||||
- rcvr.max_failures = strtoul (arg + 19, &p, 10);
|
||||
- if (*p)
|
||||
+ else
|
||||
{
|
||||
- printf (_("not a number (stopped near %s)\n"), p);
|
||||
+ lerror (&arg->loc, _("unexpected datum"));
|
||||
return;
|
||||
}
|
||||
- flags |= GDBM_RCVR_MAX_FAILED_BUCKETS;
|
||||
- }
|
||||
- else
|
||||
- {
|
||||
- terror (_("unrecognized argument: %s"), arg);
|
||||
- return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1184,6 +1218,7 @@ struct command
|
||||
void (*handler) (struct handler_param *param);
|
||||
void (*end) (void *data);
|
||||
struct argdef args[NARGS];
|
||||
+ char *argdoc[NARGS];
|
||||
int variadic;
|
||||
enum command_repeat_type repeat;
|
||||
char *doc;
|
||||
@@ -1194,12 +1229,14 @@ struct command command_tab[] = {
|
||||
{ S(count), T_CMD,
|
||||
checkdb_begin, count_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("count (number of entries)") },
|
||||
{ S(delete), T_CMD,
|
||||
checkdb_begin, delete_handler, NULL,
|
||||
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY }, { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("delete a record") },
|
||||
@@ -1209,12 +1246,14 @@ struct command command_tab[] = {
|
||||
{ "[truncate]", GDBM_ARG_STRING },
|
||||
{ "[binary|ascii]", GDBM_ARG_STRING },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("export") },
|
||||
{ S(fetch), T_CMD,
|
||||
checkdb_begin, fetch_handler, NULL,
|
||||
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY }, { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("fetch record") },
|
||||
@@ -1224,12 +1263,14 @@ struct command command_tab[] = {
|
||||
{ "[replace]", GDBM_ARG_STRING },
|
||||
{ "[nometa]" , GDBM_ARG_STRING },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
FALSE,
|
||||
N_("import") },
|
||||
{ S(list), T_CMD,
|
||||
list_begin, list_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("list") },
|
||||
@@ -1237,6 +1278,7 @@ struct command command_tab[] = {
|
||||
checkdb_begin, nextkey_handler, NULL,
|
||||
{ { N_("[KEY]"), GDBM_ARG_DATUM, DS_KEY },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NOARG,
|
||||
N_("nextkey") },
|
||||
@@ -1245,37 +1287,42 @@ struct command command_tab[] = {
|
||||
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
|
||||
{ N_("DATA"), GDBM_ARG_DATUM, DS_CONTENT },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("store") },
|
||||
{ S(first), T_CMD,
|
||||
checkdb_begin, firstkey_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("firstkey") },
|
||||
{ S(reorganize), T_CMD,
|
||||
checkdb_begin, reorganize_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("reorganize") },
|
||||
{ S(recover), T_CMD,
|
||||
checkdb_begin, recover_handler, NULL,
|
||||
- { { "[verbose]", GDBM_ARG_STRING },
|
||||
- { "[summary]", GDBM_ARG_STRING },
|
||||
- { "[backup]", GDBM_ARG_STRING },
|
||||
- { "[force]", GDBM_ARG_STRING },
|
||||
- { "[max-failed-keys=N]", GDBM_ARG_STRING },
|
||||
- { "[max-failed-buckets=N]", GDBM_ARG_STRING },
|
||||
- { "[max-failures=N]", GDBM_ARG_STRING },
|
||||
- { NULL } },
|
||||
- FALSE,
|
||||
+ { { NULL } },
|
||||
+ { "[verbose]",
|
||||
+ "[summary]",
|
||||
+ "[backup]",
|
||||
+ "[force]",
|
||||
+ "[max-failed-keys=N]",
|
||||
+ "[max-failed-buckets=N]",
|
||||
+ "[max-failures=N]",
|
||||
+ NULL },
|
||||
+ TRUE,
|
||||
REPEAT_NEVER,
|
||||
N_("recover the database") },
|
||||
{ S(avail), T_CMD,
|
||||
avail_begin, avail_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print avail list") },
|
||||
@@ -1283,24 +1330,28 @@ struct command command_tab[] = {
|
||||
print_bucket_begin, print_current_bucket_handler, NULL,
|
||||
{ { N_("NUMBER"), GDBM_ARG_STRING },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print a bucket") },
|
||||
{ S(current), T_CMD,
|
||||
print_current_bucket_begin, print_current_bucket_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print current bucket") },
|
||||
{ S(dir), T_CMD,
|
||||
print_dir_begin, print_dir_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print hash directory") },
|
||||
{ S(header), T_CMD,
|
||||
print_header_begin , print_header_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print database file header") },
|
||||
@@ -1308,48 +1359,56 @@ struct command command_tab[] = {
|
||||
NULL, hash_handler, NULL,
|
||||
{ { N_("KEY"), GDBM_ARG_DATUM, DS_KEY },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("hash value of key") },
|
||||
{ S(cache), T_CMD,
|
||||
print_cache_begin, print_cache_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print the bucket cache") },
|
||||
{ S(status), T_CMD,
|
||||
NULL, status_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print current program status") },
|
||||
{ S(version), T_CMD,
|
||||
NULL, print_version_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print version of gdbm") },
|
||||
{ S(help), T_CMD,
|
||||
help_begin, help_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("print this help list") },
|
||||
{ S(quit), T_CMD,
|
||||
NULL, quit_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("quit the program") },
|
||||
{ S(set), T_SET,
|
||||
NULL, NULL, NULL,
|
||||
{ { "[VAR=VALUE...]" }, { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("set or list variables") },
|
||||
{ S(unset), T_UNSET,
|
||||
NULL, NULL, NULL,
|
||||
{ { "VAR..." }, { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("unset variables") },
|
||||
@@ -1358,6 +1417,7 @@ struct command command_tab[] = {
|
||||
{ { "key|content", GDBM_ARG_STRING },
|
||||
{ "{ FIELD-LIST }", GDBM_ARG_STRING },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("define datum structure") },
|
||||
@@ -1365,18 +1425,21 @@ struct command command_tab[] = {
|
||||
NULL, source_handler, NULL,
|
||||
{ { "FILE", GDBM_ARG_STRING },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("source command script") },
|
||||
{ S(close), T_CMD,
|
||||
NULL, close_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("close the database") },
|
||||
{ S(open), T_CMD,
|
||||
NULL, open_handler, NULL,
|
||||
{ { "FILE", GDBM_ARG_STRING }, { NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("open new database") },
|
||||
@@ -1386,6 +1449,7 @@ struct command command_tab[] = {
|
||||
{ { N_("[FROM]"), GDBM_ARG_STRING },
|
||||
{ N_("[COUNT]"), GDBM_ARG_STRING },
|
||||
{ NULL } },
|
||||
+ { NULL },
|
||||
FALSE,
|
||||
REPEAT_NEVER,
|
||||
N_("show input history") },
|
||||
@@ -1393,6 +1457,7 @@ struct command command_tab[] = {
|
||||
{ S(debug), T_CMD,
|
||||
NULL, debug_handler, NULL,
|
||||
{ { NULL } },
|
||||
+ { NULL },
|
||||
TRUE,
|
||||
REPEAT_NEVER,
|
||||
N_("query/set debug level") },
|
||||
@@ -1476,6 +1541,9 @@ help_handler (struct handler_param *param)
|
||||
for (i = 0; i < NARGS && cmd->args[i].name; i++)
|
||||
n += fprintf (fp, " %s", gettext (cmd->args[i].name));
|
||||
|
||||
+ for (i = 0; i < NARGS && cmd->argdoc[i]; i++)
|
||||
+ n += fprintf (fp, " %s", gettext (cmd->argdoc[i]));
|
||||
+
|
||||
if (n < CMDCOLS)
|
||||
fprintf (fp, "%*.s", CMDCOLS-n, "");
|
||||
fprintf (fp, " %s", gettext (cmd->doc));
|
||||
diff --git a/src/gram.y b/src/gram.y
|
||||
index 6c79c7a..a389f48 100644
|
||||
--- a/src/gram.y
|
||||
+++ b/src/gram.y
|
||||
@@ -130,6 +130,13 @@ arg : string
|
||||
{
|
||||
$$ = gdbmarg_string ($1, &@1);
|
||||
}
|
||||
+ | T_IDENT '=' string
|
||||
+ {
|
||||
+ struct locus loc = { .beg = @1.beg, .end = @3.end };
|
||||
+ struct kvpair *kvp = kvpair_string (&loc, $3);
|
||||
+ kvp->key = $1;
|
||||
+ $$ = gdbmarg_kvpair (kvp, &loc);
|
||||
+ }
|
||||
| compound
|
||||
{
|
||||
$$ = gdbmarg_kvpair ($1, &@1);
|
||||
@@ -158,6 +165,7 @@ kvpair : value
|
||||
| T_IDENT '=' value
|
||||
{
|
||||
$3->key = $1;
|
||||
+ $3->loc.beg = @1.beg;
|
||||
$$ = $3;
|
||||
}
|
||||
;
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: gdbm
|
||||
Version: 1.18.1
|
||||
Release: 5
|
||||
Release: 6
|
||||
Epoch: 1
|
||||
Summary: A library of database functions that work similar to the standard UNIX dbm
|
||||
License: GPLv3+
|
||||
@ -10,8 +10,9 @@ Source0: http://ftp.gnu.org/gnu/gdbm/gdbm-%{version}.tar.gz
|
||||
Patch0: 0000-Fix-gdbmtool-import-command.patch
|
||||
Patch1: 0001-fix-gdbm_dump-usage-stack-overflow.patch
|
||||
Patch2: gdbm_dump-fix-command-line-error-detection.patch
|
||||
Patch3: 0002-Fix-location-tracking-in-gdbmtool.-Fix-the-recover-c.patch
|
||||
|
||||
BuildRequires: gcc libtool gettext readline-devel git
|
||||
BuildRequires: gcc libtool gettext readline-devel git bison flex
|
||||
|
||||
Provides: %{name}-libs
|
||||
Provides: %{name}-libs%{?_isa}
|
||||
@ -101,6 +102,9 @@ fi
|
||||
%{_infodir}/*.info*
|
||||
|
||||
%changelog
|
||||
* Mon Jun 27 2022 wangzhiqiang <wangzhiqiang95@huawei.com> - 1:1.18.1-6
|
||||
- Fix location tracking in gdbmtool. Fix the recover command
|
||||
|
||||
* Fri Jun 24 2022 yanxiaodan <yanxiaodan@huawei.com> - 1:1.18.1-5
|
||||
- gdbm_dump-fix-command-line-error-detection
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user