From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94728 invoked by alias); 4 Dec 2019 21:10:59 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 94715 invoked by uid 89); 4 Dec 2019 21:10:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=Activate, frank, Frank, systemtap X-Spam-Status: No, score=-16.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Dec 2019 21:10:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575493855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iv57w4vmviqPSAuMfnZTfHmzMgnM7fUwosvH84Kzyr0=; b=BCngefSi723liBi2GutsYrztoJ9fHFX4m8eruEcCVzvCj8Fk00ZHKmpSU0VODxdyS8D46I Kl2IWXy6CMqzxm7GTheWCidBlezFami64fnsdGAZW+mcHWM+svr33j6eLzcDkdQ1ny+xeA 2JxU+SZNzbody1wDKLifUBpJVB00908= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-JPBUU1ZyOtauumzP6tEBGw-1; Wed, 04 Dec 2019 16:10:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE0B9100E8C5 for ; Wed, 4 Dec 2019 21:10:51 +0000 (UTC) Received: from redhat.com (ovpn-116-64.phx2.redhat.com [10.3.116.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB2905C1B5 for ; Wed, 4 Dec 2019 21:10:51 +0000 (UTC) Received: from fche by redhat.com with local (Exim 4.92) (envelope-from ) id 1icbv8-00037q-6S for elfutils-devel@sourceware.org; Wed, 04 Dec 2019 16:10:50 -0500 Date: Wed, 04 Dec 2019 21:10:00 -0000 From: "Frank Ch. Eigler" To: elfutils-devel@sourceware.org Subject: rfc/patch: debuginfod client $DEBUGINFOD_PROGRESS env var Message-ID: <20191204211050.GA11981@redhat.com> MIME-Version: 1.0 User-Agent: Mutt/1.12.0 (2019-05-25) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: JPBUU1ZyOtauumzP6tEBGw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-IsSubscribed: yes X-SW-Source: 2019-q4/txt/msg00231.txt.bz2 debuginfod: usability tweaks, incl. $DEBUGINFOD_PROGRESS client support =20=20=20=20 This facility allows a default progress-printing function to be installed if the given environment variable is set. Some larger usage experience (systemtap/kernels) indicates the default timeout is too short, so bumped it to 30s. =20=20=20=20 Signed-off-by: Frank Ch. Eigler diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 8aa2944..a9483d0 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,13 @@ +2019-12-04 Frank Ch. Eigler + + * debuginfod-client.c (default_progressfn): New function. + (debuginfod_begin): Use it if $DEBUGINFOD_PROGRESS set. + (server_timeout): Bump to 30 seconds. + (debuginfod_query_server): Call progressfn -after- rather than + before curl ops, to make it likely that a successful transfer + results in final a=3Db call. Tweak cleanup sequence. + * debuginfod.h: Document $DEBUGINFOD_PROGRESS name. + 2019-11-26 Mark Wielaard =20 * Makefile.am (BUILD_STATIC): Add needed libraries for libdw and diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 6e62b86..3ee5e48 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -40,6 +40,7 @@ =20 #include "config.h" #include "debuginfod.h" +#include "lib/system.h" #include #include #include @@ -107,7 +108,7 @@ static const char url_delim_char =3D ' '; /* Timeout for debuginfods, in seconds. This env var must be set for debuginfod-client to run. */ static const char *server_timeout_envvar =3D DEBUGINFOD_TIMEOUT_ENV_VAR; -static int server_timeout =3D 5; +static int server_timeout =3D 30; =20 /* Data associated with a particular CURL easy handle. Passed to the write callback. */ @@ -511,6 +512,28 @@ debuginfod_query_server (debuginfod_client *c, { CURLMcode curl_res; =20 + /* Wait 1 second, the minimum DEBUGINFOD_TIMEOUT. */ + curl_multi_wait(curlm, NULL, 0, 1000, NULL); + + /* If the target file has been found, abort the other queries. */ + if (target_handle !=3D NULL) + for (int i =3D 0; i < num_urls; i++) + if (data[i].handle !=3D target_handle) + curl_multi_remove_handle(curlm, data[i].handle); + + curl_res =3D curl_multi_perform(curlm, &still_running); + + if (curl_res !=3D CURLM_OK) + { + switch (curl_res) + { + case CURLM_CALL_MULTI_PERFORM: continue; + case CURLM_OUT_OF_MEMORY: rc =3D -ENOMEM; break; + default: rc =3D -ENETUNREACH; break; + } + goto out1; + } + if (c->progressfn) /* inform/check progress callback */ { loops ++; @@ -554,27 +577,6 @@ debuginfod_query_server (debuginfod_client *c, if ((*c->progressfn) (c, pa, pb)) break; } - - /* Wait 1 second, the minimum DEBUGINFOD_TIMEOUT. */ - curl_multi_wait(curlm, NULL, 0, 1000, NULL); - - /* If the target file has been found, abort the other queries. */ - if (target_handle !=3D NULL) - for (int i =3D 0; i < num_urls; i++) - if (data[i].handle !=3D target_handle) - curl_multi_remove_handle(curlm, data[i].handle); - - curl_res =3D curl_multi_perform(curlm, &still_running); - if (curl_res !=3D CURLM_OK) - { - switch (curl_res) - { - case CURLM_CALL_MULTI_PERFORM: continue; - case CURLM_OUT_OF_MEMORY: rc =3D -ENOMEM; break; - default: rc =3D -ENETUNREACH; break; - } - goto out1; - } } while (still_running); =20 /* Check whether a query was successful. If so, assign its handle @@ -673,9 +675,9 @@ debuginfod_query_server (debuginfod_client *c, =20 curl_multi_cleanup(curlm); unlink (target_cache_tmppath); + close (fd); /* before the rmdir, otherwise it'll fail */ (void) rmdir (target_cache_dir); /* nop if not empty */ free(data); - close (fd); =20 out0: free (server_urls); @@ -684,6 +686,35 @@ debuginfod_query_server (debuginfod_client *c, return rc; } =20 + +/* Activate a basic form of progress tracing */ +static int +default_progressfn (debuginfod_client *c, long a, long b) +{ + (void) c; + + int fd =3D open(getenv(DEBUGINFOD_PROGRESS_ENV_VAR), + O_APPEND|O_WRONLY|O_CREAT, 0666); + if (fd < 0) + goto out; + + char *msg =3D NULL; + int rc =3D asprintf(&msg, + "Downloading from debuginfod %ld/%ld%s", a, b, + ((a =3D=3D b) ? "\n" : "\r")); /* XXX: include URL - stateful */ + if (rc < 0) + goto out1; + + (void) write_retry(fd, msg, rc); + free (msg); + + out1: + close (fd); + out: + return 0; +} + + /* See debuginfod.h */ debuginfod_client * debuginfod_begin (void) @@ -692,7 +723,12 @@ debuginfod_begin (void) size_t size =3D sizeof (struct debuginfod_client); client =3D (debuginfod_client *) malloc (size); if (client !=3D NULL) - client->progressfn =3D NULL; + { + if (getenv(DEBUGINFOD_PROGRESS_ENV_VAR)) + client->progressfn =3D default_progressfn; + else + client->progressfn =3D NULL; + } return client; } =20 diff --git a/debuginfod/debuginfod.h b/debuginfod/debuginfod.h index 6b1b1cc..33fae86 100644 --- a/debuginfod/debuginfod.h +++ b/debuginfod/debuginfod.h @@ -33,6 +33,7 @@ #define DEBUGINFOD_URLS_ENV_VAR "DEBUGINFOD_URLS" #define DEBUGINFOD_CACHE_PATH_ENV_VAR "DEBUGINFOD_CACHE_PATH" #define DEBUGINFOD_TIMEOUT_ENV_VAR "DEBUGINFOD_TIMEOUT" +#define DEBUGINFOD_PROGRESS_ENV_VAR "DEBUGINFOD_PROGRESS" =20 /* Handle for debuginfod-client connection. */ typedef struct debuginfod_client debuginfod_client; diff --git a/doc/ChangeLog b/doc/ChangeLog index 00a61ac..9542161 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2019-12-04 Frank Ch. Eigler + + * debuginfod-find.1: Bump default timeout to 30. + * debuginfod_find_debuginfo.3: Ditto. + Document $DEBUGINFOD_PROGRESS. + 2019-09-02 Mark Wielaard =20 * readelf.1 (symbols): Add optional section name. diff --git a/doc/debuginfod-find.1 b/doc/debuginfod-find.1 index a759ecb..7f14e8c 100644 --- a/doc/debuginfod-find.1 +++ b/doc/debuginfod-find.1 @@ -121,7 +121,7 @@ debuginfod instances. Alternate URL prefixes are separ= ated by space. .B DEBUGINFOD_TIMEOUT This environment variable governs the timeout for each debuginfod HTTP connection. A server that fails to respond within this many seconds -is skipped. The default is 5. +is skipped. The default is 30. =20 .TP 21 .B DEBUGINFOD_CACHE_PATH diff --git a/doc/debuginfod_find_debuginfo.3 b/doc/debuginfod_find_debuginf= o.3 index be8eed0..63766b3 100644 --- a/doc/debuginfod_find_debuginfo.3 +++ b/doc/debuginfod_find_debuginfo.3 @@ -165,7 +165,15 @@ debuginfod instances. Alternate URL prefixes are sepa= rated by space. .B DEBUGINFOD_TIMEOUT This environment variable governs the timeout for each debuginfod HTTP connection. A server that fails to respond within this many seconds -is skipped. The default is 5. +is skipped. The default is 30. + +.TP 21 +.B DEBUGINFOD_PROGRESS +This environment variable governs the default progress function. If +set, and if a progressfn is not explicitly set, then the library will +configure a default progressfn. This function will append a simple +progress message periodically to the given file. Consider using +"/dev/stderr" on platforms that support it. The default is nothing. =20 .TP 21 .B DEBUGINFOD_CACHE_PATH diff --git a/tests/ChangeLog b/tests/ChangeLog index 6e3923f..d63d0eb 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2019-12-04 Frank Ch. Eigler + + * run-debuinfod-find.sh: Test $DEBUGINFOD_PROGRESS. + 2019-11-26 Mark Wielaard =20 * Makefile.am (BUILD_STATIC): Add libraries needed for libdw. diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh index 0ade03b..be6d565 100755 --- a/tests/run-debuginfod-find.sh +++ b/tests/run-debuginfod-find.sh @@ -153,8 +153,11 @@ cmp $filename F/prog2 cat vlog grep -q Progress vlog tempfiles vlog -filename=3D`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executa= ble $BUILDID2` +filename=3D`testrun env DEBUGINFOD_PROGRESS=3Dvlog2 ${abs_top_builddir}/de= buginfod/debuginfod-find executable $BUILDID2` cmp $filename F/prog2 +cat vlog2 +grep -q Downloading vlog2 +tempfiles vlog2 filename=3D`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source = $BUILDID2 ${PWD}/prog2.c` cmp $filename ${PWD}/prog2.c =20