Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
abstract in-tree detection into libutil, remove FLUX_CONF_INTREE environment variable #2351
This is split off the shell plugin work, since it is fairly independent and may actually generate some discussion on its own.
In the shell we want to load a different default initrc depending on if we're running "in-tree" or not, but the code to detect if an executable was only available in
This PR abstracts the in-tree detection into
int executable_is_intree (void); const char *executable_selfdir (void);
The algorithm for
Additionally, the new code only computes results on the first call, since both the intree value and executable directory obviously will not change. Since the calls may now be made from broker modules, the critical sections and memoized results are protected by a mutex (since it seems flux commands are already linked with libpthread anyway)
Finally, users of
I meant to comment that I wasn't sure of a valid way to add unit tests. I could easily add unit tests to ensure that the unit test itself is detected as running in-tree if you think that would help?
Oops, sorry. Already wrote up a quick unit test -- also exercised threaded access to the function to ensure no issues there (test could be flawed, just starts 16 threads in a barrier and tries to call
Copy functionality from src/cmd/flux.c to detect if flux components are running "in-tree" into libutil/intree.[ch], with some differences noted below: Rename dir_self() and flux_is_installed() to executable_selfdir() and executable_is_intree(). Rather than comparing directories directly, this version of executable_is_intree() works by comparing the discovered directory to the current executable to the absolute top builddir ($abs_top_buildir as exported by Makfele.am) to determine if the executable was run from *any* subdirectory of the top build dir. Results from both executable_is_intree() and executable_selfdir() are memoized on the first call so that multiple calls don't have to open "/proc/self/exec", call realpath(3), etc, and it is known that the results will never change for a given executable. However, since broker modules may call into these functions, the calls are made thread safe by wrapping critical sections in a mutex.
Switch flux_is_installed() to use the provided libutil executable_is_intree() interface. Similarly, replace dir_self() with executable_selfdir(). Since executable_selfdir() returns a const char *, simplify the call and remove the free() of the result.
Update job-exec module to use executable_is_intree() instead of FLUX_CONF_INTREE environment variable. Also moves default_job_shell to a static global so it doesn't have to be recomputed each time a job is launched.
Drop use of FLUX_CONF_INTREE environment variable for in-tree detection and use libutil/intree executable_is_intree() instead.
Problem: The FLUX_CONF_INTREE environment variable may be somewhat brittle as a method to determine if flux components are running in-tree or not. For example, the variable is exported, but never unset, and it is unclear what effect this might have on jobs, etc. Now that there are no users of FLUX_CONF_INTREE, just drop it.
@@ Coverage Diff @@ ## master #2351 +/- ## ========================================== - Coverage 80.82% 80.81% -0.01% ========================================== Files 217 218 +1 Lines 34518 34530 +12 ========================================== + Hits 27898 27907 +9 - Misses 6620 6623 +3