Skip to content

Commit

Permalink
flux: rework FLUX_EXEC_PATH logic
Browse files Browse the repository at this point in the history
Command line is no longer an override.  Instead prepend higher
priorities paths so we fall through to find stuff.
  • Loading branch information
garlick committed Sep 30, 2014
1 parent a81aac7 commit f357f76
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/cmd/flux.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,41 @@ int setup_lua_env (const char *topdir)
return (0);
}

static void path_push (char **path, const char *add)
{
char *new = xasprintf ("%s%s%s", add, *path ? ":" : "",
*path ? *path : "");
free (*path);
*path = new;
}

void setup_exec_env (const char *xopt, const char *topdir)
{
char *s, *path = NULL;

path_push (&path, EXEC_PATH);
if (topdir) {
s = xasprintf ("%s/src/cmd", topdir);
path_push (&path, s);
free (s);
}
if ((s = getenv ("FLUX_EXEC_PATH")))
path_push (&path, s);
if (xopt)
path_push (&path, xopt);
if (setenv ("FLUX_EXEC_PATH", path, 1) < 0)
err_exit ("%s", path);
free (path);
}

int main (int argc, char *argv[])
{
int ch;
bool hopt = false;
bool vopt = false;
char *flux_exe_dir = dir_self ();
char *flux_top_builddir = getenv ("FLUX_TOP_BUILDDIR");
char *xopt = NULL;

log_init ("flux");

Expand All @@ -132,8 +160,7 @@ int main (int argc, char *argv[])
err_exit ("setenv FLUX_MODULE_PATH=%s", optarg);
break;
case 'x': /* --exec-path */
if (setenv ("FLUX_EXEC_PATH", optarg, 1) < 0)
err_exit ("setenv FLUX_EXEC_PATH=%s", optarg);
xopt = optarg;
break;
case 'B': /* --cmbd-path */
if (setenv ("FLUX_CMBD_PATH", optarg, 1) < 0)
Expand All @@ -153,11 +180,11 @@ int main (int argc, char *argv[])
argc -= optind;
argv += optind;

setup_exec_env (xopt, flux_top_builddir);

if (strcmp (flux_exe_dir, X_BINDIR) != 0) {
glob_t gl;
char *modpath;
if (setenv ("FLUX_EXEC_PATH", ".", 0) < 0)
err_exit ("setenv");
if (glob ("../modules/*/.libs", GLOB_ONLYDIR, NULL, &gl) == 0) {
modpath = argv_concat (gl.gl_pathc, gl.gl_pathv, ":");
globfree (&gl);
Expand All @@ -168,8 +195,6 @@ int main (int argc, char *argv[])
if (setenv ("FLUX_CMBD_PATH", "../broker/cmbd", 0) < 0)
err_exit ("setenv");
} else {
if (setenv ("FLUX_EXEC_PATH", EXEC_PATH, 0) < 0)
err_exit ("setenv");
if (setenv ("FLUX_CMBD_PATH", CMBD_PATH, 0) < 0)
err_exit ("setenv");
}
Expand Down

0 comments on commit f357f76

Please sign in to comment.