Index: trunk/FACT++/dim/src/dis.c
===================================================================
--- trunk/FACT++/dim/src/dis.c	(revision 12585)
+++ trunk/FACT++/dim/src/dis.c	(revision 12757)
@@ -133,4 +133,6 @@
 	int conn_id;
 	int exit_id;
+	char node[MAX_NODE_NAME];
+	char task[MAX_TASK_NAME];
 } EXIT_H;
 
@@ -1966,4 +1968,6 @@
 
 	DISABLE_AST
+	*secs = 0;
+	*millisecs = 0;
 	if(!serv_id)
 	{
@@ -1989,4 +1993,5 @@
 		*millisecs = servp->user_millisecs;
 	}
+/*
 	else
 	{
@@ -1994,4 +1999,5 @@
 		*millisecs = 0;
 	}
+*/
 	ENABLE_AST
 	return(1);
@@ -2345,4 +2351,7 @@
 	if(!(clip = find_client(conn_id)))
 	{
+		/*
+		dna_set_test_write(conn_id, 15);
+		*/
 		clip = (CLIENT *)malloc(sizeof(CLIENT));
 		clip->conn_id = conn_id;
@@ -2941,8 +2950,81 @@
 	ENABLE_AST
 }
-		
+	
+static void add_exit_handler_item(int conn_id, int tag)
+{
+	EXIT_H *newp;
+
+	DISABLE_AST
+	if(!Exit_h_head) 
+	{
+		Exit_h_head = (EXIT_H *)malloc(sizeof(EXIT_H));
+		sll_init( (SLL *) Exit_h_head );
+	}
+	if( (newp = (EXIT_H *)sll_search((SLL *) Exit_h_head, 
+		(char *)&conn_id, 4)) )
+	{
+		newp->conn_id = conn_id;
+		newp->exit_id = tag;
+		strcpy(newp->node, Net_conns[conn_id].node);
+		strcpy(newp->task, Net_conns[conn_id].task);
+	}
+	else
+	{
+		newp = (EXIT_H *)malloc(sizeof(EXIT_H));
+		newp->conn_id = conn_id;
+		newp->exit_id = tag;
+		strcpy(newp->node, Net_conns[conn_id].node);
+		strcpy(newp->task, Net_conns[conn_id].task);
+		sll_insert_queue( (SLL *) Exit_h_head, (SLL *) newp );
+	}
+	ENABLE_AST
+}
+
+static void rem_exit_handler_item(EXIT_H *exitp)
+{
+
+	DISABLE_AST
+	if(!Exit_h_head) 
+	{
+		ENABLE_AST
+		return;
+	}
+	sll_remove( (SLL *) Exit_h_head, (SLL *) exitp );
+	free(exitp);
+	ENABLE_AST
+}
+
+static EXIT_H *find_exit_handler_item(int conn_id)
+{
+	EXIT_H *exitp;
+
+	DISABLE_AST;
+	if(!Exit_h_head)
+	{
+		ENABLE_AST;
+		return((EXIT_H *)0);
+	}
+	if( (exitp = (EXIT_H *) sll_search((SLL *) Exit_h_head, (char *) &conn_id, 4)) )
+	{
+		ENABLE_AST;
+		return(exitp);
+	}
+	ENABLE_AST;
+	return((EXIT_H *)0);
+}
+
+static int check_exit_handler_item(EXIT_H *exitp, int conn_id)
+{
+	if( (!strcmp(exitp->node, Net_conns[conn_id].node)) &&
+		(!strcmp(exitp->task, Net_conns[conn_id].task)))
+	{
+		return exitp->exit_id;
+	}
+	return 0;
+}
+
 void add_exit_handler(int *tag, int *bufp, int *size)
 {
-	EXIT_H *newp;
+	EXIT_H *exitp;
 
 	if(size){}
@@ -2950,23 +3032,10 @@
 	if(*bufp)
 	{
-		if(!Exit_h_head) 
-		{
-			Exit_h_head = (EXIT_H *)malloc(sizeof(EXIT_H));
-			sll_init( (SLL *) Exit_h_head );
-		}
-		newp = (EXIT_H *)malloc(sizeof(EXIT_H));
-		newp->conn_id = Curr_conn_id;
-		newp->exit_id = *bufp;
-		sll_insert_queue( (SLL *) Exit_h_head, (SLL *) newp );
+		add_exit_handler_item(Curr_conn_id, *bufp);
 	}
 	else
 	{
-		if(!Exit_h_head) 
-			return;
-		if((newp = (EXIT_H *)sll_search((SLL *) Exit_h_head, 
-			(char *)&Curr_conn_id, 4)) )
-		{
-			sll_remove( (SLL *) Exit_h_head, (SLL *) newp );
-		}
+		if((exitp = find_exit_handler_item(Curr_conn_id)))
+			rem_exit_handler_item(exitp);
 	}
 }
@@ -2974,49 +3043,36 @@
 void dis_set_client_exit_handler(int conn_id, int tag)
 {
-	EXIT_H *newp;
-
-	DISABLE_AST
+	EXIT_H *exitp;
+
 	if(tag)
 	{
-		if(!Exit_h_head) 
-		{
-			Exit_h_head = (EXIT_H *)malloc(sizeof(EXIT_H));
-			sll_init( (SLL *) Exit_h_head );
-		}
-		if( (newp = (EXIT_H *)sll_search((SLL *) Exit_h_head, 
-			(char *)&conn_id, 4)) )
-		{
-			newp->conn_id = conn_id;
-			newp->exit_id = tag;
+		add_exit_handler_item(conn_id, tag);
+	}
+	else
+	{
+		if((exitp = find_exit_handler_item(conn_id)))
+			rem_exit_handler_item(exitp);
+	}
+}
+
+
+int do_exit_handler(int conn_id)
+{
+	register EXIT_H *exitp;
+	int exit_id;
+
+	DISABLE_AST;
+	if((exitp = find_exit_handler_item(conn_id)))
+	{
+		if((exit_id = check_exit_handler_item(exitp, conn_id)))
+		{
+			(Client_exit_user_routine)( &exit_id );
 		}
 		else
 		{
-			newp = (EXIT_H *)malloc(sizeof(EXIT_H));
-			newp->conn_id = conn_id;
-			newp->exit_id = tag;
-			sll_insert_queue( (SLL *) Exit_h_head, (SLL *) newp );
-		}
-	}
-	else
-	{
-		if(!Exit_h_head) 
-		{
-			ENABLE_AST
-			return;
-		}
-		if( (newp = (EXIT_H *)sll_search((SLL *) Exit_h_head, 
-			(char *)&conn_id, 4)) )
-		{
-			sll_remove( (SLL *) Exit_h_head, (SLL *) newp );
-		}
-	}
-	ENABLE_AST
-}
-
-int do_exit_handler(int conn_id)
-{
-	register EXIT_H *exitp;
-
-	DISABLE_AST;
+			rem_exit_handler_item(exitp);
+		}
+	}
+/*
 	if(!Exit_h_head)
 	{
@@ -3030,4 +3086,5 @@
 		free(exitp);
 	}
+*/
 	ENABLE_AST
 	return(1);
