From 7aaf3af6e4ea49cb711131984898f16717584d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Fri, 9 Feb 2007 21:59:53 +0000 Subject: [PATCH] Be better at setting and clearing error string. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20215 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/hdb/db.c | 58 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/lib/hdb/db.c b/lib/hdb/db.c index e31a2f376..f38a156ee 100644 --- a/lib/hdb/db.c +++ b/lib/hdb/db.c @@ -67,8 +67,11 @@ DB_lock(krb5_context context, HDB *db, int operation) { DB *d = (DB*)db->hdb_db; int fd = (*d->fd)(d); - if(fd < 0) + if(fd < 0) { + krb5_set_error_string(context, + "Can't lock database: %s", db->hdb_name); return HDB_ERR_CANT_LOCK_DB; + } return hdb_lock(fd, operation); } @@ -77,8 +80,11 @@ DB_unlock(krb5_context context, HDB *db) { DB *d = (DB*)db->hdb_db; int fd = (*d->fd)(d); - if(fd < 0) + if(fd < 0) { + krb5_set_error_string(context, + "Can't unlock database: %s", db->hdb_name); return HDB_ERR_CANT_LOCK_DB; + } return hdb_unlock(fd); } @@ -93,14 +99,22 @@ DB_seq(krb5_context context, HDB *db, int code; code = db->hdb_lock(context, db, HDB_RLOCK); - if(code == -1) + if(code == -1) { + krb5_set_error_string(context, "Database %s in use", db->hdb_name); return HDB_ERR_DB_INUSE; + } code = (*d->seq)(d, &key, &value, flag); db->hdb_unlock(context, db); /* XXX check value */ - if(code == -1) - return errno; - if(code == 1) + if(code == -1) { + code = errno; + krb5_set_error_string(context, "Database %s seq error: %s", + db->hdb_name, strerror(code)); + return code; + } + if(code == 1) { + krb5_clear_error_string(context); return HDB_ERR_NOENTRY; + } key_data.data = key.data; key_data.length = key.size; @@ -174,10 +188,16 @@ DB__get(krb5_context context, HDB *db, krb5_data key, krb5_data *reply) return code; code = (*d->get)(d, &k, &v, 0); db->hdb_unlock(context, db); - if(code < 0) - return errno; - if(code == 1) + if(code < 0) { + code = errno; + krb5_set_error_string(context, "Database %s get error: %s", + db->hdb_name, strerror(code)); + return code; + } + if(code == 1) { + krb5_clear_error_string(context); return HDB_ERR_NOENTRY; + } krb5_data_copy(reply, v.data, v.size); return 0; @@ -200,10 +220,16 @@ DB__put(krb5_context context, HDB *db, int replace, return code; code = (*d->put)(d, &k, &v, replace ? 0 : R_NOOVERWRITE); db->hdb_unlock(context, db); - if(code < 0) - return errno; - if(code == 1) + if(code < 0) { + code = errno; + krb5_set_error_string(context, "Database %s put error: %s", + db->hdb_name, strerror(code)); + return code; + } + if(code == 1) { + krb5_clear_error_string(context); return HDB_ERR_EXISTS; + } return 0; } @@ -220,8 +246,12 @@ DB__del(krb5_context context, HDB *db, krb5_data key) return code; code = (*d->del)(d, &k, 0); db->hdb_unlock(context, db); - if(code == 1) - return HDB_ERR_NOENTRY; + if(code == 1) { + code = errno; + krb5_set_error_string(context, "Database %s put error: %s", + db->hdb_name, strerror(code)); + return code; + } if(code < 0) return errno; return 0;