changeset 8:78f6455272bf

Sync writes Use difftime()
author Simon Horman <horms@verge.net.au>
date Tue, 14 May 2002 15:10:26 +0900
parents 385e4e7f7daa
children 33e380418b2f
files pbs/pbs.c pbs/pbs_db.c pbs/pbs_db.h
diffstat 3 files changed, 33 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pbs/pbs.c	Tue May 14 13:43:31 2002 +0900
+++ b/pbs/pbs.c	Tue May 14 15:10:26 2002 +0900
@@ -287,7 +287,7 @@
 		}
 
 		now = time(NULL);
-		if(now > expire_now) {
+		if(difftime(now, expire_now) < 0) {
 			if(pbs_db_traverse(db, 
 					pbs_db_traverse_func_expire_record, 
 					&now) < 0) {
@@ -359,6 +359,7 @@
 			free(line);
 			line = NULL;
 		}
+		pbs_db_sync(db);
 	}
 
 	exit_status = 0;
@@ -718,6 +719,7 @@
 	const char *peername_str_fixed;
 	char *buf = NULL;
 	time_t expire;
+	time_t now;
 	size_t len;
 	size_t buf_len = 0;
 
@@ -726,15 +728,18 @@
 		return(-2);
 	}
 
-	namelen = sizeof(peername);
-	if(getpeername(fd, (struct sockaddr *)&peername, &namelen)) {
-		PBS_DEBUG_ERRNO("getpeername");
-		return(-1);
-	}
-	peername_str = inet_ntoa(peername.sin_addr);
+	peername_str = getenv("TCPREMOTEIP");
 	if(peername_str == NULL) {
-		PBS_DEBUG_ERRNO("inet_ntoa");
-		return(-1);
+		namelen = sizeof(peername);
+		if(getpeername(fd, (struct sockaddr *)&peername, &namelen)) {
+			PBS_DEBUG_ERRNO("getpeername");
+			return(-1);
+		}
+		peername_str = inet_ntoa(peername.sin_addr);
+		if(peername_str == NULL) {
+			PBS_DEBUG_ERRNO("inet_ntoa");
+			return(-1);
+		}
 	}
 
 	peername_str_fixed = pbs_record_fix_key(peername_str, prefix, 
@@ -744,12 +749,13 @@
 		return(-1);
 	}
 
+	now = time(NULL);
 	if(pbs_db_get(db, (char *)peername_str_fixed, 
 			strlen(peername_str_fixed)+1, 
 			(void **)&expire, &len) < 0) {
 		PBS_INFO_UNSAFE("No (Not in database): %s", peername_str);
 	}
-	else if (time(NULL) > expire) {
+	else if (difftime(now, expire) < 0) {
 		PBS_INFO_UNSAFE("No (Expired): %s", peername_str);
 	}
 	else {
--- a/pbs/pbs_db.c	Tue May 14 13:43:31 2002 +0900
+++ b/pbs/pbs_db.c	Tue May 14 15:10:26 2002 +0900
@@ -75,6 +75,20 @@
 	return(0);
 }
 
+int pbs_db_sync(pbs_db_t *db) {
+	DB *dbp;
+	int status;
+
+	dbp = (DB *)db;
+	status = dbp->sync(dbp, 0);
+	if(status != 0) {
+		PBS_DEBUG_DB("dbp->sync", status);
+		return(-1);
+	}
+
+	return(0);
+}
+
 int pbs_db_put(pbs_db_t *db, void *key, size_t key_len, void *data, 
 		size_t data_len)
 {
@@ -240,7 +254,7 @@
 	now=*(time_t *)func_data;
 
 
-	if(expire > now && now != ~0) {
+	if(difftime(now, expire) > 0) {
 		return(0);
 	}
 
--- a/pbs/pbs_db.h	Tue May 14 13:43:31 2002 +0900
+++ b/pbs/pbs_db.h	Tue May 14 15:10:26 2002 +0900
@@ -39,6 +39,8 @@
 
 int pbs_db_close(pbs_db_t *db);
 
+int pbs_db_sync(pbs_db_t *db);
+
 int pbs_db_put(pbs_db_t *db, void *keyp, size_t key_len, void *datap, 
 		size_t data_len);