#include <fcntl.h>
#include <gelf.h>
#include <libdwelf.h>
+#include <signal.h>
#ifndef DUMMY_LIBDEBUGINFOD
#include <json-c/json.h>
#endif
/* debuginfod connection handle. */
static debuginfod_client *client;
static int verbose;
+static volatile sig_atomic_t interrupted;
+
+static void
+handle_sigint(int signo __attribute__((__unused__)))
+{
+ interrupted = 1;
+}
int progressfn(debuginfod_client *c __attribute__((__unused__)),
long a, long b)
{
+ if (interrupted)
+ return 1;
+ if (verbose < 1)
+ return 0;
+
static bool first = true;
static struct timespec last;
struct timespec now;
switch (key)
{
case 'v': verbose++;
- debuginfod_set_progressfn (client, & progressfn);
if (verbose > 1)
debuginfod_set_verbose_fd (client, STDERR_FILENO);
break;
return 1;
}
+ /* Set SIGINT handler and progressfn so that temp files can be cleaned
+ up when a download is cancelled. */
+ struct sigaction sa;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = handle_sigint;
+ sigaction (SIGINT, &sa, NULL);
+
+ debuginfod_set_progressfn (client, & progressfn);
+
/* Exercise user data pointer, to support testing only. */
debuginfod_set_user_data (client, (void *)"Progress");
if (rc < 0)
{
- fprintf(stderr, "Server query failed: %s\n", strerror(-rc));
+ if (interrupted != 0)
+ fputs ("Server query cancelled\n", stderr);
+ else
+ fprintf(stderr, "Server query failed: %s\n", strerror(-rc));
+
return 1;
}
else
grep -q Progress vlog
grep -q Downloaded.from vlog
tempfiles vlog
-filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
+filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find -v executable $BUILDID2 2>vlog2`
cmp $filename F/prog2
-grep -q 'Downloading.*http' vlog2
tempfiles vlog2
+grep -q 'Progress' vlog2
filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c`
cmp $filename ${PWD}/prog2.c