[PATCH] small cleanup in gencache

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Nov 25 22:54:10 MST 2014


Hi!

I'd appreciate review&push!

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From c7b44ffaa57c4cb0fc350f2b8bba5e29d934141c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 25 Nov 2014 21:03:18 +0000
Subject: [PATCH] lib: Use tdb_parse_record in gencache_set

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/gencache.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 3192b45..5ee406b 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -251,6 +251,17 @@ static bool gencache_have_val(const char *keystr, const DATA_BLOB *data,
 	return state.gotit;
 }
 
+static int last_stabilize_parser(TDB_DATA key, TDB_DATA data,
+				 void *private_data)
+{
+	time_t *last_stabilize = private_data;
+
+	if ((data.dsize != 0) && (data.dptr[data.dsize-1] == '\0')) {
+		*last_stabilize = atoi((char *)data.dptr);
+	}
+	return 0;
+}
+
 /**
  * Set an entry in the cache file. If there's no such
  * one, then add it.
@@ -267,7 +278,6 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
 			    time_t timeout)
 {
 	int ret;
-	TDB_DATA databuf;
 	char* val;
 	time_t last_stabilize;
 	static int writecount;
@@ -337,12 +347,10 @@ bool gencache_set_data_blob(const char *keystr, const DATA_BLOB *blob,
 	 */
 
 	last_stabilize = 0;
-	databuf = tdb_fetch_compat(cache_notrans, last_stabilize_key());
-	if ((databuf.dptr != NULL)
-	    && (databuf.dptr[databuf.dsize-1] == '\0')) {
-		last_stabilize = atoi((char *)databuf.dptr);
-		SAFE_FREE(databuf.dptr);
-	}
+
+	tdb_parse_record(cache_notrans, last_stabilize_key(),
+			 last_stabilize_parser, &last_stabilize);
+
 	if ((last_stabilize
 	     + lp_parm_int(-1, "gencache", "stabilize_interval", 300))
 	    < time(NULL)) {
-- 
1.9.1



More information about the samba-technical mailing list