svn rev #24510: trunk/src/plugins/kdb/db2/
ghudson@MIT.EDU
ghudson at MIT.EDU
Thu Nov 4 17:27:03 EDT 2010
http://src.mit.edu/fisheye/changelog/krb5/?cs=24510
Commit By: ghudson
Log Message:
Further kdb_db2 code cleanup: make gen_dbsuffix return a
krb5_error_code to simplify error handling in callers, and discard the
db_lf_time field which was set but never used.
Changed Files:
U trunk/src/plugins/kdb/db2/kdb_db2.c
U trunk/src/plugins/kdb/db2/kdb_db2.h
Modified: trunk/src/plugins/kdb/db2/kdb_db2.c
===================================================================
--- trunk/src/plugins/kdb/db2/kdb_db2.c 2010-11-04 17:20:30 UTC (rev 24509)
+++ trunk/src/plugins/kdb/db2/kdb_db2.c 2010-11-04 21:27:03 UTC (rev 24510)
@@ -264,15 +264,17 @@
return status;
}
-/* Return the concatenation of db_name and sfx. */
-static char *
-gen_dbsuffix(char *db_name, char *sfx)
+/* Set *out to the concatenation of db_name and sfx. */
+static krb5_error_code
+gen_dbsuffix(char *db_name, char *sfx, char **out)
{
- char *dbsuffix;
+ char *result;
- if (asprintf(&dbsuffix, "%s%s", db_name, sfx) < 0)
- return NULL;
- return dbsuffix;
+ *out = NULL;
+ if (asprintf(&result, "%s%s", db_name, sfx) < 0)
+ return ENOMEM;
+ *out = result;
+ return 0;
}
/*
@@ -296,8 +298,7 @@
bti.compare = NULL;
bti.prefix = NULL;
- fname = (dbc->tempdb) ? gen_dbsuffix(fname, "~") : strdup(fname);
- if (fname == NULL) {
+ if (gen_dbsuffix(fname, dbc->tempdb ? "~" : "", &fname) != 0) {
errno = ENOMEM;
return NULL;
}
@@ -355,9 +356,10 @@
db_ctx->db = NULL;
- if (!(filename = gen_dbsuffix(db_ctx->db_name, db_ctx->tempdb
- ?KDB2_TEMP_LOCK_EXT:KDB2_LOCK_EXT)))
- return ENOMEM;
+ retval = gen_dbsuffix(db_ctx->db_name, db_ctx->tempdb ?
+ KDB2_TEMP_LOCK_EXT : KDB2_LOCK_EXT, &filename);
+ if (retval)
+ return retval;
db_ctx->db_lf_name = filename; /* so it gets freed by clear_context */
/*
@@ -373,9 +375,6 @@
set_cloexec_fd(db_ctx->db_lf_file);
db_ctx->db_inited++;
- if ((retval = krb5_db2_get_age(context, NULL, &db_ctx->db_lf_time)))
- goto err_out;
-
snprintf(policy_db_name, sizeof(policy_db_name), "%s%s.kadm5",
db_ctx->db_name, db_ctx->tempdb ? "~" : "");
snprintf(policy_lock_name, sizeof(policy_lock_name),
@@ -507,13 +506,7 @@
}
} else
retval = errno;
- if (!retval) {
- if (fstat(db_ctx->db_lf_file, &st) == 0)
- db_ctx->db_lf_time = st.st_mtime;
- else
- retval = errno;
- }
- return (retval);
+ return retval;
}
#define MAX_LOCK_TRIES 5
@@ -523,7 +516,6 @@
{
krb5_db2_context *db_ctx;
int krb5_lock_mode;
- DB *db;
krb5_error_code retval;
time_t mod_time;
int mode, gotlock, tries;
@@ -578,14 +570,11 @@
if ((retval = krb5_db2_get_age(context, NULL, &mod_time)))
goto lock_error;
- db = open_db(db_ctx, db_ctx->db_name,
- mode == KRB5_LOCKMODE_SHARED ? O_RDONLY : O_RDWR, 0600);
- if (db) {
- db_ctx->db_lf_time = mod_time;
- db_ctx->db = db;
- } else {
+ db_ctx->db = open_db(db_ctx, db_ctx->db_name,
+ mode == KRB5_LOCKMODE_SHARED ? O_RDONLY : O_RDWR,
+ 0600);
+ if (db_ctx->db == NULL) {
retval = errno;
- db_ctx->db = NULL;
goto lock_error;
}
@@ -657,13 +646,11 @@
return errno;
(*db->close)(db);
- db_name2 = db_ctx->tempdb ? gen_dbsuffix(db_name, "~") : strdup(db_name);
- if (db_name2 == NULL)
- return ENOMEM;
- okname = gen_dbsuffix(db_name2, KDB2_LOCK_EXT);
- if (!okname)
- retval = ENOMEM;
- else {
+ retval = gen_dbsuffix(db_name, db_ctx->tempdb ? "~" : "", &db_name2);
+ if (retval)
+ return retval;
+ retval = gen_dbsuffix(db_name2, KDB2_LOCK_EXT, &okname);
+ if (retval == 0) {
fd = open(okname, O_CREAT | O_RDWR | O_TRUNC, 0600);
if (fd < 0)
retval = errno;
@@ -697,8 +684,7 @@
char zbuf[BUFSIZ];
int dowrite;
- filename = gen_dbsuffix(dbname, suffix);
- if (filename == 0)
+ if (gen_dbsuffix(dbname, suffix, &filename) != 0)
return ENOMEM;
if ((fd = open(filename, O_RDWR, 0)) < 0) {
free(filename);
@@ -1268,11 +1254,9 @@
goto clean_n_exit;
}
- temp_db_name = gen_dbsuffix(db_name, "~");
- if (temp_db_name == NULL) {
- status = ENOMEM;
+ status = gen_dbsuffix(db_name, "~", &temp_db_name);
+ if (status)
goto clean_n_exit;
- }
for (db_argp = db_args; *db_argp; db_argp++) {
if (!strcmp(*db_argp, "merge_nra")) {
@@ -1480,11 +1464,9 @@
if (retval)
goto errout;
- db_ctx->db_lf_name = gen_dbsuffix(db_ctx->db_name, KDB2_LOCK_EXT);
- if (db_ctx->db_lf_name == NULL) {
- retval = ENOMEM;
+ retval = gen_dbsuffix(db_ctx->db_name, KDB2_LOCK_EXT, &db_ctx->db_lf_name);
+ if (retval)
goto errout;
- }
db_ctx->db_lf_file = open(db_ctx->db_lf_name, O_RDWR|O_CREAT, 0600);
if (db_ctx->db_lf_file < 0) {
retval = errno;
@@ -1494,16 +1476,10 @@
db_ctx->db_inited = 1;
- retval = krb5_db2_get_age(context, NULL, &db_ctx->db_lf_time);
+ retval = gen_dbsuffix(from, KDB2_LOCK_EXT, &fromok);
if (retval)
goto errout;
- fromok = gen_dbsuffix(from, KDB2_LOCK_EXT);
- if (fromok == NULL) {
- retval = ENOMEM;
- goto errout;
- }
-
if ((retval = krb5_db2_lock(context, KRB5_LOCKMODE_EXCLUSIVE)))
goto errfromok;
Modified: trunk/src/plugins/kdb/db2/kdb_db2.h
===================================================================
--- trunk/src/plugins/kdb/db2/kdb_db2.h 2010-11-04 17:20:30 UTC (rev 24509)
+++ trunk/src/plugins/kdb/db2/kdb_db2.h 2010-11-04 21:27:03 UTC (rev 24510)
@@ -39,7 +39,6 @@
krb5_boolean hashfirst; /* Try hash database type first */
char * db_lf_name; /* Name of lock file */
int db_lf_file; /* File descriptor of lock file */
- time_t db_lf_time; /* Time last updated */
int db_locks_held; /* Number of times locked */
int db_lock_mode; /* Last lock mode, e.g. greatest*/
krb5_boolean db_nb_locks; /* [Non]Blocking lock modes */
More information about the cvs-krb5
mailing list