public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: "Frank Ch. Eigler" <fche@redhat.com>
To: elfutils-devel@sourceware.org
Subject: PATCH: PR27783: debuginfod: fetch default DEBUGINFOD_URLS from systemwide file
Date: Thu, 29 Apr 2021 12:13:48 -0400	[thread overview]
Message-ID: <20210429161348.GB6131@redhat.com> (raw)

Hi -

This change was suggested by fedora fesco folks, to make it easier for
for auxiliary system daemons to use debuginfod by default.


commit 4db2eba32aaed7d567f5ebea6b2eb7a6dc4b4b36
Author: Frank Ch. Eigler <fche@redhat.com>
Date:   Thu Apr 29 11:49:14 2021 -0400

    PR27783 debuginfod: fetch default DEBUGINFOD_URLS from systemwide file
    
    Introduce use of a systemwide config file /etc/debuginfod_urls for a
    fallback default for an unset $DEBUGINFOD_URLS.  $DEBUGINFOD_URLS_FILE
    overrides the default location of that file, which is probably mainly
    useful for testing.  Deprecate the similar /etc/profile.d/debuginfod*
    mechanism that affected only login shells.
    
    OTOH, setting ANY of the following to be an empty string will disable
    debuginfod-client capability:
    - env var $DEBUGINFOD_URLS
    - env var $DEBUGINFOD_URLS_FILE
    - the file named by $DEBUGINFOD_URLS_FILE
    
    Signed-off-by: Frank Ch. Eigler <fche@redhat.com>

diff --git a/ChangeLog b/ChangeLog
index e18746fb9771..4057e19a87ed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-29  Frank Ch. Eigler <fche@redhat.com>
+
+	PR27783
+	* configure.ac (enable-debuginfod-urls): Tweak AC_CONFIG_FILE.
+
 2021-03-30  Frank Ch. Eigler  <fche@redhat.com>
 
 	* configure.ac: Look for pthread_setname_np.
diff --git a/NEWS b/NEWS
index 038c6019f572..5f4b0992b629 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 Version 0.184
 
+debuginfod-client: DEBUGINFOD_URLS_FILE (default /etc/debuginfod_urls)
+                   is consulted for DEBUGINFOD_URLS if that is unset.
+
 debuginfod: Use libarchive's bsdtar as the .deb-family file unpacker.
 
 Version 0.183
diff --git a/config/ChangeLog b/config/ChangeLog
index 0e179cbc673b..ab13c4a80586 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,12 @@
+2021-04-29  Frank Ch. Eigler <fche@redhat.com>
+
+	PR27783
+	* profile.*: Drop these.
+	* debuginfod_urls.in: New file.
+	* elfutils.spec.in: Adjust accordingly.
+	* debuginfod.sysconfig: Add blurb to unset upstream links by default.
+	* Makefile.am: dist it.
+
 2021-02-17  Timm Bäder  <tbaeder@redhat.com>
 
 	* eu.am (NO_PACKED_NOT_ALIGNED_WARNING): New variable.
diff --git a/config/Makefile.am b/config/Makefile.am
index a66f54904991..1b6cdcc8fa8b 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -30,7 +30,7 @@
 ##
 EXTRA_DIST = elfutils.spec.in known-dwarf.awk 10-default-yama-scope.conf \
 	     libelf.pc.in libdw.pc.in libdebuginfod.pc.in \
-	     debuginfod.service debuginfod.sysconfig profile.sh.in profile.csh.in
+	     debuginfod.service debuginfod.sysconfig debuginfod_urls.in
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libelf.pc libdw.pc
@@ -38,11 +38,10 @@ if LIBDEBUGINFOD
 pkgconfig_DATA += libdebuginfod.pc
 
 install-data-local:
-	$(INSTALL_DATA) profile.sh -D $(DESTDIR)$(sysconfdir)/profile.d/debuginfod.sh
-	$(INSTALL_DATA) profile.csh -D $(DESTDIR)$(sysconfdir)/profile.d/debuginfod.csh
+	$(INSTALL_DATA) debuginfod_urls -D $(DESTDIR)$(sysconfdir)/debuginfod_urls
 
 uninstall-local:
