[Spread-cvs] commit: r537 - trunk/libspread

jschultz at spread.org jschultz at spread.org
Fri Jul 13 17:05:42 EDT 2012


Author: jschultz
Date: 2012-07-13 17:05:42 -0400 (Fri, 13 Jul 2012)
New Revision: 537

Modified:
   trunk/libspread/sp.c
Log:
Made initial session search infinite loop even more impossible.  Added an SP_BUG error type to indicate internal bug detected.


Modified: trunk/libspread/sp.c
===================================================================
--- trunk/libspread/sp.c	2012-07-13 19:57:49 UTC (rev 536)
+++ trunk/libspread/sp.c	2012-07-13 21:05:42 UTC (rev 537)
@@ -568,6 +568,7 @@
 	int			p;
 	int			s;
 	int                     ses;
+	int                     base_ses;
 	int			ret, i;
         unsigned int            len;
 	int			sp_v1, sp_v2, sp_v3;
@@ -922,8 +923,22 @@
 
 	/* find an unused session structure */
 
-	for ( ses = MBOX_TO_BASE_SES(s); Sessions[ses].state != SESS_UNUSED; ses = (ses != MAX_LIB_SESSIONS - 1 ? ses + 1 : 0)) {}
+	ses = base_ses = MBOX_TO_BASE_SES(s);
 
+	while( Sessions[ses].state != SESS_UNUSED ) {
+
+	        if( ++ses == MAX_LIB_SESSIONS) {
+	                ses = 0;
+		}
+
+		if( ses == base_ses ) {
+		        Alarm( SESSION, "SP_connect: BUG! No unused sessions when there should be!\n");
+			close( s );
+			Mutex_unlock( &Struct_mutex );
+			return( SP_BUG );
+		}
+	}
+
 	Sessions[ses].mbox = s;
         Sessions[ses].state = SESS_ACTIVE;
 	strcpy( Sessions[ses].private_group_name, private_group );
@@ -2168,6 +2183,9 @@
 		case NET_ERROR_ON_SESSION:
 			Alarm( PRINT, "SP_error: (%d) The network socket experienced an error. This Spread mailbox will no longer work until the connection is disconnected and then reconnected\n", error );
 			break;
+	        case SP_BUG:
+		        Alarm(PRINT, "SP_error: (%d) Internal spread bug detected!\n", error);
+			break;
 		default:
 			Alarm( PRINT, "SP_error: (%d) unrecognized error\n", error );
 	}




More information about the Spread-cvs mailing list