From 8ca62cdf4bee6afb34c3e5f22e238bb8ea7c1007 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Thu, 17 Jun 2004 03:26:28 +0000 Subject: [PATCH] Update that integrates the session directory utilities into the sys_info and common_cmd_line functions. Calls to ompi_sys_info will now check for the universe session directory, and create it if it doesn't already exist. We will shortly be integrating the command line functions into these utilities so you can set the location and name of the session directory. Stay tuned - same bat channel, same batty minds... This commit was SVN r1351. --- src/util/Makefile.am | 2 ++ src/util/common_cmd_line.c | 3 +++ src/util/os_create_dirpath.c | 6 ++++-- src/util/os_session_dir.c | 32 ++++++++++--------------------- src/util/sys_info.c | 37 ++++++++++++++++++++++++++++++++++-- src/util/sys_info.h | 2 +- 6 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/util/Makefile.am b/src/util/Makefile.am index fd72f91bf1..c5a60a4684 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -22,6 +22,7 @@ headers = \ sys_info.h \ os_path.h \ os_create_dirpath.h \ + os_session_dir.h \ strncpy.h libutil_la_SOURCES = \ @@ -37,6 +38,7 @@ libutil_la_SOURCES = \ sys_info.c \ os_path.c \ os_create_dirpath.c \ + os_session_dir.c \ strncpy.c # Conditionally install the header files diff --git a/src/util/common_cmd_line.c b/src/util/common_cmd_line.c index 392aac4cba..fbd465d7cc 100644 --- a/src/util/common_cmd_line.c +++ b/src/util/common_cmd_line.c @@ -30,6 +30,9 @@ int ompi_common_cmd_line_init(int argc, char **argv) ompi_cmd_line_make_opt(ompi_common_cmd_line, 'u', "--universe", 1, "Specify the Open MPI universe"); + ompi_cmd_line_make_opt(ompi_common_cmd_line, + 't', "--tmpdir", 1, + "Specify the Open MPI prefix for the session directory"); /* Parse the command line */ diff --git a/src/util/os_create_dirpath.c b/src/util/os_create_dirpath.c index 322098ad5f..5a7236ee5d 100644 --- a/src/util/os_create_dirpath.c +++ b/src/util/os_create_dirpath.c @@ -19,7 +19,7 @@ int ompi_os_create_dirpath(const char *path, const mode_t mode) char *pth, *bottom_up; struct stat buf; - if (NULL == path) { /* protect ourselves from fools */ + if (NULL == path) { /* protect ourselves from errors */ return(OMPI_ERROR); } @@ -65,7 +65,9 @@ int ompi_os_create_dirpath(const char *path, const mode_t mode) while (strlen(bottom_up) > 1) { strcat(pth, ompi_system_info.path_sep); strcat(pth, basename(bottom_up)); - if (0 != mkdir(pth, mode)) { /* try to make the next layer - return error if can't */ + /* try to make the next layer - return error if can't & directory doesn't exist */ + /* if directory already exists, then that means somebody beat us to it - not an error */ + if ((0 != mkdir(pth, mode)) && (stat(pth, &buf) != 0)) { free(pth); free(bottom_up); return(OMPI_ERROR); diff --git a/src/util/os_session_dir.c b/src/util/os_session_dir.c index 316e938ce1..749c49e522 100644 --- a/src/util/os_session_dir.c +++ b/src/util/os_session_dir.c @@ -42,7 +42,6 @@ static int ompi_check_dir(bool create, char *directory) { struct stat buf; mode_t my_mode = S_IRWXU; /* at the least, I need to be able to do anything */ - mode_t mode_all = S_IRWXU | S_IRWXG | S_IRWXO; /* permissions for ompi-sessions directory - open to all */ if (0 == stat(directory, &buf)) { /* exists - check access */ if ((buf.st_mode & my_mode) == my_mode) { /* okay, I can work here */ @@ -50,7 +49,7 @@ static int ompi_check_dir(bool create, char *directory) } } if (create) { - return(ompi_os_create_dirpath(directory, mode_all)); /* try to create it, but ensure open to all */ + return(ompi_os_create_dirpath(directory, my_mode)); /* try to create it with proper mode */ } return(OMPI_ERROR); /* couldn't find it, or don't have access rights, and not asked to create it */ } @@ -60,7 +59,7 @@ char *ompi_find_session_dir(bool create, char *prefix) char *tmpprefix=NULL, *tmp=NULL; char *sessions=NULL; - sessions = strdup("openmpi-sessions"); + sprintf(sessions, "openmpi-sessions-%s", ompi_system_info.user); if (NULL != prefix) { tmpprefix = strdup(ompi_os_path(false, prefix, sessions, NULL)); /* make sure it's an absolute pathname */ @@ -121,22 +120,6 @@ char *ompi_find_session_dir(bool create, char *prefix) free(tmpprefix); } - if (NULL != getenv("HOME")) { - tmp = strdup(getenv("HOME")); - tmpprefix = strdup(ompi_os_path(false, tmp, sessions, NULL)); - if (OMPI_SUCCESS == ompi_check_dir(create, tmpprefix)) { /* check for existence and access, or create it */ - free(tmp); - free(sessions); - return(tmpprefix); - } - } - if (tmp != NULL) { - free(tmp); - } - if (tmpprefix != NULL) { - free(tmpprefix); - } - tmp = strdup(OMPI_DEFAULT_TMPDIR); tmpprefix = strdup(ompi_os_path(false, tmp, sessions, NULL)); if (OMPI_SUCCESS == ompi_check_dir(create, tmpprefix)) { /* check for existence and access, or create it */ @@ -170,8 +153,13 @@ int ompi_session_dir_init(char *prefix, char *universe) char *tmpprefix = NULL; char *name; - /* check if universe is specified - if not, error out */ + /* check if universe is specified - if not, use "default-universe" */ if (NULL == universe) { + universe = strdup("default-universe"); + } + + /* check to see if ompi_system_info populated - otherwise, error out */ + if (!ompi_system_info.init) { return(OMPI_ERROR); } @@ -180,8 +168,8 @@ int ompi_session_dir_init(char *prefix, char *universe) return (OMPI_ERROR); } - /* set up the name of the user's session directory, which is prefix/, and try to create it */ - name = ompi_os_path(false, tmpprefix, ompi_system_info.user, universe, NULL); + /* set up the name of the universe session directory, which is prefix/universe, and try to create it */ + name = ompi_os_path(false, tmpprefix, universe, NULL); if (OMPI_ERROR == ompi_os_create_dirpath(name, S_IRWXU)) { /* couldn't create the user directory */ free(tmpprefix); free(name); diff --git a/src/util/sys_info.c b/src/util/sys_info.c index c8d781ed33..8a9cbe3b64 100644 --- a/src/util/sys_info.c +++ b/src/util/sys_info.c @@ -9,8 +9,13 @@ #include #include +#include "ompi_config.h" + #include "include/constants.h" #include "util/sys_info.h" +#include "util/os_session_dir.h" +#include "util/cmd_line.h" +#include "util/common_cmd_line.h" ompi_sys_info_t ompi_system_info = { /* .init = */ false, @@ -30,14 +35,16 @@ ompi_sys_info_t ompi_system_info = { /* .sock_stderr = */ NULL}; -void ompi_sys_info(void) +int ompi_sys_info(void) { struct utsname sys_info; char *path_name, sep[2]; + char *universe = NULL; + char *tmpdir = NULL; struct passwd *pwdent; if (ompi_system_info.init) { - return; + return OMPI_SUCCESS; } if (0 > uname(&sys_info)) { /* have an error - set utsname values to indicate */ @@ -61,6 +68,7 @@ void ompi_sys_info(void) free(ompi_system_info.machine); ompi_system_info.machine = NULL; } + return OMPI_ERROR; } else { ompi_system_info.sysname = strdup(sys_info.sysname); ompi_system_info.nodename = strdup(sys_info.nodename); @@ -90,5 +98,30 @@ void ompi_sys_info(void) /* get the process id */ ompi_system_info.pid = getpid(); + /* set the init flag so that session_dir_init knows not to come back here */ ompi_system_info.init = true; /* only indicates that we have been through here once - still have to test for NULL values */ + + /* see if user specified universe name */ + if (ompi_cmd_line_is_taken(ompi_common_cmd_line, "universe")) { + if (NULL == ompi_cmd_line_get_param(ompi_common_cmd_line, "universe", 0, 0)) { + return(OMPI_ERROR); + } + universe = strdup(ompi_cmd_line_get_param(ompi_common_cmd_line, "universe", 0, 0)); + } + + /* see if user specified session directory prefix */ + if (ompi_cmd_line_is_taken(ompi_common_cmd_line, "tmpdir")) { + if (NULL == ompi_cmd_line_get_param(ompi_common_cmd_line, "tmpdir", 0, 0)) { + return(OMPI_ERROR); + } + tmpdir = strdup(ompi_cmd_line_get_param(ompi_common_cmd_line, "tmpdir", 0, 0)); + } + + /* get the session directory setup */ + if (OMPI_ERROR == ompi_session_dir_init(tmpdir, universe)) { + /* this is a serious error, so return the error condition */ + return(OMPI_ERROR); + } + + return(OMPI_SUCCESS); } diff --git a/src/util/sys_info.h b/src/util/sys_info.h index e2fa17e4d3..bc66b0b458 100644 --- a/src/util/sys_info.h +++ b/src/util/sys_info.h @@ -78,4 +78,4 @@ extern ompi_sys_info_t ompi_system_info; * @retval None */ -void ompi_sys_info(void); +int ompi_sys_info(void);