diff --git a/orte/mca/odls/alps/odls_alps_module.c b/orte/mca/odls/alps/odls_alps_module.c index 8de9665c16a..8d25e798518 100644 --- a/orte/mca/odls/alps/odls_alps_module.c +++ b/orte/mca/odls/alps/odls_alps_module.c @@ -298,6 +298,15 @@ static int close_open_file_descriptors(int write_fd, return ORTE_ERR_FILE_OPEN_FAILURE; } struct dirent *files; + + /* grab the fd of the opendir above so we don't close in the + * middle of the scan. */ + int dir_scan_fd = dirfd(dir); + if(dir_scan_fd < 0 ) { + return ORTE_ERR_FILE_OPEN_FAILURE; + } + + while (NULL != (files = readdir(dir))) { if (!isdigit(files->d_name[0])) { continue; @@ -311,7 +320,8 @@ static int close_open_file_descriptors(int write_fd, #if OPAL_PMIX_V1 fd != opts.p_internal[1] && #endif - fd != write_fd) { + fd != write_fd && + fd != dir_scan_fd) { close(fd); } } diff --git a/orte/mca/odls/default/odls_default_module.c b/orte/mca/odls/default/odls_default_module.c index b9c6f665ce3..ab9d6e442f6 100644 --- a/orte/mca/odls/default/odls_default_module.c +++ b/orte/mca/odls/default/odls_default_module.c @@ -302,6 +302,15 @@ static int close_open_file_descriptors(int write_fd, return ORTE_ERR_FILE_OPEN_FAILURE; } struct dirent *files; + + /* grab the fd of the opendir above so we don't close in the + * middle of the scan. */ + int dir_scan_fd = dirfd(dir); + if(dir_scan_fd < 0 ) { + return ORTE_ERR_FILE_OPEN_FAILURE; + } + + while (NULL != (files = readdir(dir))) { if (!isdigit(files->d_name[0])) { continue; @@ -315,7 +324,8 @@ static int close_open_file_descriptors(int write_fd, #if OPAL_PMIX_V1 fd != opts.p_internal[1] && #endif - fd != write_fd) { + fd != write_fd && + fd != dir_scan_fd) { close(fd); } }