From 90243e7779a119e4e73fb053b8e1d5841f7509d2 Mon Sep 17 00:00:00 2001
From: Howard Chu <hyc@openldap.org>
Date: Tue, 30 Aug 2011 19:14:56 -0700
Subject: [PATCH] For test063

add hex timestamp to lutil_debug() output
Fix LASTMOD race condition in accesslog.c
Set refreshInterval even if using refreshAndPersist, since
fallbacks will use refresh params
---
 libraries/liblber/debug.c               |  3 ++-
 servers/slapd/overlays/accesslog.c      |  5 +++--
 tests/scripts/test063-delta-multimaster | 25 +++++++++++++++++++++----
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/libraries/liblber/debug.c b/libraries/liblber/debug.c
index 277eecae63..cc38e85b44 100644
--- a/libraries/liblber/debug.c
+++ b/libraries/liblber/debug.c
@@ -62,8 +62,9 @@ void (lutil_debug)( int debug, int level, const char *fmt, ... )
 	}
 #endif
 
+	sprintf(buffer, "%08x ", time(0L));
 	va_start( vl, fmt );
-	vsnprintf( buffer, sizeof(buffer), fmt, vl );
+	vsnprintf( buffer+9, sizeof(buffer)-9, fmt, vl );
 	buffer[sizeof(buffer)-1] = '\0';
 	if( log_file != NULL ) {
 		fputs( buffer, log_file );
diff --git a/servers/slapd/overlays/accesslog.c b/servers/slapd/overlays/accesslog.c
index d01c70d067..4023e18b14 100644
--- a/servers/slapd/overlays/accesslog.c
+++ b/servers/slapd/overlays/accesslog.c
@@ -2110,6 +2110,7 @@ accesslog_db_root(
 		AttributeDescription *ad = NULL;
 		const char *text = NULL;
 		Entry *e_ctx;
+		BackendDB db;
 
 		e = entry_alloc();
 		ber_dupbv( &e->e_name, li->li_db->be_suffix );
@@ -2154,7 +2155,8 @@ accesslog_db_root(
 			}
 			be_entry_release_rw( op, e_ctx, 0 );
 		}
-		op->o_bd = li->li_db;
+		db = *li->li_db;
+		op->o_bd = &db;
 
 		op->ora_e = e;
 		op->o_req_dn = e->e_name;
@@ -2162,7 +2164,6 @@ accesslog_db_root(
 		op->o_callback = &nullsc;
 		SLAP_DBFLAGS( op->o_bd ) |= SLAP_DBFLAG_NOLASTMOD;
 		rc = op->o_bd->be_add( op, &rs );
-		SLAP_DBFLAGS( op->o_bd ) ^= SLAP_DBFLAG_NOLASTMOD;
 		if ( e == op->ora_e )
 			entry_free( e );
 	}
diff --git a/tests/scripts/test063-delta-multimaster b/tests/scripts/test063-delta-multimaster
index af043057dd..61438d5e9e 100755
--- a/tests/scripts/test063-delta-multimaster
+++ b/tests/scripts/test063-delta-multimaster
@@ -42,7 +42,7 @@ case "$SYNCMODE" in
 		SYNCTYPE="type=refreshOnly interval=00:00:00:03"
 		;;
 	rp)
-		SYNCTYPE="type=refreshAndPersist"
+		SYNCTYPE="type=refreshAndPersist interval=00:00:00:03"
 		;;
 	*)
 		echo "unknown sync mode $SYNCMODE"
@@ -288,8 +288,26 @@ if test $RC != 0 ; then
 	exit $RC
 fi
 
-echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
-sleep $SLEEP1
+THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
+sleep 1
+for i in 1 2 3; do
+	$LDAPSEARCH -S "" -b "$THEDN" -H $URI1 \
+		-s base '(objectClass=*)' entryCSN > "${MASTEROUT}.$i" 2>&1
+	RC=$?
+
+	if test $RC = 0 ; then
+		break
+	fi
+
+	if test $RC != 32 ; then
+		echo "ldapsearch failed at slave ($RC)!"
+		test $KILLSERVERS != no && kill -HUP $KILLPIDS
+		exit $RC
+	fi
+
+	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
+	sleep $SLEEP1
+done
 
 n=1
 while [ $n -le $MMR ]; do
@@ -353,7 +371,6 @@ n=`expr $n + 1`
 done
 
 echo "Using ldapmodify to force conflicts between server 1 and 2..."
-THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
 	>> $TESTOUT 2>&1 << EOF
 dn: $THEDN
-- 
GitLab