Previously, with libfoo.so in the current directory, the following
command would fail:
glaze --wrapper=libfoo.so <program> <args>
And to fix things, the user would have to explicitly name the current
working directory such as:
glaze --wrapper=./libfoo.so <program> <args>
That seems like a silly requirement, (and is an artefact if the logic
of the dynamic loader).
To allow the convenient usage (without "./") we teach libglaze to
explicitly look for the wrapper in the current working directory, and
if found, to resolve its absolute path.
* If "wrapper" is an absolute path, return it directly.
*
* Otherwise, ("wrapper" is relative), look for an existing file named
* If "wrapper" is an absolute path, return it directly.
*
* Otherwise, ("wrapper" is relative), look for an existing file named
- * "wrapper" in the same directory as the currently executing binary,
- * (as determined by /proc/self/exe). If that file exists, return its
- * path.
+ * "wrapper" in the following locations in order:
+ *
+ * 1. The current working directory
+ *
+ * 2. The same directory as the currently executing binary, (as
+ * determined by /proc/self/exe).
+ *
+ * If either of those files exist, return its path.
*
* Otherwise, return the original, relative "wrapper".
*/
static const char *
resolve_wrapper_path (void *ctx, const char *wrapper)
{
*
* Otherwise, return the original, relative "wrapper".
*/
static const char *
resolve_wrapper_path (void *ctx, const char *wrapper)
{
- char *bin_path, *lib_path;
+ char *cwd_path, *bin_path, *lib_path;
+ /* Return absolute wrapper path immediately. */
if (*wrapper == '/')
return wrapper;
if (*wrapper == '/')
return wrapper;
+ /* Look for wrapper in current working directory. */
+ cwd_path = get_current_dir_name ();
+
+ lib_path = talloc_asprintf (ctx, "%s/%s", cwd_path, wrapper);
+
+ free (cwd_path);
+
+ if (exists (lib_path))
+ return lib_path;
+
+ talloc_free (lib_path);
+
+ /* Look for wrapper next to current executable. */
bin_path = get_bin_name (ctx);
chop_trailing_path_component (bin_path);
bin_path = get_bin_name (ctx);
chop_trailing_path_component (bin_path);
+ /* Allow relative wrapper path to remain as-is. */