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) 2010 IBM Corporation. All rights reserved.
* Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights * Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved * Copyright (c) 2013-2015 Intel, Inc. All rights reserved
* *
* $COPYRIGHT$ * $COPYRIGHT$
* *
@ -358,24 +358,34 @@ static void send_error_show_help(int fd, int exit_status,
the parent. */ the parent. */
static int close_open_file_descriptors(int write_fd, static int close_open_file_descriptors(int write_fd,
orte_iof_base_io_conf_t opts) { orte_iof_base_io_conf_t opts) {
int pid = getpid(); int pid = getpid();
char *fds_dir = NULL; char *fds_dir = NULL;
int rc = asprintf(&fds_dir, "/proc/%d/fd", pid); int rc = asprintf(&fds_dir, "/proc/%d/fd", pid);
if (rc < 0) return ORTE_ERR_OUT_OF_RESOURCE; if (rc < 0) {
DIR *dir = opendir(fds_dir); return ORTE_ERR_OUT_OF_RESOURCE;
free(fds_dir); }
if (dir == NULL) return ORTE_ERR_FILE_OPEN_FAILURE; DIR *dir = opendir(fds_dir);
struct dirent *files; free(fds_dir);
while ((files = readdir(dir)) != NULL) { if (NULL == dir) {
if(!strncmp(files->d_name,".",1) || !strncmp(files->d_name,"..",2)) return ORTE_ERR_FILE_OPEN_FAILURE;
continue; }
unsigned int fd = strtoul(files->d_name, NULL, 10); struct dirent *files;
if (errno == EINVAL || errno == ERANGE) return ORTE_ERR_TYPE_MISMATCH; while (NULL != (files = readdir(dir))) {
if (fd >=3 && fd != opts.p_internal[1] && fd != write_fd) { if (0 == strncmp(files->d_name,".",1) ||
close(fd); 0 == strncmp(files->d_name,"..",2)) {
} continue;
} }
return ORTE_SUCCESS; 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;
} }
static int do_child(orte_app_context_t* context, static int do_child(orte_app_context_t* context,
@ -459,12 +469,12 @@ static int do_child(orte_app_context_t* context,
the pipe used for the IOF INTERNAL messages, and the pipe up to the pipe used for the IOF INTERNAL messages, and the pipe up to
the parent. */ the parent. */
if (ORTE_SUCCESS != close_open_file_descriptors(write_fd, opts)) { if (ORTE_SUCCESS != close_open_file_descriptors(write_fd, opts)) {
// close *all* file descriptors -- slow // close *all* file descriptors -- slow
for(fd=3; fd<fdmax; fd++) { for(fd=3; fd<fdmax; fd++) {
if (fd != opts.p_internal[1] && fd != write_fd) { if (fd != opts.p_internal[1] && fd != write_fd) {
close(fd); close(fd);
}
} }
}
} }
if (context->argv == NULL) { if (context->argv == NULL) {