Skip to content

Commit 7633c42

Browse files
authored
Merge pull request #6304 from uberlinuxguy/issue_6303_race_fix
Adding changes for issue #6303 for branch master.
2 parents 352b667 + 98d81a5 commit 7633c42

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

orte/mca/odls/alps/odls_alps_module.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ static int close_open_file_descriptors(int write_fd,
298298
return ORTE_ERR_FILE_OPEN_FAILURE;
299299
}
300300
struct dirent *files;
301+
302+
/* grab the fd of the opendir above so we don't close in the
303+
* middle of the scan. */
304+
int dir_scan_fd = dirfd(dir);
305+
if(dir_scan_fd < 0 ) {
306+
return ORTE_ERR_FILE_OPEN_FAILURE;
307+
}
308+
309+
301310
while (NULL != (files = readdir(dir))) {
302311
if (!isdigit(files->d_name[0])) {
303312
continue;
@@ -311,7 +320,8 @@ static int close_open_file_descriptors(int write_fd,
311320
#if OPAL_PMIX_V1
312321
fd != opts.p_internal[1] &&
313322
#endif
314-
fd != write_fd) {
323+
fd != write_fd &&
324+
fd != dir_scan_fd) {
315325
close(fd);
316326
}
317327
}

orte/mca/odls/default/odls_default_module.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ static int close_open_file_descriptors(int write_fd,
302302
return ORTE_ERR_FILE_OPEN_FAILURE;
303303
}
304304
struct dirent *files;
305+
306+
/* grab the fd of the opendir above so we don't close in the
307+
* middle of the scan. */
308+
int dir_scan_fd = dirfd(dir);
309+
if(dir_scan_fd < 0 ) {
310+
return ORTE_ERR_FILE_OPEN_FAILURE;
311+
}
312+
313+
305314
while (NULL != (files = readdir(dir))) {
306315
if (!isdigit(files->d_name[0])) {
307316
continue;
@@ -315,7 +324,8 @@ static int close_open_file_descriptors(int write_fd,
315324
#if OPAL_PMIX_V1
316325
fd != opts.p_internal[1] &&
317326
#endif
318-
fd != write_fd) {
327+
fd != write_fd &&
328+
fd != dir_scan_fd) {
319329
close(fd);
320330
}
321331
}

orte/mca/odls/pspawn/odls_pspawn.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ static int close_open_file_descriptors(posix_spawn_file_actions_t *factions)
231231
return ORTE_ERR_FILE_OPEN_FAILURE;
232232
}
233233
struct dirent *files;
234+
235+
/* grab the fd of the opendir above so we don't close in the
236+
* middle of the scan. */
237+
int dir_scan_fd = dirfd(dir);
238+
if(dir_scan_fd < 0 ) {
239+
return ORTE_ERR_FILE_OPEN_FAILURE;
240+
}
241+
234242
while (NULL != (files = readdir(dir))) {
235243
if (!isdigit(files->d_name[0])) {
236244
continue;
@@ -240,7 +248,7 @@ static int close_open_file_descriptors(posix_spawn_file_actions_t *factions)
240248
closedir(dir);
241249
return ORTE_ERR_TYPE_MISMATCH;
242250
}
243-
if (fd >=3) {
251+
if (fd >=3 && fd != dir_scan_fd) {
244252
posix_spawn_file_actions_addclose(factions, fd);
245253
}
246254
}

0 commit comments

Comments
 (0)