@@ -152,51 +152,67 @@ void pmix_errhandler_invoke(pmix_status_t status,
152152 pmix_proc_t procs [], size_t nprocs ,
153153 pmix_info_t info [], size_t ninfo )
154154{
155- #if 0
156155 /* We need to parse thru each registered handler and determine
157156 * which one to call for the specific error */
158- int i ;
157+ int i , idflt ;
159158 size_t j , k ;
160- bool exact_match = false;
159+ bool fired = false;
160+ bool exact_match ;
161161 int allerrhandler_ind = -1 ;
162- pmix_error_reg_info_t * errreg ;
162+ pmix_error_reg_info_t * errreg , * errdflt = NULL ;
163+ pmix_info_t * iptr ;
164+
165+ PMIX_INFO_CREATE (iptr , ninfo + 1 );
166+ (void )strncpy (iptr [0 ].key , PMIX_ERROR_HANDLER_ID , PMIX_MAX_KEYLEN );
167+ iptr [0 ].value .type = PMIX_INT ;
168+ for (j = 0 ; j < ninfo ; j ++ ) {
169+ PMIX_INFO_LOAD (& iptr [j + 1 ], info [j ].key , & info [j ].value .data , info [j ].value .type );
170+ }
163171
164- for (i = 0 ; i < pmix_globals .errregs .size && ! exact_match ; i ++ ) {
172+ for (i = 0 ; i < pmix_globals .errregs .size ; i ++ ) {
165173 if (NULL == (errreg = (pmix_error_reg_info_t * ) pmix_pointer_array_get_item (& pmix_globals .errregs , i ))) {
166174 continue ;
167175 }
168- if (0 == errreg -> ninfo ) {
169- // this is a general err handler we will call it if there is no better match
170- allerrhandler_ind = i ;
171- } else {
172- /* match error name key first */
173- for (j = 0 ; j < errreg -> ninfo ; j ++ ) {
174- if ((0 == strcmp (errreg -> info [j ].key , PMIX_ERROR_NAME )) &&
175- (status == errreg -> info [j ].value .data .int32 )) {
176- exact_match = true;
177- break ;
178- } else {
179- for (k = 0 ; k < errreg -> ninfo ; k ++ ) {
180- if ((0 == strcmp (errreg -> info [j ].key , info [k ].key )) &&
181- (pmix_value_cmp (& errreg -> info [j ].value , & info [k ].value ))) {
182- break ;
183- }
184- }
176+ if (NULL == errreg -> info || 0 == errreg -> ninfo ) {
177+ // this is a general err handler - we will call it if there is no better match
178+ errdflt = errreg ;
179+ idflt = i ;
180+ continue ;
181+ }
182+ iptr [0 ].value .data .integer = i ;
183+ /* match error name key first */
184+ exact_match = false;
185+ for (j = 0 ; j < errreg -> ninfo ; j ++ ) {
186+ if ((0 == strcmp (errreg -> info [j ].key , PMIX_ERROR_NAME )) &&
187+ (status == errreg -> info [j ].value .data .int32 )) {
188+ iptr [0 ].value .data .integer = i ;
189+ errreg -> errhandler (status , procs , nprocs , iptr , ninfo + 1 );
190+ fired = true;
191+ exact_match = true;
192+ break ;
193+ }
194+ }
195+ if (!exact_match ) {
196+ /* if no exact match was found, then we will fire the errhandler
197+ * for any matching info key. This may be too lax and need to be adjusted
198+ * later */
199+ for (k = 0 ; k < errreg -> ninfo ; k ++ ) {
200+ if ((0 == strcmp (errreg -> info [j ].key , info [k ].key )) &&
201+ (pmix_value_cmp (& errreg -> info [j ].value , & info [k ].value ))) {
202+ errreg -> errhandler (status , procs , nprocs , iptr , ninfo + 1 );
203+ fired = true;
185204 }
186205 }
187206 }
188207 }
189- for ( i = 0 ;i < nmatched ; i ++ ) {
190- errreg = (pmix_error_reg_info_t * ) pmix_pointer_array_get_item (& pmix_globals .errregs ,
191- matched_errregs [i ]);
192- errreg -> errhandler (status , procs , nprocs , info , ninfo );
193- }
194- if ( 0 == nmatched && 0 <= allerrhandler_ind ) {
195- errreg = (pmix_error_reg_info_t * ) pmix_pointer_array_get_item (& pmix_globals .errregs ,
196- allerrhandler_ind );
197- errreg -> errhandler (status , procs , nprocs , info , ninfo );
208+
209+ /* if nothing fired and we found a general err handler, then fire it */
210+ if (!fired && NULL != errdflt ) {
211+ iptr [0 ].value .data .integer = idflt ;
212+ errdflt -> errhandler (status , procs , nprocs , iptr , ninfo + 1 );
198213 }
199- #endif
214+ /* cleanup */
215+ PMIX_INFO_FREE (iptr , ninfo + 1 );
200216}
201217
202218pmix_status_t pmix_lookup_errhandler (pmix_notification_fn_t err ,
0 commit comments