-	rm -f $(DESTDIR)$(sysconfdir)/profile.d/debuginfod.sh $(DESTDIR)$(sysconfdir)/profile.d/debuginfod.csh
+	rm -f $(DESTDIR)$(sysconfdir)/debuginfod_urls
 endif
 
 if MAINTAINER_MODE
diff --git a/config/debuginfod.sysconfig b/config/debuginfod.sysconfig
index 446038742bae..bb0c84f3d4d5 100644
--- a/config/debuginfod.sysconfig
+++ b/config/debuginfod.sysconfig
@@ -8,7 +8,10 @@ DEBUGINFOD_PATHS="-t43200 -F -R /usr/lib/debug /usr/bin /usr/libexec /usr/sbin /
 # prefer reliability/durability over performance
 #DEBUGINFOD_PRAGMAS="-D 'pragma synchronous=full;'"
 
-# upstream debuginfods
+# set it to empty to avoid accidental recursive reference
+DEBUGINFOD_URLS=""
+DEBUGINFOD_URLS_FILE=""
+# or specify upstream debuginfods
 #DEBUGINFOD_URLS="http://secondhost:8002 http://thirdhost:8002"
 #DEBUGINFOD_TIMEOUT="5"
 #DEBUGINFOD_CACHE_DIR=""
diff --git a/config/debuginfod_urls.in b/config/debuginfod_urls.in
new file mode 100644
index 000000000000..5a5fa815d2e9
--- /dev/null
+++ b/config/debuginfod_urls.in
@@ -0,0 +1 @@
+@DEBUGINFOD_URLS@
diff --git a/config/elfutils.spec.in b/config/elfutils.spec.in
index 9df92b3815e7..ba06480c71c1 100644
--- a/config/elfutils.spec.in
+++ b/config/elfutils.spec.in
@@ -298,7 +298,7 @@ fi
 %{_libdir}/libdebuginfod.so.*
 %{_bindir}/debuginfod-find
 %{_mandir}/man1/debuginfod-find.1*
