diff --git a/orte/mca/odls/alps/odls_alps_module.c b/orte/mca/odls/alps/odls_alps_module.c index 0d655a4d7d..0413b841cd 100644 --- a/orte/mca/odls/alps/odls_alps_module.c +++ b/orte/mca/odls/alps/odls_alps_module.c @@ -356,21 +356,15 @@ static void send_error_show_help(int fd, int exit_status, static int close_open_file_descriptors(int write_fd, orte_iof_base_io_conf_t opts) { - int pid, rc, fd; - char *fds_dir = NULL; + int rc, fd; DIR *dir = NULL; struct dirent *files; - int app_alps_filedes[2],alps_app_filedes[2]; + int app_alps_filedes[2], alps_app_filedes[2]; - pid = getpid(); - - rc = asprintf(&fds_dir, "/proc/%d/fd", pid); - if (rc < 0) return ORTE_ERR_OUT_OF_RESOURCE; - - dir = opendir(fds_dir); - free(fds_dir); - - if (dir == NULL) return ORTE_ERR_FILE_OPEN_FAILURE; + dir = opendir("/proc/self/fd"); + if (NULL == dir) { + return ORTE_ERR_FILE_OPEN_FAILURE; + } /* close all file descriptors w/ exception of stdin/stdout/stderr, the pipe used for the IOF INTERNAL messages, and the pipe up to @@ -380,6 +374,7 @@ static int close_open_file_descriptors(int write_fd, orte_iof_base_io_conf_t opt rc = alps_app_lli_pipes(app_alps_filedes,alps_app_filedes); if (0 != rc) { + closedir(dir); return ORTE_ERR_FILE_OPEN_FAILURE; } @@ -387,7 +382,10 @@ static int close_open_file_descriptors(int write_fd, orte_iof_base_io_conf_t opt if(!strncmp(files->d_name,".",1) || !strncmp(files->d_name,"..",2)) continue; fd = strtoul(files->d_name, NULL, 10); - if (errno == EINVAL || errno == ERANGE) return ORTE_ERR_TYPE_MISMATCH; + if (EINVAL == errno || ERANGE == errno) { + closedir(dir); + return ORTE_ERR_TYPE_MISMATCH; + } /* * skip over the pipes we have open to apshepherd or slurmd @@ -404,6 +402,8 @@ static int close_open_file_descriptors(int write_fd, orte_iof_base_io_conf_t opt close(fd); } } + + closedir(dir); return ORTE_SUCCESS; }