aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2006-11-09 15:54:35 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2006-11-09 15:54:35 +0000
commit626886632c3cc876915ea30f3e1c16ee494a8b99 (patch)
tree6e6f6f86290dd2b017d0618d8fe06962b9a0e489
parent9761d8417f2af6f49d09a7e7083656121031e11a (diff)
downloadmailfromd-626886632c3cc876915ea30f3e1c16ee494a8b99.tar.gz
mailfromd-626886632c3cc876915ea30f3e1c16ee494a8b99.tar.bz2
Update invocations of mu_dbm_open, remove calls to mu_dbm_lock/mu_dbm_unlock.
git-svn-id: file:///svnroot/mailfromd/branches/release_3_0_patches@832 7a8a7f39-df28-0410-adc6-e0d955640f24
-rw-r--r--src/bi_db.m47
-rw-r--r--src/cache.c36
-rw-r--r--src/db.c20
-rw-r--r--src/rate.c99
4 files changed, 71 insertions, 91 deletions
diff --git a/src/bi_db.m4 b/src/bi_db.m4
index f8bc7cb2..f44442f2 100644
--- a/src/bi_db.m4
+++ b/src/bi_db.m4
@@ -27,7 +27,7 @@ dbmap_lookup_p(eval_environ_t env, char *dbname, const char *email)
DBM_DATUM key;
DBM_DATUM contents;
- if (mu_dbm_open(dbname, &db, MU_STREAM_READ, 0)) {
+ if (mu_dbm_open(dbname, &db, MU_STREAM_READ, 0, NULL)) {
if (env_catch(env, mf_dbfailure) == 0)
return -1;
else
@@ -103,13 +103,13 @@ MF_DEFUN(greylist, NUMBER, STRING email, NUMBER interval)
if (prog_trace_option)
prog_trace(env, "GREYLIST %s %ld %ld", email, interval);
- if (mu_dbm_open(greylist_format->dbname, &db, MU_STREAM_RDWR, 0600)) {
+ if (mu_dbm_open(greylist_format->dbname, &db, MU_STREAM_RDWR, 0600,
+ &readonly)) {
if (env_catch(env, mf_dbfailure) == 0)
return;
runtime_error(env, "mu_dbm_open(%s) failed: %s",
greylist_format->dbname, mu_strerror(errno));
}
- readonly = mu_dbm_lock(&db);
memset(&key, 0, sizeof key);
memset(&contents, 0, sizeof contents);
@@ -184,7 +184,6 @@ MF_DEFUN(greylist, NUMBER, STRING email, NUMBER interval)
} else
rc = 0;
- mu_dbm_unlock(&db);
mu_dbm_close(&db);
push(env, (STKVAL) rc);
diff --git a/src/cache.c b/src/cache.c
index 08ccb7aa..bd6b982d 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -44,16 +44,16 @@ cache_get(char *email)
int status;
debug1(50, "getting cache info for %s", email);
- if (mu_dbm_open(cache_format->dbname, &db, MU_STREAM_RDWR, 0600)) {
+ if (mu_dbm_open(cache_format->dbname, &db, MU_STREAM_RDWR, 0600,
+ &readonly)) {
mu_error("mu_dbm_open(%s) failed: %s", cache_format->dbname,
mu_strerror(errno));
return mf_failure;
}
- if (status = mu_dbm_lock(&db)) {
- readonly = 1;
- debug2(1, "cannot lock %s: %s; switching to read-only mode",
- cache_format->dbname, mu_strerror(status));
- }
+ if (readonly)
+ debug1(1, "cannot lock %s: switching to read-only mode",
+ cache_format->dbname);
+
memset (&key, 0, sizeof key);
memset (&contents, 0, sizeof contents);
MU_DATUM_PTR (key) = email;
@@ -83,7 +83,6 @@ cache_get(char *email)
} else
rc = mf_failure;
mu_dbm_datum_free(&contents);
- mu_dbm_unlock(&db);
mu_dbm_close(&db);
return rc;
}
@@ -103,25 +102,20 @@ cache_insert(char *email, mf_status rc)
debug4(50,"inserting cache info for %s. status=%s (%d), time=%s",
email, mf_status_str(rc), rc,
mailfromd_timestr(res.timestamp, timebuf, sizeof timebuf));
- if (mu_dbm_open(cache_format->dbname, &db, MU_STREAM_RDWR, 0600)) {
+ if (mu_dbm_open(cache_format->dbname, &db, MU_STREAM_RDWR, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", cache_format->dbname,
mu_strerror(errno));
return;
}
- if ((status = mu_dbm_lock(&db)) == 0) {
- memset(&key, 0, sizeof key);
- memset(&contents, 0, sizeof contents);
- MU_DATUM_PTR(key) = email;
- MU_DATUM_SIZE(key) = strlen (email) + 1;
- MU_DATUM_PTR(contents) = (void*)&res;
- MU_DATUM_SIZE(contents) = sizeof(res);
- if (mu_dbm_insert(&db, key, contents, 1))
- mu_error("Cannot insert datum");
- mu_dbm_unlock(&db);
- } else
- mu_error("cannot lock %s: %s",
- cache_format->dbname, mu_strerror(status));
+ memset(&key, 0, sizeof key);
+ memset(&contents, 0, sizeof contents);
+ MU_DATUM_PTR(key) = email;
+ MU_DATUM_SIZE(key) = strlen (email) + 1;
+ MU_DATUM_PTR(contents) = (void*)&res;
+ MU_DATUM_SIZE(contents) = sizeof(res);
+ if (mu_dbm_insert(&db, key, contents, 1))
+ mu_error("Cannot insert datum");
mu_dbm_close(&db);
}
diff --git a/src/db.c b/src/db.c
index fbbde16b..0b3581cb 100644
--- a/src/db.c
+++ b/src/db.c
@@ -37,7 +37,7 @@ db_list_item(char *dbname, char *email, db_item_printer_t fun)
DBM_DATUM key, contents;
int rc = 1;
- if (mu_dbm_open(dbname, &db, MU_STREAM_READ, 0600)) {
+ if (mu_dbm_open(dbname, &db, MU_STREAM_READ, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", dbname,
mu_strerror(errno));
return 1;
@@ -63,7 +63,7 @@ db_list(char *dbname, db_item_printer_t fun)
DBM_DATUM key, contents;
int rc = 0;
- if (mu_dbm_open(dbname, &db, MU_STREAM_READ, 0600)) {
+ if (mu_dbm_open(dbname, &db, MU_STREAM_READ, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", dbname,
mu_strerror(errno));
return 1;
@@ -97,7 +97,7 @@ db_expire(char *dbname, db_expire_t fun)
size_t i, key_count = 0;
int rc = 0;
- if (mu_dbm_open(dbname, &db, MU_STREAM_RDWR, 0600)) {
+ if (mu_dbm_open(dbname, &db, MU_STREAM_RDWR, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", dbname,
mu_strerror(errno));
return 1;
@@ -161,7 +161,7 @@ db_delete(char *dbname, char *id)
DBM_DATUM key;
int rc;
- if (mu_dbm_open(dbname, &db, MU_STREAM_RDWR, 0600)) {
+ if (mu_dbm_open(dbname, &db, MU_STREAM_RDWR, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", dbname,
mu_strerror(errno));
return 1;
@@ -213,20 +213,13 @@ db_compact(char *dbname, db_expire_t fun)
tmpname = make_tmp_name(dbname);
- if (mu_dbm_open(dbname, &odb, MU_STREAM_READ, 0600)) {
+ if (mu_dbm_open(dbname, &odb, MU_STREAM_READ, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", dbname,
mu_strerror(errno));
return 1;
}
- mu_locker_set_default_retry_count (300);
- if (rc = mu_dbm_lock(&odb)) {
- mu_error ("cannot lock %s: %s", dbname, mu_strerror (rc));
- mu_dbm_close(&odb);
- return 1;
- }
-
- if (mu_dbm_open(tmpname, &ndb, MU_STREAM_CREAT, 0600)) {
+ if (mu_dbm_open(tmpname, &ndb, MU_STREAM_CREAT, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", tmpname,
mu_strerror(errno));
return 1;
@@ -287,7 +280,6 @@ db_compact(char *dbname, db_expire_t fun)
rc = 1;
}
}
- mu_dbm_unlock(&odb);
free(tmpname);
return rc;
diff --git a/src/rate.c b/src/rate.c
index 177f6455..70cb1797 100644
--- a/src/rate.c
+++ b/src/rate.c
@@ -44,65 +44,60 @@ get_rate(char *email, double *ret)
mf_status status = mf_success;
debug1(50, "getting rate info for %s", email);
- if (mu_dbm_open(rate_format->dbname, &db, MU_STREAM_RDWR, 0600)) {
+ if (mu_dbm_open(rate_format->dbname, &db, MU_STREAM_RDWR, 0600, NULL)) {
mu_error("mu_dbm_open(%s) failed: %s", rate_format->dbname,
mu_strerror(errno));
return mf_failure;
}
- if ((rc = mu_dbm_lock(&db)) == 0) {
- memset (&key, 0, sizeof key);
- memset (&contents, 0, sizeof contents);
- MU_DATUM_PTR (key) = email;
- MU_DATUM_SIZE (key) = strlen (email) + 1;
- t = time(NULL);
- if (mu_dbm_fetch(&db, key, &contents) == 0) {
- rp = (struct rate_result *) MU_DATUM_PTR(contents);
- debug4(50,
- "found time: %lu, interval: %lu, count: %lu, "
- "rate: %g",
- rp->timestamp, rp->interval, rp->count,
- rp->interval == 0 ? -1 :
- (double)rp->count/rp->interval);
- } else {
- /* Initialize the structure */
- rate.timestamp = t;
- rate.interval = 0;
- rate.count = 0;
- rp = &rate;
- }
-
- /* Update the structure */
- rp->interval = t - rp->timestamp + rp->interval;
- rp->timestamp = t;
- rp->count++;
-
- if (rp->interval == 0)
- result = 0;
- else
- result = (double) rp->count / rp->interval;
- debug2(50, "rate for %s is %g", email, result);
-
- /* Update the db */
- if (rate_format->expire_interval
- && rp->interval > rate_format->expire_interval) {
- debug1(50, "expiring %s rates", email);
- rp->interval = 0;
- rp->count = 1;
- } else
- debug1(50, "updating %s rates", email);
-
- MU_DATUM_PTR(contents) = (void*)rp;
- MU_DATUM_SIZE(contents) = sizeof(*rp);
- if (mu_dbm_insert(&db, key, contents, 1))
- mu_error ("Cannot insert datum");
- mu_dbm_datum_free(&contents);
- mu_dbm_unlock(&db);
+ memset (&key, 0, sizeof key);
+ memset (&contents, 0, sizeof contents);
+ MU_DATUM_PTR (key) = email;
+ MU_DATUM_SIZE (key) = strlen (email) + 1;
+ t = time(NULL);
+ if (mu_dbm_fetch(&db, key, &contents) == 0) {
+ rp = (struct rate_result *) MU_DATUM_PTR(contents);
+ debug4(50,
+ "found time: %lu, interval: %lu, count: %lu, "
+ "rate: %g",
+ rp->timestamp, rp->interval, rp->count,
+ rp->interval == 0 ? -1 :
+ (double)rp->count/rp->interval);
} else {
- mu_error("cannot lock %s: %s",
- rate_format->dbname, mu_strerror(rc));
- status = mf_failure;
+ /* Initialize the structure */
+ rate.timestamp = t;
+ rate.interval = 0;
+ rate.count = 0;
+ rp = &rate;
}
+
+ /* Update the structure */
+ rp->interval = t - rp->timestamp + rp->interval;
+ rp->timestamp = t;
+ rp->count++;
+
+ if (rp->interval == 0)
+ result = 0;
+ else
+ result = (double) rp->count / rp->interval;
+ debug2(50, "rate for %s is %g", email, result);
+
+ /* Update the db */
+ if (rate_format->expire_interval
+ && rp->interval > rate_format->expire_interval) {
+ debug1(50, "expiring %s rates", email);
+ rp->interval = 0;
+ rp->count = 1;
+ } else
+ debug1(50, "updating %s rates", email);
+
+ MU_DATUM_PTR(contents) = (void*)rp;
+ MU_DATUM_SIZE(contents) = sizeof(*rp);
+ if (mu_dbm_insert(&db, key, contents, 1))
+ mu_error ("Cannot insert datum");
+
+ mu_dbm_datum_free(&contents);
+
mu_dbm_close(&db);
*ret = result;
return mf_success;

Return to:

Send suggestions and report system problems to the System administrator.