-%config(noreplace) %{_sysconfdir}/profile.d/*
+%config(noreplace) %{_sysconfdir}/debuginfod_urls
   
 %files debuginfod-client-devel
 %defattr(-,root,root)
diff --git a/config/profile.csh.in b/config/profile.csh.in
deleted file mode 100644
index 0a2d6d162019..000000000000
--- a/config/profile.csh.in
+++ /dev/null
@@ -1,11 +0,0 @@
-if ("@DEBUGINFOD_URLS@" != "") then
-	if ($?DEBUGINFOD_URLS) then
-		if ($%DEBUGINFOD_URLS) then
-			setenv DEBUGINFOD_URLS "$DEBUGINFOD_URLS @DEBUGINFOD_URLS@"
-		else
-			setenv DEBUGINFOD_URLS "@DEBUGINFOD_URLS@"
-		endif
-	else
-		setenv DEBUGINFOD_URLS "@DEBUGINFOD_URLS@"
-	endif
-endif
diff --git a/config/profile.sh.in b/config/profile.sh.in
deleted file mode 100644
index aa228a0dcd16..000000000000
--- a/config/profile.sh.in
+++ /dev/null
@@ -1,4 +0,0 @@
-if [ -n "@DEBUGINFOD_URLS@" ]; then
-	DEBUGINFOD_URLS="${DEBUGINFOD_URLS-}${DEBUGINFOD_URLS:+ }@DEBUGINFOD_URLS@"
-	export DEBUGINFOD_URLS
-fi
diff --git a/configure.ac b/configure.ac
index ad046bc27ac1..1ce280513e73 100644
--- a/configure.ac
+++ b/configure.ac
@@ -781,10 +781,10 @@ AS_IF([test "x$enable_debuginfod" != "xno"], [
 AS_IF([test "x$enable_debuginfod" != "xno"],AC_DEFINE([ENABLE_DEBUGINFOD],[1],[Build debuginfod]))
 AM_CONDITIONAL([DEBUGINFOD],[test "x$enable_debuginfod" = "xyes"])
 
-dnl for /etc/profile.d/elfutils.{csh,sh}
+dnl for /etc/debuginfod_urls
 default_debuginfod_urls=""
 AC_ARG_ENABLE(debuginfod-urls,
-            [AS_HELP_STRING([--enable-debuginfod-urls@<:@=URLS@:>@],[add URLS to profile.d DEBUGINFOD_URLS])],
+            [AS_HELP_STRING([--enable-debuginfod-urls@<:@=URLS@:>@],[set systemwide default DEBUGINFOD_URLS])],
             [if test "x${enableval}" = "xyes";
              then default_debuginfod_urls="https://debuginfod.elfutils.org/";
              elif test "x${enableval}" != "xno"; then
@@ -792,7 +792,7 @@ AC_ARG_ENABLE(debuginfod-urls,
              fi],
             [default_debuginfod_urls=""])
 AC_SUBST(DEBUGINFOD_URLS, $default_debuginfod_urls)                
-AC_CONFIG_FILES([config/profile.sh config/profile.csh])
+AC_CONFIG_FILES([config/debuginfod_urls])
 
 AC_OUTPUT
 
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 3909100903cb..20744497e383 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,12 @@
+2021-04-29  Frank Ch. Eigler <fche@redhat.com>
+
+	PR27783
+	* debuginfod-client.c (xstr_readfile, xstr_readline): New helpers.
+	(debuginfod_begin): In absence of $DEBUGINFOD_URLS, read
+	$DEBUGINFOD_URLS_FILE for default urls.
+	* Makefile.am (CFLAGS): Pass $SYSCONFDIR.
+	* debuginfod.h (DEBUGINFOD_URLS_FILE_ENV_VAR): New variable.
+
 2021-04-26  Frank Ch. Eigler <fche@redhat.com>
 
 	PR27571
diff --git a/debuginfod/Makefile.am b/debuginfod/Makefile.am
index 3adb27559c9c..0b61f4b1cb69 100644
--- a/debuginfod/Makefile.am
+++ b/debuginfod/Makefile.am
@@ -80,6 +80,9 @@ noinst_LIBRARIES = libdebuginfod.a
 noinst_LIBRARIES += libdebuginfod_pic.a
 endif
 
+# expand $sysconfdir with embedded $prefix if any
+SYSCONFDIR=$(shell prefix="$(prefix)"; sysconfdir="$(sysconfdir)"; echo $$sysconfdir)
+AM_CFLAGS += -DSYSCONFDIR='"$(SYSCONFDIR)"'
 libdebuginfod_a_SOURCES = debuginfod-client.c
 libdebuginfod_pic_a_SOURCES = debuginfod-client.c
 am_libdebuginfod_pic_a_OBJECTS = $(libdebuginfod_a_SOURCES:.c=.os)
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 374989e26d43..e65aac8b4c1c 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1122,6 +1122,53 @@ debuginfod_query_server (debuginfod_client *c,
 
 
 
+/* Read given file into malloc()d buffer, if possible.  Caller to free. */
+static char*
+xstr_readfile (const char *file)
+{
+  char* buf = NULL;
+  struct stat st;
+  int fd = open (file, O_RDONLY);
+  if (fd < 0) goto out;
+  int rc = fstat(fd, &st);
+  if (rc < 0) goto out1;
+  off_t sz = st.st_size;
+  buf = malloc (sz+1);
+  if (buf == NULL) goto out1;
+  off_t i = 0;
+  while (i < sz) /* loop to read the whole thing */
+    {
+      ssize_t s = read(fd, & buf[i], sz-i);
+      if (s <= 0) break;
+      i += s;
+    }
+
+  /* NUL-terminate */
+  buf[i] = '\0';
+  
+ out1:
+  close (fd);
+
+ out:
+  return buf;
+}
+
+
+/* Return the first line of given file, with no \n but a \0.
+   Caller to free(). */
+static char*
+xstr_readline (const char *file)
+{
+  char *f = xstr_readfile (file);
+  if (f == NULL)
+    return f;
+  char *ret = index (f, '\n');
+  if (ret)
+    *ret = '\0';
+  return f;
+}
+
+
 /* See debuginfod.h  */
 debuginfod_client  *
 debuginfod_begin (void)
