Skip to content

Commit

Permalink
flux: exec subcommand directly if it contains /
Browse files Browse the repository at this point in the history
This allows an installed version of the flux command driver to be used
in front of a command in development.  For example
   flux ./flux-newcommand
  • Loading branch information
garlick committed Sep 30, 2014
1 parent de50b17 commit 368c0b0
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/cmd/flux.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ char *dir_self (void)
void exec_subcommand_dir (bool vopt, const char *dir,char *argv[],
const char *prefix)
{
char *path;
if (asprintf (&path, "%s/%s%s", dir, prefix ? prefix : "", argv[0]) < 0)
oom ();
char *path = xasprintf ("%s%s%s%s",
dir ? dir : "",
dir ? "/" : "",
prefix ? prefix : "", argv[0]);
if (vopt)
msg ("trying to exec %s", path);
execvp (path, argv); /* no return if successful */
Expand All @@ -241,17 +242,22 @@ void exec_subcommand_dir (bool vopt, const char *dir,char *argv[],

void exec_subcommand (bool vopt, char *argv[])
{
char *searchpath = getenv ("FLUX_EXEC_PATH"); // assert != NULL
char *cpy = xstrdup (searchpath);
char *dir, *saveptr = NULL, *a1 = cpy;

while ((dir = strtok_r (a1, ":", &saveptr))) {
exec_subcommand_dir (vopt, dir, argv, "flux-");
//exec_subcommand_dir (vopt, dir, argv, NULL); /* deprecated */
a1 = NULL;
if (strchr (argv[0], '/')) {
exec_subcommand_dir (vopt, NULL, argv, NULL);
err_exit ("%s", argv[0]);
} else {
char *searchpath = getenv ("FLUX_EXEC_PATH"); // assert != NULL
char *cpy = xstrdup (searchpath);
char *dir, *saveptr = NULL, *a1 = cpy;

while ((dir = strtok_r (a1, ":", &saveptr))) {
exec_subcommand_dir (vopt, dir, argv, "flux-");
a1 = NULL;
}
free (cpy);
msg_exit ("`%s' is not a flux command. See 'flux --help'", argv[0]);
}
free (cpy);
msg_exit ("`%s' is not a flux command. See 'flux --help'", argv[0]);
}

/*
Expand Down

0 comments on commit 368c0b0

Please sign in to comment.