From 96ace65d59a6496e43e09483df4018b077c47567 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Mon, 4 Nov 2019 19:38:07 +0000 Subject: [PATCH] utils: Always look in helpers directory before PATH Previously, we always looked for vulkaninfo and wflinfo in the PATH. Now we look in the helpers directory, and only search the PATH if the necessary executable isn't there. This enables us to ship relative symlinks from the helpers directory /usr/libexec/steam-runtime-tools-0 to an adjacent /usr/bin directory, so that if the Steam Runtime is relocated to (for example) .../steam-runtime, we will find vulkaninfo and wflinfo in .../steam-runtime/usr/bin. Signed-off-by: Simon McVittie <smcv@collabora.com> --- steam-runtime-tools/utils.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/steam-runtime-tools/utils.c b/steam-runtime-tools/utils.c index 5b2cbca9e..00d734632 100644 --- a/steam-runtime-tools/utils.c +++ b/steam-runtime-tools/utils.c @@ -265,21 +265,6 @@ _srt_get_helper (const char *helpers_path, } } - if ((flags & SRT_HELPER_FLAGS_SEARCH_PATH) != 0 - && helpers_path == NULL) - { - /* For helpers that are not part of steam-runtime-tools, such as - * *-wflinfo and *-vulkaninfo, we currently only search PATH, - * unless helpers_path has been overridden */ - if (multiarch == NULL) - prefixed = g_strdup (base); - else - prefixed = g_strdup_printf ("%s-%s", multiarch, base); - - g_ptr_array_add (argv, g_steal_pointer (&prefixed)); - return argv; - } - if (helpers_path == NULL) { helpers_path = _srt_get_helpers_path (error); @@ -291,6 +276,9 @@ _srt_get_helper (const char *helpers_path, } } + /* Prefer a helper from ${SRT_HELPERS_PATH} or + * ${libexecdir}/steam-runtime-tools-${_SRT_API_MAJOR} + * if it exists */ path = g_strdup_printf ("%s/%s%s%s", helpers_path, multiarch == NULL ? "" : multiarch, @@ -304,7 +292,8 @@ _srt_get_helper (const char *helpers_path, g_ptr_array_add (argv, g_steal_pointer (&path)); return argv; } - else + + if ((flags & SRT_HELPER_FLAGS_SEARCH_PATH) == 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s not found", path); @@ -312,6 +301,18 @@ _srt_get_helper (const char *helpers_path, g_ptr_array_unref (argv); return NULL; } + + /* For helpers that are not part of steam-runtime-tools, such as + * *-wflinfo and *-vulkaninfo, we fall back to searching $PATH */ + g_free (path); + + if (multiarch == NULL) + prefixed = g_strdup (base); + else + prefixed = g_strdup_printf ("%s-%s", multiarch, base); + + g_ptr_array_add (argv, g_steal_pointer (&prefixed)); + return argv; } /** -- GitLab