From 3d8ddbc13642ef27f5ebfa6c53c5a44ccfd495c6 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Fri, 25 Jan 2019 09:27:33 -0500 Subject: [PATCH] Adding changes for issue #6303 for branch v4.0.x. Signed-off-by: Jason Williams (cherry picked from commit 98d81a5f7a619d5a19615297a6fe8a18d8e3781c) --- orte/mca/odls/alps/odls_alps_module.c | 12 +++++++++++- orte/mca/odls/default/odls_default_module.c | 12 +++++++++++- orte/mca/odls/pspawn/odls_pspawn.c | 10 +++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/orte/mca/odls/alps/odls_alps_module.c b/orte/mca/odls/alps/odls_alps_module.c index 8de9665c16..8d25e79851 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 b9c6f665ce..ab9d6e442f 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); } } diff --git a/orte/mca/odls/pspawn/odls_pspawn.c b/orte/mca/odls/pspawn/odls_pspawn.c index 537f1a70ea..7909d210c6 100644 --- a/orte/mca/odls/pspawn/odls_pspawn.c +++ b/orte/mca/odls/pspawn/odls_pspawn.c @@ -231,6 +231,14 @@ static int close_open_file_descriptors(posix_spawn_file_actions_t *factions) 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; @@ -240,7 +248,7 @@ static int close_open_file_descriptors(posix_spawn_file_actions_t *factions) closedir(dir); return ORTE_ERR_TYPE_MISMATCH; } - if (fd >=3) { + if (fd >=3 && fd != dir_scan_fd) { posix_spawn_file_actions_addclose(factions, fd); } }