فهرست منبع

Add invalid handle definition

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1014 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 20 سال پیش
والد
کامیت
5bd057566c
2فایلهای تغییر یافته به همراه14 افزوده شده و 1 حذف شده
  1. 2 0
      include/saAis.h
  2. 12 1
      lib/util.c

+ 2 - 0
include/saAis.h

@@ -129,4 +129,6 @@ typedef SaUint64T SaInvocationT;
 
 typedef SaUint64T SaSizeT;
 
+#define SA_HANDLE_INVALID 0x0ull
+
 #endif /* AIS_TYPES_H_DEFINED */

+ 12 - 1
lib/util.c

@@ -522,6 +522,7 @@ saHandleCreate (
 	void *newHandles;
 	int found = 0;
 	void *instance;
+	int i;
 
 	pthread_mutex_lock (&handleDatabase->mutex);
 
@@ -549,7 +550,17 @@ saHandleCreate (
 	}
 
 
-	check = random();
+	/*
+	 * This code makes sure the random number isn't zero
+	 * We use 0 to specify an invalid handle out of the 1^64 address space
+	 * If we get 0 200 times in a row, the RNG may be broken
+	 */
+	for (i = 0; i < 200; i++) {
+		check = random();
+		if (check != 0) {
+			break;
+		}
+	}
 
 	memset (instance, 0, instanceSize);