Просмотр исходного кода

- Handling of HUP and other poll errors improved in saAmfDispatch.
- Termination of testamf1 when saAmfDispatch returns an error.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1171 fd59a12c-fef9-0310-b244-a6a79926bd2f

Hans Feldt 19 лет назад
Родитель
Сommit
99948bf07b
2 измененных файлов с 23 добавлено и 15 удалено
  1. 16 13
      lib/amf.c
  2. 7 2
      test/testamf1.c

+ 16 - 13
lib/amf.c

@@ -191,13 +191,16 @@ saAmfDispatch (
 	struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
 	struct res_lib_amf_healthcheckcallback *res_lib_amf_healthcheckcallback;
 	struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
 	struct res_lib_amf_csiremovecallback *res_lib_amf_csiremovecallback;
 	struct res_lib_amf_componentterminatecallback *res_lib_amf_componentterminatecallback;
 	struct res_lib_amf_componentterminatecallback *res_lib_amf_componentterminatecallback;
-
-	/*
-	struct res_lib_amf_protectiongrouptrackcallback *res_lib_amf_protectiongrouptrackcallback;
-	*/
 	SaAmfCallbacksT callbacks;
 	SaAmfCallbacksT callbacks;
 	struct res_overlay dispatch_data;
 	struct res_overlay dispatch_data;
 
 
+	if (dispatchFlags != SA_DISPATCH_ONE &&
+		dispatchFlags != SA_DISPATCH_ALL &&
+		dispatchFlags != SA_DISPATCH_BLOCKING) {
+
+		return (SA_AIS_ERR_INVALID_PARAM);
+	}
+
 	error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
 	error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
 		(void *)&amfInstance);
 		(void *)&amfInstance);
 	if (error != SA_AIS_OK) {
 	if (error != SA_AIS_OK) {
@@ -221,23 +224,21 @@ saAmfDispatch (
 
 
 		error = saPollRetry (&ufds, 1, timeout);
 		error = saPollRetry (&ufds, 1, timeout);
 		if (error != SA_AIS_OK) {
 		if (error != SA_AIS_OK) {
-			goto error_nounlock;
+			goto error_put;
 		}
 		}
 
 
 		pthread_mutex_lock (&amfInstance->dispatch_mutex);
 		pthread_mutex_lock (&amfInstance->dispatch_mutex);
 
 
-		error = saPollRetry (&ufds, 1, 0);
-		if (error != SA_AIS_OK) {
-			goto error_nounlock;
-		}
-
 		/*
 		/*
 		 * Handle has been finalized in another thread
 		 * Handle has been finalized in another thread
 		 */
 		 */
 		if (amfInstance->finalize == 1) {
 		if (amfInstance->finalize == 1) {
 			error = SA_AIS_OK;
 			error = SA_AIS_OK;
-			pthread_mutex_unlock (&amfInstance->dispatch_mutex);
+			goto error_unlock;
+		}
 
 
+		if ((ufds.revents & (POLLERR|POLLHUP|POLLNVAL)) != 0) {
+			error = SA_AIS_ERR_BAD_HANDLE;
 			goto error_unlock;
 			goto error_unlock;
 		}
 		}
 
 
@@ -378,7 +379,7 @@ saAmfDispatch (
 			break;
 			break;
 		default:
 		default:
 			error = SA_AIS_ERR_LIBRARY;	
 			error = SA_AIS_ERR_LIBRARY;	
-			goto error_nounlock;
+			goto error_put;
 			break;
 			break;
 		}
 		}
 
 
@@ -397,8 +398,10 @@ saAmfDispatch (
 	} while (cont);
 	} while (cont);
 
 
 error_unlock:
 error_unlock:
+	pthread_mutex_unlock (&amfInstance->dispatch_mutex);
+error_put:
 	saHandleInstancePut (&amfHandleDatabase, amfHandle);
 	saHandleInstancePut (&amfHandleDatabase, amfHandle);
-error_nounlock:
+
 	return (error);
 	return (error);
 }
 }
 
 

+ 7 - 2
test/testamf1.c

@@ -370,9 +370,14 @@ int main (int argc, char **argv) {
 
 
 	do {
 	do {
 		select (select_fd + 1, &read_fds, 0, 0, 0);
 		select (select_fd + 1, &read_fds, 0, 0, 0);
-		saAmfDispatch (handle, SA_DISPATCH_ALL);
+		result = saAmfDispatch (handle, SA_DISPATCH_ALL);
+
+		if (result != SA_AIS_OK) {
+			exit (-1);
+		}
 	} while (result && stop == 0);
 	} while (result && stop == 0);
 
 
+
 	printf ("healthchecks stopped for 5 seconds\n");
 	printf ("healthchecks stopped for 5 seconds\n");
 	sleep (5);
 	sleep (5);
 	result = saAmfHealthcheckStart (handle,
 	result = saAmfHealthcheckStart (handle,
@@ -383,7 +388,7 @@ int main (int argc, char **argv) {
 
 
 	do {
 	do {
 		select (select_fd + 1, &read_fds, 0, 0, 0);
 		select (select_fd + 1, &read_fds, 0, 0, 0);
-		saAmfDispatch (handle, SA_DISPATCH_ALL);
+		result = saAmfDispatch (handle, SA_DISPATCH_ALL);
 	} while (result);
 	} while (result);
 
 
 	saAmfFinalize (handle);
 	saAmfFinalize (handle);