1
1

Merge pull request #911 from rhc54/topic/cleanup

Cleanup the odls "close file descriptor" commit to conform to OMPI co…
Этот коммит содержится в:
rhc54 2015-09-20 07:01:39 -07:00
родитель 1367a442b6 c167acc5a7
Коммит 13def2a69b

Просмотреть файл

@ -15,7 +15,7 @@
* Copyright (c) 2010 IBM Corporation. All rights reserved.
* Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved
* Copyright (c) 2013-2015 Intel, Inc. All rights reserved
*
* $COPYRIGHT$
*
@ -361,20 +361,30 @@ static int close_open_file_descriptors(int write_fd,
int pid = getpid();
char *fds_dir = NULL;
int rc = asprintf(&fds_dir, "/proc/%d/fd", pid);
if (rc < 0) return ORTE_ERR_OUT_OF_RESOURCE;
if (rc < 0) {
return ORTE_ERR_OUT_OF_RESOURCE;
}
DIR *dir = opendir(fds_dir);
free(fds_dir);
if (dir == NULL) return ORTE_ERR_FILE_OPEN_FAILURE;
if (NULL == dir) {
return ORTE_ERR_FILE_OPEN_FAILURE;
}
struct dirent *files;
while ((files = readdir(dir)) != NULL) {
if(!strncmp(files->d_name,".",1) || !strncmp(files->d_name,"..",2))
while (NULL != (files = readdir(dir))) {
if (0 == strncmp(files->d_name,".",1) ||
0 == strncmp(files->d_name,"..",2)) {
continue;
unsigned int fd = strtoul(files->d_name, NULL, 10);
if (errno == EINVAL || errno == ERANGE) return ORTE_ERR_TYPE_MISMATCH;
}
int fd = strtol(files->d_name, NULL, 10);
if (errno == EINVAL || errno == ERANGE) {
closedir(dir);
return ORTE_ERR_TYPE_MISMATCH;
}
if (fd >=3 && fd != opts.p_internal[1] && fd != write_fd) {
close(fd);
}
}
closedir(dir);
return ORTE_SUCCESS;
}