[PATCH] libdwfl: Do not dlopen libdebuginfod if DEBUGINFOD_URLS is unset or empty
Vitaly Chikunov
vt@altlinux.org
Thu Nov 5 14:44:52 GMT 2020
Avoid calling expensive dlopen at the cost of an extra getenv check when
we already know it would not be needed.
This mirrors the getenv check from debuginfod_query_server.
Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
---
libdwfl/debuginfod-client.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/libdwfl/debuginfod-client.c b/libdwfl/debuginfod-client.c
index ee604ad9..6fd83900 100644
--- a/libdwfl/debuginfod-client.c
+++ b/libdwfl/debuginfod-client.c
@@ -38,6 +38,8 @@ static __typeof__ (debuginfod_find_executable) *fp_debuginfod_find_executable;
static __typeof__ (debuginfod_find_debuginfo) *fp_debuginfod_find_debuginfo;
static __typeof__ (debuginfod_end) *fp_debuginfod_end;
+static const char *server_urls_envvar = DEBUGINFOD_URLS_ENV_VAR;
+
/* NB: this is slightly thread-unsafe */
static debuginfod_client *
@@ -101,6 +103,12 @@ __libdwfl_debuginfod_end (debuginfod_client *c)
void __attribute__ ((constructor))
__libdwfl_debuginfod_init (void)
{
+ /* Is there any server we can query? If not, don't do any work,
+ * just return. Don't try to dlopen. */
+ char *urls_envvar = getenv(server_urls_envvar);
+ if (urls_envvar == NULL || urls_envvar[0] == '\0')
+ return;
+
void *debuginfod_so = dlopen("libdebuginfod-" VERSION ".so", RTLD_LAZY);
if (debuginfod_so == NULL)
--
2.25.4
More information about the Elfutils-devel
mailing list