Commit d7cb72f7 changed debuginfod-find to always set a progress
callback function in order to handle interrupts during downloading.

Previously debuginfod-find set a progressfn only when the -v command
line option was given.  If the DEBUGINFOD_PROGRESS environment variable
is set, libdebuginfod automatically sets a default progressfn as long as
no other progressfn has been set using debuginfod_set_progressfn.

Commit d7cb72f7 therefore resulted in DEBUGINFOD_PROGRESS no longer
affecting debuginfod-find when invoked without -v.

This patch restores the old behaviour: when DEBUGINFOD_PROGRESS is set
and -v is not given, the default progressfn will trigger during
downloading.

Signed-off-by: Aaron Merey <[email protected]>
---
 debuginfod/debuginfod-find.c             | 16 +++++++++++++---
 tests/run-debuginfod-artifact-running.sh |  5 +++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/debuginfod/debuginfod-find.c b/debuginfod/debuginfod-find.c
index 39de65c3..75fb1101 100644
--- a/debuginfod/debuginfod-find.c
+++ b/debuginfod/debuginfod-find.c
@@ -68,6 +68,7 @@ static const struct argp_option options[] =
 static debuginfod_client *client;
 static int verbose;
 static volatile sig_atomic_t interrupted;
+static bool saw_progress_envvar;
 
 static void
 handle_sigint(int signo __attribute__((__unused__)))
@@ -75,13 +76,19 @@ handle_sigint(int signo __attribute__((__unused__)))
   interrupted = 1;
 }
 
-int progressfn(debuginfod_client *c __attribute__((__unused__)),
-              long a, long b)
+static int
+progressfn(debuginfod_client *c, long a, long b)
 {
   if (interrupted)
     return 1;
   if (verbose < 1)
-    return 0;
+    {
+      /* Fallback to the default progressfn if verbose isn't set and
+        DEBUGINFOD_PROGRESS is set.  */
+      if (saw_progress_envvar)
+       return debuginfod_default_progressfn (c, a, b);
+      return 0;
+    }
 
   static bool first = true;
   static struct timespec last;
@@ -153,6 +160,9 @@ main(int argc, char** argv)
   sa.sa_handler = handle_sigint;
   sigaction (SIGINT, &sa, NULL);
 
+  if (getenv(DEBUGINFOD_PROGRESS_ENV_VAR) != NULL)
+    saw_progress_envvar = true;
+
   debuginfod_set_progressfn (client, & progressfn);
 
   /* Exercise user data pointer, to support testing only. */
diff --git a/tests/run-debuginfod-artifact-running.sh 
b/tests/run-debuginfod-artifact-running.sh
index 2d5d834d..746f4dc3 100755
--- a/tests/run-debuginfod-artifact-running.sh
+++ b/tests/run-debuginfod-artifact-running.sh
@@ -112,6 +112,11 @@ grep -q 'Progress' vlog2
 filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source 
$BUILDID2 ${PWD}/prog2.c`
 cmp $filename ${PWD}/prog2.c
 
+# Check that debuginfod-find with DEBUGINFOD_PROGRESS set and no -v uses
+# libdebuginfod's default progress callback function
+rm -rf $DEBUGINFOD_CACHE_PATH/$BUILDID2/executable
+filename=`testrun env DEBUGINFOD_PROGRESS=1 
${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
+grep -q 'Downloading.*http' vlog2
 
 kill $PID1
 wait $PID1
-- 
2.53.0

Reply via email to