@@ -218,9 +218,12 @@ pmix_output(0, "TOOL INIT");
218218 if (0 == strcmp (PMIX_EVENT_BASE , info [n ].key )) {
219219 pmix_globals .evbase = (pmix_event_base_t * )info [n ].value .data .ptr ;
220220 pmix_globals .external_evbase = true;
221+ } else if (strcmp (info [i ].key , PMIX_SERVER_PIDINFO ) == 0 ) {
222+ server_pid = info [i ].value .data .integer ;
221223 }
222224 }
223225 }
226+
224227 /* setup the globals */
225228 pmix_globals_init ();
226229 PMIX_CONSTRUCT (& pmix_client_globals .pending_requests , pmix_list_t );
@@ -254,31 +257,19 @@ pmix_output(0, "TOOL INIT");
254257 }
255258 }
256259
257- /* setup the path to the daemon rendezvous point */
258- memset (& address , 0 , sizeof (struct sockaddr_un ));
259- address .sun_family = AF_UNIX ;
260- /* Get first 10 char's of hostname to match what the server is doing */
261- gethostname (hostname , hostnamelen );
262-
263- /* Get the local hostname, and look for a file named
264- * /tmp/pmix.hostname.tool - this file will contain
265- * the URI where the server is listening. The URI consists
266- * of 3 parts - the code below will parse the string read
267- * from the file and connect accordingly */
260+ /* setup the path to the daemon rendezvous point */
261+ memset (& address , 0 , sizeof (struct sockaddr_un ));
262+ address .sun_family = AF_UNIX ;
263+ /* Get first 10 char's of hostname to match what the server is doing */
264+ gethostname (hostname , hostnamelen );
268265
269- for (i = 0 ; i < (int )ninfo ; i ++ ) {
270- if (strcmp (info [i ].key , PMIX_SERVER_PIDINFO ) == 0 ) {
271- server_pid = info [i ].value .data .integer ;
272- break ;
273- }
274- }
275266 /* if they gave us a specific pid, then look for that
276267 * particular server - otherwise, see if there is only
277268 * one on this node and default to it */
278269 if (server_pid != -1 ) {
279270 snprintf (address .sun_path , sizeof (address .sun_path )- 1 , "%s/pmix.%s.%d" , tdir , hostname , server_pid );
280271 /* if the rendezvous file doesn't exist, that's an error */
281- if (0 != access (address .sun_path , R_OK )) {
272+ if (0 != access (address .sun_path , R_OK )) {
282273 pmix_output_close (pmix_globals .debug_output );
283274 pmix_output_finalize ();
284275 pmix_class_finalize ();
@@ -294,13 +285,16 @@ pmix_output(0, "TOOL INIT");
294285 }
295286 /* search the entries for something that starts with pmix.hostname */
296287 if (0 > asprintf (& tmp , "pmix.%s" , hostname )) {
288+ closedir (cur_dirp );
297289 return PMIX_ERR_NOMEM ;
298290 }
299291 evar = NULL ;
300292 while (NULL != (dir_entry = readdir (cur_dirp ))) {
301293 if (0 == strncmp (dir_entry -> d_name , tmp , strlen (tmp ))) {
302294 /* found one - if more than one, then that's an error */
303295 if (NULL != evar ) {
296+ closedir (cur_dirp );
297+ free (evar );
304298 free (tmp );
305299 pmix_output_close (pmix_globals .debug_output );
306300 pmix_output_finalize ();
@@ -833,24 +827,23 @@ static pmix_status_t usock_connect(struct sockaddr_un *addr, int *fd)
833827 "timeout connecting to server" );
834828 CLOSE_THE_SOCKET (sd );
835829 continue ;
836- }
837-
838- /* Some kernels (Linux 2.6) will automatically software
839- abort a connection that was ECONNREFUSED on the last
840- attempt, without even trying to establish the
841- connection. Handle that case in a semi-rational
842- way by trying twice before giving up */
843- else if (ECONNABORTED == pmix_socket_errno ) {
830+ } else if (ECONNABORTED == pmix_socket_errno ) {
831+ /* Some kernels (Linux 2.6) will automatically software
832+ abort a connection that was ECONNREFUSED on the last
833+ attempt, without even trying to establish the
834+ connection. Handle that case in a semi-rational
835+ way by trying twice before giving up */
844836 pmix_output_verbose (2 , pmix_globals .debug_output ,
845837 "connection to server aborted by OS - retrying" );
846838 CLOSE_THE_SOCKET (sd );
847839 continue ;
848840 } else {
849841 pmix_output_verbose (2 , pmix_globals .debug_output ,
850842 "Failed to connect, errno = %d, err= %s\n" , errno , strerror (errno ));
843+ CLOSE_THE_SOCKET (sd );
851844 continue ;
845+ }
852846 }
853- }
854847 /* otherwise, the connect succeeded - so break out of the loop */
855848 break ;
856849 }
0 commit comments