@@ -1130,7 +1177,8 @@ debuginfod_begin (void)
   size_t size = sizeof (struct debuginfod_client);
   const char* server_urls = NULL;
   client = (debuginfod_client *) calloc (1, size);
-
+  char* default_urls = NULL;
+    
   if (client != NULL)
     {
       if (getenv(DEBUGINFOD_PROGRESS_ENV_VAR))
@@ -1144,6 +1192,21 @@ debuginfod_begin (void)
   /* Count the DEBUGINFOD_URLS and create the long-lived curl handles. */
   client->num_urls = 0;
   server_urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
+  /* Fall back to fetching default from a system file. */
+  if (server_urls == NULL)
+    {
+      const char* server_urls_file = getenv (DEBUGINFOD_URLS_FILE_ENV_VAR);
+      if (server_urls_file == NULL) server_urls_file = SYSCONFDIR "/debuginfod_urls";
+      default_urls = xstr_readline (server_urls_file);
+      if (default_urls != NULL)
+        {
+          server_urls = default_urls;
+          /* Save it to the environment so this file opening dance is
+             not repeated for this process. */
+          setenv ("DEBUGINFOD_URLS", default_urls, 1 /* overwrite */);
+        }
+    }
+  
   if (server_urls != NULL)
     for (int i = 0; server_urls[i] != '\0'; i++)
       if (server_urls[i] != url_delim_char
@@ -1184,7 +1247,8 @@ debuginfod_begin (void)
   free (client);
   client = NULL;
 
- out:  
+ out:
+  free (default_urls); /* ok even if NULL */
   return client;
 }
 
diff --git a/debuginfod/debuginfod.h.in b/debuginfod/debuginfod.h.in
index 559ea9479349..891cdf0da0cc 100644
--- a/debuginfod/debuginfod.h.in
+++ b/debuginfod/debuginfod.h.in
@@ -31,6 +31,7 @@
 
 /* Names of environment variables that control the client logic. */
 #define DEBUGINFOD_URLS_ENV_VAR "DEBUGINFOD_URLS"
+#define DEBUGINFOD_URLS_FILE_ENV_VAR "DEBUGINFOD_URLS_FILE"
 #define DEBUGINFOD_CACHE_PATH_ENV_VAR "DEBUGINFOD_CACHE_PATH"
 #define DEBUGINFOD_TIMEOUT_ENV_VAR "DEBUGINFOD_TIMEOUT"
 #define DEBUGINFOD_PROGRESS_ENV_VAR "DEBUGINFOD_PROGRESS"
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 05fcd23d5465..2703bd7d2d0f 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-29  Frank Ch. Eigler <fche@redhat.com>
+
+	PR27783
+	* debuginfod*: Document new $DEBUGINFOD_URLS_FILE variable.
+
 2021-04-23  Frank Ch. Eigler <fche@redhat.com>
 
 	PR27701
diff --git a/doc/debuginfod-find.1 b/doc/debuginfod-find.1
index 12d4ec2d32fe..1e14b992ddc6 100644
--- a/doc/debuginfod-find.1
+++ b/doc/debuginfod-find.1
@@ -132,6 +132,12 @@ proxy server could.)
 This environment variable contains a list of URL prefixes for trusted
 debuginfod instances.  Alternate URL prefixes are separated by space.
 
