Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/pm/hydra/libhydra/fs/hydra_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,44 @@ char *HYD_find_full_path(const char *execname)
fn_fail:
goto fn_exit;
}

char *HYD_find_base_path(const char *execname)
{
char *post = NULL, *loc, *basepath = NULL;
HYD_status status = HYD_SUCCESS;
char *tmp[HYD_NUM_TMP_STRINGS];

HYD_FUNC_ENTER();

post = MPL_strdup(execname);
loc = strrchr(post, '/');
if (!loc) {
status = HYD_find_in_path(execname, &basepath);
HYD_ERR_POP(status, "error while searching for executable in the user path\n");
}
else {
*(++loc) = 0;
/* Check if it is absolute or relative */
if (post[0] != '/') { /* relative */
tmp[0] = HYD_getcwd();
tmp[1] = MPL_strdup("/");
tmp[2] = MPL_strdup(post);
tmp[3] = NULL;
status = HYD_str_alloc_and_join(tmp, &basepath);
HYD_ERR_POP(status, "unable to join strings\n");
HYD_str_free_list(tmp);
}
else { /* absolute */
basepath = MPL_strdup(post);
}
}

fn_exit:
if(post)
MPL_free(post);
HYD_FUNC_EXIT();
return basepath;

fn_fail:
goto fn_exit;
}
1 change: 1 addition & 0 deletions src/pm/hydra/libhydra/fs/hydra_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
HYD_status HYD_find_in_path(const char *execname, char **path);
char *HYD_getcwd(void);
char *HYD_find_full_path(const char *execname);
char *HYD_find_base_path(const char *execname);

#endif /* HYDRA_FS_H_INCLUDED */
28 changes: 1 addition & 27 deletions src/pm/hydra/mpiexec/mpiexec_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,33 +929,7 @@ HYD_status mpiexec_get_parameters(char **t_argv)
/***** AUTO-DETECT/COMPUTE PARAMETERS ****/

/* Get the base path */
/* Find the last '/' in the executable name */
post = MPL_strdup(progname);
loc = strrchr(post, '/');
if (!loc) { /* If there is no path */
mpiexec_params.base_path = NULL;
status = HYD_find_in_path(progname, &mpiexec_params.base_path);
HYD_ERR_POP(status, "error while searching for executable in the user path\n");
}
else { /* There is a path */
*(++loc) = 0;

/* Check if its absolute or relative */
if (post[0] != '/') { /* relative */
tmp[0] = HYD_getcwd();
tmp[1] = MPL_strdup("/");
tmp[2] = MPL_strdup(post);
tmp[3] = NULL;
status = HYD_str_alloc_and_join(tmp, &mpiexec_params.base_path);
HYD_ERR_POP(status, "unable to join strings\n");
HYD_str_free_list(tmp);
}
else { /* absolute */
mpiexec_params.base_path = MPL_strdup(post);
}
}
MPL_free(post);

mpiexec_params.base_path = HYD_find_base_path(progname);

/***** DEFAULT PARAMETERS ****/

Expand Down