[Pkg-gnupg-commit] [gnupg2] 39/241: gpg: Make the tofu DB check and initialization atomic.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Dec 9 20:31:50 UTC 2015
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit 85bd7d9491f8cc13c2b03f19b4f70ea13b45c704
Author: Neal H. Walfield <neal at g10code.com>
Date: Tue Oct 20 20:42:44 2015 +0200
gpg: Make the tofu DB check and initialization atomic.
* g10/tofu.c (initdb): Make the version check and the database
initialization atomic.
--
Signed-off-by: Neal H. Walfield <neal at g10code.com>
Co-authored-by: Andre Heinecke <aheinecke at intevation.de>
---
g10/tofu.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/g10/tofu.c b/g10/tofu.c
index 4ad44eb..0a23626 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -248,6 +248,15 @@ initdb (sqlite3 *db, enum db_type type)
unsigned long int count;
int version = -1;
+ rc = sqlite3_exec (db, "begin transaction;", NULL, NULL, &err);
+ if (rc)
+ {
+ log_error (_("error beginning transaction on TOFU database: %s\n"),
+ err);
+ sqlite3_free (err);
+ return 1;
+ }
+
/* If the DB has no tables, then assume this is a new DB that needs
to be initialized. */
rc = sqlite3_exec (db,
@@ -258,7 +267,7 @@ initdb (sqlite3 *db, enum db_type type)
log_error (_("error querying TOFU DB's available tables: %s\n"),
err);
sqlite3_free (err);
- return 1;
+ goto out;
}
else if (count != 0)
/* Assume that the DB is already initialized. Make sure the
@@ -270,21 +279,22 @@ initdb (sqlite3 *db, enum db_type type)
/* Happy, happy, joy, joy. */
{
sqlite3_free (err);
- return 0;
+ rc = 0;
+ goto out;
}
else if (rc == SQLITE_ABORT && version == -1)
/* Unsupported version. */
{
/* An error message was already displayed. */
sqlite3_free (err);
- return 1;
+ goto out;
}
else if (rc)
/* Some error. */
{
log_error (_("error determining TOFU DB's version: %s\n"), err);
sqlite3_free (err);
- return 1;
+ goto out;
}
else
/* Unexpected success. This can only happen if there are no
@@ -292,19 +302,11 @@ initdb (sqlite3 *db, enum db_type type)
{
log_error (_("error determining TOFU DB's version: %s\n"),
"select returned 0, but expected ABORT");
- return 1;
+ rc = 1;
+ goto out;
}
}
- rc = sqlite3_exec (db, "begin transaction;", NULL, NULL, &err);
- if (rc)
- {
- log_error (_("error beginning transaction on TOFU database: %s\n"),
- err);
- sqlite3_free (err);
- return 1;
- }
-
/* Create the version table. */
rc = sqlite3_exec (db,
"create table version (version INTEGER);",
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list