+.TP 21
+.B DEBUGINFOD_URLS_FILE
+If $DEBUGINFOD_URLS is unset, the file named by this environment variable
+is read, and its first line is used as $DEBUGINFOD_URLS.  The default file 
+is under the system configuration directory (usually \fB/etc/debuginfod_urls\fP).
+
 .TP 21
 .B DEBUGINFOD_TIMEOUT
 This environment variable governs the timeout for each debuginfod HTTP
diff --git a/doc/debuginfod.8 b/doc/debuginfod.8
index 1ba42cf65ffa..9408aff0193d 100644
--- a/doc/debuginfod.8
+++ b/doc/debuginfod.8
@@ -416,6 +416,12 @@ debuginfod instances.  Alternate URL prefixes are separated by space.
 Avoid referential loops that cause a server to contact itself, directly
 or indirectly - the results would be hilarious.
 
+.TP 21
+.B DEBUGINFOD_URLS_FILE
+If $DEBUGINFOD_URLS is unset, the file named by this environment variable
+is read, and its first line is used as $DEBUGINFOD_URLS.  The default file 
+is under the system configuration directory (usually \fB/etc/debuginfod_urls\fP).
+
 .TP
 .B DEBUGINFOD_TIMEOUT
 This environment variable governs the timeout for each debuginfod HTTP
diff --git a/doc/debuginfod_find_debuginfo.3 b/doc/debuginfod_find_debuginfo.3
index 5ae44a9834be..2cee2ef1c9d9 100644
--- a/doc/debuginfod_find_debuginfo.3
+++ b/doc/debuginfod_find_debuginfo.3
@@ -248,6 +248,12 @@ proxy server could.)
 This environment variable contains a list of URL prefixes for trusted
 debuginfod instances.  Alternate URL prefixes are separated by space.
 
+.TP 21
+.B DEBUGINFOD_URLS_FILE
+If $DEBUGINFOD_URLS is unset, the file named by this environment variable
+is read, and its first line is used as $DEBUGINFOD_URLS.  The default file 
+is under the system configuration directory (usually \fB/etc/debuginfod_urls\fP).
+
 .TP 21
 .B DEBUGINFOD_TIMEOUT
 This environment variable governs the timeout for each debuginfod HTTP
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 0712417fa6cd..bc2016f40203 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-29  Frank Ch. Eigler <fche@redhat.com>
+
+	PR27783
+	* run-debuginfod-find.sh: Add a $DEBUGINFOD_URLS_FILE test.
+
 2021-04-26  Frank Ch. Eigler <fche@redhat.com>
 
 	PR27571
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
index 7ad2a45d3aac..9a217121b7e2 100755
--- a/tests/run-debuginfod-find.sh
+++ b/tests/run-debuginfod-find.sh
@@ -497,9 +497,17 @@ testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
 # test parallel queries in client
 export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
 mkdir -p $DEBUGINFOD_CACHE_PATH
-export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
 
-testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
+# test URLs in file
+urlfile=${PWD}/debuginfod_urls
+tempfiles $urlfile
+echo "BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE" > $urlfile
+
+# NB: instead of this, use a nested env/stuff goo, avoid affecting valgrind itself
+# hiding under testrun() from being affected by these settings.
+#unset DEBUGINFOD_URLS
+#export DEBUGINFOD_URLS_FILE=$urlfile
+testrun env -u DEBUGINFOD_URLS env DEBUGINFOD_URLS_FILE=$urlfile ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
 
 ########################################################################
 
@@ -615,7 +623,7 @@ local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/sourc
 mkdir -p ${local_dir}
 echo "int main() { return 0; }" > ${local_dir}/main.c
 
-# first test that is doesn't work, when no DEBUGINFOD_URLS is set
+# first test that is doesn't work, when DEBUGINFOD_URLS is empty
 DEBUGINFOD_URLS=""
 testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
 


             reply	other threads:[~2021-04-29 16:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 16:13 Frank Ch. Eigler [this message]
2021-05-03 12:59 ` Mark Wielaard
2021-05-03 13:05   ` Frank Ch. Eigler
2021-05-05 14:41     ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210429161348.GB6131@redhat.com \
    --to=fche@redhat.com \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).