* 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)
{
- char *bin_path, *lib_path;
+ char *cwd_path, *bin_path, *lib_path;
+ /* Return absolute wrapper path immediately. */
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);
talloc_free (lib_path);
+ /* Allow relative wrapper path to remain as-is. */
return wrapper;
}