summaryrefslogtreecommitdiffstats
path: root/src/plugins/kdb/db2/kdb_db2.c
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2010-11-03 17:32:11 +0000
committerGreg Hudson <ghudson@mit.edu>2010-11-03 17:32:11 +0000
commitf94de982b69e79e8a27193e3b765ff37d66f1ada (patch)
treedcd802f3389ed24103f69d96a6b3bd79cfd07dfa /src/plugins/kdb/db2/kdb_db2.c
parent602ae0d3ad698ef15b49d0a24b2cf1a7cb05bb35 (diff)
downloadkrb5-f94de982b69e79e8a27193e3b765ff37d66f1ada.tar.gz
krb5-f94de982b69e79e8a27193e3b765ff37d66f1ada.tar.xz
krb5-f94de982b69e79e8a27193e3b765ff37d66f1ada.zip
Simplify kdb_db2's open_db() a little further, avoiding a suspicious
switch fallthrough. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24508 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/plugins/kdb/db2/kdb_db2.c')
-rw-r--r--src/plugins/kdb/db2/kdb_db2.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/plugins/kdb/db2/kdb_db2.c b/src/plugins/kdb/db2/kdb_db2.c
index a5ec2d01d2..36969584af 100644
--- a/src/plugins/kdb/db2/kdb_db2.c
+++ b/src/plugins/kdb/db2/kdb_db2.c
@@ -309,13 +309,14 @@ open_db(krb5_db2_context *dbc, char *fname, int flags, int mode)
hashi.lorder = 0;
hashi.nelem = 1;
+ /* Try our best guess at the database type. */
db = dbopen(fname, flags, mode,
dbc->hashfirst ? DB_HASH : DB_BTREE,
dbc->hashfirst ? (void *) &hashi : (void *) &bti);
- if (db != NULL) {
- free(fname);
- return db;
- }
+ if (db != NULL)
+ goto done;
+
+ /* If that was wrong, retry with the other type. */
switch (errno) {
#ifdef EFTYPE
case EFTYPE:
@@ -324,12 +325,15 @@ open_db(krb5_db2_context *dbc, char *fname, int flags, int mode)
db = dbopen(fname, flags, mode,
dbc->hashfirst ? DB_BTREE : DB_HASH,
dbc->hashfirst ? (void *) &bti : (void *) &hashi);
+ /* If that worked, update our guess for next time. */
if (db != NULL)
dbc->hashfirst = !dbc->hashfirst;
- default:
- free(fname);
- return db;
+ break;
}
+
+done:
+ free(fname);
+ return db;
}
/* Initialize the lock file and policy database fields of the DB2 context