public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdwfl: Do not dlopen libdebuginfod if DEBUGINFOD_URLS is unset or empty
@ 2020-11-05 14:44 Vitaly Chikunov
  2020-11-09 13:49 ` Mark Wielaard
  0 siblings, 1 reply; 5+ messages in thread
From: Vitaly Chikunov @ 2020-11-05 14:44 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Vitaly Chikunov, Dmitry V . Levin

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-09 16:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 14:44 [PATCH] libdwfl: Do not dlopen libdebuginfod if DEBUGINFOD_URLS is unset or empty Vitaly Chikunov
2020-11-09 13:49 ` Mark Wielaard
2020-11-09 14:57   ` Frank Ch. Eigler
2020-12-09 15:35     ` Dmitry V. Levin
2020-12-09 16:42       ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).