Commit Graph

101 Commits

Author SHA1 Message Date
zhanghaibo e660ab2124 upgrade to v0.188
Signed-off-by: zhanghaibo <zhanghaibo0@huawei.com>
Change-Id: I83c8756f5ce0a464b037bc963cfdce43df82921b
2023-04-25 18:45:37 +08:00
Frank Ch. Eigler 0b454c7e19 PR27859: correct 404-latch bug in debuginfod client reuse
PR27701 implemented curl handle reuse in debuginfod_client objects,
but with an unexpected bug.  Server responses returning an error
"latched" because the curl_easy handles for error cases weren't all
systematically removed from the curl multi handle.  This prevented
their proper re-addition the next time.

This version of the code simplfies matters by making only the curl
curl_multi handle long-lived.  This turns out to be enough, because it
can maintain a pool of long-lived http/https connections and related
data, and lend them out to short-lived curl_easy handles.  This mode
handles errors or hung downloads even better, because the easy handles
don't undergo complex state transitions between reuse.

A new test case confirms this correction via the federating debuginfod
instance (cleaning caches between subtests to make sure http* is being
used and reused).

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-05-16 17:51:16 -04:00
Martin Liska adc201f819 Come up with startswith function.
New function in system.h that returns true if a string has a given
prefix, false otherwise.  Use it in place of strncmp.

Signed-off-by: Martin Liška <mliska@suse.cz>
2021-05-12 11:56:57 +02:00
Alice Zhang via Elfutils-devel 5f72c51a7e debuginfod: debuginfod client should cache negative results.
Add debuginfod_config_cache for reading and writing to cache
configuration files, make use of the function within
debuginfod_clean_cache and debuginfod_query_server.

In debuginfod_query_server, create 000-permission file on failed
queries. Before querying each BUILDID, if corresponding 000 file
detected, compare its stat mtime with parameter from
.cache/cache_miss_s. If mtime is fresher, then return ENOENT and
exit; otherwise unlink the 000 file and proceed to a new query.

tests: add test in run-debuginfod-find.sh

test if the 000 file is created on failed query; if querying the
same failed BUILDID, whether the query should proceed without
going through server; set the cache_miss_s to 0 and query the same
buildid, and this time should go through the server.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
2021-05-06 23:04:26 +02:00
Frank Ch. Eigler 92980edc82 PR27571: debuginfod client cache - file permissions
Files in the download cache should be read-only.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-05-01 14:15:32 -04:00
Frank Ch. Eigler 95edde45e5 PR26125: debuginfod client cache - rmdir harder
With PR25365, we accidentally lost the ability to rmdir client-cache
directories corresponding to buildids.  Bring this back, with some
attention to a possible race between a client doing cleanup and
another client doing lookups at the same time.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-05-01 14:03:01 -04:00
Frank Ch. Eigler 6c8b68b024 PR27701: debuginfod client: encourage reused debuginfod_client objects
Client objects now carry long-lived curl handles for outgoing
connections.  This makes it more efficient for multiple sequential
queries, because the TCP connections and/or TLS state info are kept
around awhile, avoiding O(100ms) setup latencies.  debuginfod is
adjusted to take advantage of this for federation.  Other clients
should gradually do this too, perhaps including elfutils itself (in
the libdwfl->debuginfod_client hooks).

A large gdb session with 117 debuginfo downloads was observed to run
twice as fast (45s vs. 1m30s wall-clock time), just in nuking this
extra setup latency.  This was tested via a debuginfod intermediary:
it should be even faster once gdb reuses its own debuginfod_client.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-04-30 21:26:27 -04:00
Frank Ch. Eigler a81366e011 debuginfod: only update database stats once per groom
On very large servers, each database-stat counting pass can take tens
of minutes (!), and doing it twice per groom pass does not seriously
improve data quality.  Just do it once, after stale data removal &
basic sqlite vacuum.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-04-15 07:21:25 -04:00
Frank Ch. Eigler 2a849629a0 debuginfod: Recognize .debug_*-less symtab-laden files as debuginfo
Borrow logic from elfclassify for is_debug_only() for our own
debuginfo identification.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-04-15 07:21:24 -04:00
Frank Ch. Eigler 69fc2b3a5c debuginfod: Set child thread names via pthread_setname_np()
In order to assist problem diagnosis / monitoring, use this
gnu-flavoured pthread function to set purpose names to the various
child threads debuginfod starts.  libmicrohttpd already sets this for
its threads.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-03-30 13:22:43 -04:00
Timm Bäder a51f278371 debuginfod-client: Don't compare a double to a long
Clang warns about this:

../../debuginfod/debuginfod-client.c:899:28: error: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion]
                pa = (dl > LONG_MAX ? LONG_MAX : (long)dl);
                         ~ ^~~~~~~~
/usr/lib64/clang/10.0.1/include/limits.h:47:19: note: expanded from macro 'LONG_MAX'
                  ^~~~~~~~~~~~
<built-in>:38:22: note: expanded from here
                     ^~~~~~~~~~~~~~~~~~~~

Modified for jakub's observation about LONG_MAX overflow.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-07 13:08:15 -05:00
Timm Bäder f82f46fc68 debuginfod-client: Fix typo in curl feature detection
CURLINFO_CURLINFO_CONTENT_LENGTH_DOWNLOAD_T is one CURLINFO_ too much.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-05 13:36:15 -05:00
Frank Ch. Eigler 35e49cac53 debuginfod: filter webapi for bad keywords early
Prevent some unnecessary processing of user data and
keep invalid request types out of metrics.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-02-25 14:07:51 -05:00
Frank Ch. Eigler f146d5ec8e PR27413: use bsdtar to unpack deb-related formats
dpkg-deb has been reported to be fragile when running under
debuginfod, whereas bsdtar (libarchive) is happy with all these
flavors of files.  Switch to a bsdtar based pipeline, now
equipped with an escaped glob pattern that adapts to a variety
of interior data.tar* compression formats.

No testsuite impact.  .ipk format tested with some random openwrt and
kino-extension binaries found on the net.  Some of these are built
with out buildid, and hardly any with debuginfo, but whatever, bsdtar
and elfutils extract whatever info is there.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Signed-off-by: Dorinda Bassey <dorindabassey@gmail.com>
2021-02-17 06:27:51 -05:00
Frank Ch. Eigler aa121ea7f1 PR27092: debuginfod low-memory handling
A couple of closely related pieces of work allow more early warning
about low storage/memory conditions:

- New prometheus metrics to track filesystem freespace, and more
  details about some errors.
- Frequent checking of $TMPDIR freespace, to trigger fdcache
  emergency flushes.
- Switch to floating point prometheus metrics, to communicate
  fractions - and short time intervals - accurately.
- Fix startup-time pthread-creation error handling.

Testing is smoke-test-level only as it is hard to create
free-space-limited $TMPDIRs. Locally tested against tiny through
medium tmpfs filesystems, with or without sqlite db also there.  Shows
a pleasant stream of diagnostics and metrics during shortage but
generally does not fail outright.  However, catching an actual
libstdc++- or kernel-level OOM is beyond our ken.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-02-05 12:38:50 -05:00
Frank Ch. Eigler 6362941714 PR27323 debuginfod: improve query concurrency with grooming
Start using a second sqlite3 database connection for webapi query
servicing.  This allows much better concurrency when long-running
grooming operations are in progress.

No testsuite impact.  Grooming times are too short to try to hit with
concurrent requests.  OTOH the existing tests did show some
interesting regressions that needed fixing, like needing not to
dual-wield db and dbq when doing rpm-dwz-related lookups from during
scanning, and the way in which corrupted databases are reported.
These needed some automated invocations of gdb on the running
debuginfod binaries that just failed their testing, for in-situ
debugging.

Hand-tested for function on a huge 20GB index file.  Allowed webapi
queries to be run throughout random points of the grooming process,
including especially the long count(*) report loops before & after.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-02-05 12:38:50 -05:00
Dmitry V. Levin 05c232f7fd Split the top level .gitignore file
Move subdirectory parts of the top level .gitignore into appropriate
subdirectories.  This would be consistent with ChangeLog files,
currently one has to update the top level ChangeLog file when
the top level .gitignore file is changed in a way that affects
a specific subdirectory only.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-20 08:00:00 +00:00
Dmitry V. Levin 0f0e6c5372 debuginfod: fix spelling typos in error diagnostics and comments
Initalize -> Initialize
Unsucessful -> Unsuccessful
expession -> expression
incompatiblity -> incompatibility

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-12 18:06:28 +01:00
Dmitry V. Levin 7e2e30586d debuginfod: create libdebuginfod.so.1 before libdebuginfod.so
This would allow to switch from "libdebuginfod-" VERSION ".so"
to DEBUGINFOD_SONAME in __libdwfl_debuginfod_init, and to remove the
fall back to dlopen of "libdebuginfod.so" which would no longer be needed.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-09 23:05:32 +01:00
Dmitry V. Levin fc5e808d54 debuginfod: export DEBUGINFOD_SONAME macro in debuginfod.h
Add DEBUGINFOD_SONAME macro to API for use by those of libdebuginfod
clients that would like to dlopen the library in the same way as
__libdwfl_debuginfod_init does.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-09 20:38:07 +01:00
Dmitry V. Levin 2f02e81510 Drop $(EXEEXT) suffix from shared libraries
According to GNU Automake documentation [1], $(EXEEXT) is the suffix
that should be used for executables, it is not applicable for shared libraries.

[1] https://www.gnu.org/software/automake/manual/html_node/EXEEXT.html

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-06 12:47:24 +01:00
Frank Ch. Eigler 841bd252a0 debuginfod: correct prometheus metric typo
The "-" character is not allowed in a metric label_name, whoops,
so use "_" for one of the new sqlite metrics.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-11-25 21:20:27 -05:00
Frank Ch. Eigler ea5788a5ba debuginfod: use clock_gettime(CLOCK_MONOTONIC) for intervals
On Mark's request, use a monotonic clock for metrics/reports related
to time interval measurement.  gettimeofday can jump a bit, which
could distort metrics.  Tests unaffected.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-11-25 19:42:10 -05:00
Frank Ch. Eigler ba6499984c debuginfod: sqlite3 metrics
Add metrics for tracking sqlite3 error counts and query performance.

The former looks like a new sibling of the "error_count" family, and
is tested by dd-corrupting a live database file then triggering some
debuginfod activity.

    error_count{sqlite3="file is not a database"} 1

The latter looks like _count/_sum pairs for each type of sqlite
prepared-statement used in the code, and is grep smoke-tested.  They
should assist a sysadmin in tuning db storage.  This example shows a
6.4 ms/operation cost:

    sqlite3_milliseconds_count{step-done="rpm-file-intern"} 318
    sqlite3_milliseconds_sum{reset="rpm-file-intern"} 2033

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-11-25 19:42:10 -05:00
Mark Wielaard 6b82ac67d8 debuginfod-client: Initialize struct handle_data errbuf to the empty string.
Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-23 17:52:02 +01:00
Mark Wielaard 609053a588 debuginfod-client: Add debuginfod_set_verbose_fd and DEBUGINFOD_VERBOSE
Introduce a new function debuginfod_set_verbose_fd which will produce
verbose output on a given file descriptor (STDERR_FILENO if the
environment variable DEBUGINFOD_VERBOSE is set) showing how the search
for a particular client query is going.

Example output:

debuginfod_find_debuginfo 1234567890
server urls "https://debuginfod.elfutils.org/ http://dbgd.usersys.com:3632/"
checking build-id
checking cache dir /home/mark/.cache/debuginfod_client
using timeout 90
init server 0 https://debuginfod.elfutils.org/
url 0 https://debuginfod.elfutils.org/buildid/1234567890/debuginfo
init server 1 http://dbgd.usersys.com:3632/
url 1 http://dbgd.usersys.com:3632/buildid/1234567890/debuginfo
query 2 urls in parallel
server response HTTP response code said error
url 0 The requested URL returned error: 404 Not Found
server response HTTP response code said error
url 1 The requested URL returned error: 404 Not Found
not found No such file or directory (err=-2)

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-23 16:58:36 +01:00
Mark Wielaard 371a4f8148 debuginfod: Handle "/" and report unrecognized operations
This doesn't change any functionality, but simply shows something a little
user friendlier when accessing the server "by hand" (in a browser).

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-22 00:09:33 +01:00
Frank Ch. Eigler 73548bd3e8 debuginfod: add thread-busy metrics to webapi service
Improve monitoring of debuginfod instances by tracking thread_busy
status for the threads responding to http requests.  While these are
usually short-lived, longer archive-uncompress operations can take
long enough time to show up on top/uptime.  This should also assist
noticing abusive clients and guide scaling of the service.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-11-21 17:10:49 -05:00
Mark Wielaard d89111fb0e debuginfod-find: Be a bit less verbose with -v
debuginfod-find -v enables a progressfn that prints the Progress every
time the callback is called. For slow transfers or big downloads this
can be really verbose (hundreds a times a second). Slow it down a bit,
so it only prints the progress at most 5 times a second.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-17 14:36:37 +01:00
Érico Rolim ced66615bd Switch from numerical to defined constants for permissions.
Use defined constants for permission values. Also add fallback
definitions for them in system.h, to allow for compatibility with
systems that don't provide these macros.

Include system.h in all tests/ files that required it.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-03 15:54:14 +01:00
Érico Rolim 95ec1659cd debuginfod.cxx: include libintl.h.
Uncomment the <libintl.h> include, since textdomain() and
bindtextdomain() functions provided by it are being used.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
2020-11-03 01:15:54 +01:00
Érico Rolim da855fc9cd Support building when fts and obstack aren't part of libc.
- Make configure.ac test for fts and obstack availability;
- Add fts and obstack ldflags to all files that need them;
- Add missing argp ldflags to programs in debuginfod/.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
2020-11-03 01:11:06 +01:00
Frank Ch. Eigler 201077456a debuginfod: Accelerate traversal, shutdowns, improve metrics
Added new metrics for scanning that allow estimation of its reading
bandwidth.  Accelerated responsivity to SIGINT shutdown during
archive-scanning phase, which previously insisted on completely
processing the current archive.  Noted in systemd service file that in
the worst case, it might still take a long time.  Accelerated
traversals by moving regex -I/-X handling to apply to file names only
(as always documented), so directory traversal metrics are accurate
regardless of their name.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-10-31 10:00:39 -04:00
Frank Ch. Eigler 736cd2e2b5 PR26775: restore thread_work_groom metric to cycle count
... and add new metrics about progress of traversal and groom
processes.  Correct one control flow abnormality that could
prematurely end a scanner thread and might have accounted for
the inconsistent test results from the previous patch.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-10-30 18:26:04 -04:00
Frank Ch. Eigler 2237828857 PR26775: make grooming progress visible & interruptible
On very large servers, it's desirable to be able to interrupt a rescan
or groom cycle.  SIGUSR[12] now do that.  (Unfortunately, this is not
practically testable in the testsuite, since these cycles are so fast
on that small dataset.)  We also expose more internal progress count
about the grooming pass, so the administrator can assess possible need
to interrupt.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-10-30 10:09:29 -04:00
Frank Ch. Eigler f5015aebdb PR26810: debuginfod should tolerate some absence/renaming sans grooming
debuginfod now knows to handle a case where a buildid search is
satisfiable from more than one source (e.g., archive location), but
some of them are invalid.  New exception catching beneath the sqlite
scanning loop ensures all possible matches are scanned in case of
errors.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-10-30 10:09:29 -04:00
Mark Wielaard 747a84b60e debuginfod: Translate CURLE_PEER_FAILED_VERIFICATION to ECONNREFUSED.
When a file couldn't be retrieved because of an bad HTTPS certificate
find-debuginfod currently says:
Server query failed: No such file or directory

With this patch it will say:
Server query failed: Connection refused

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-10-26 22:55:29 +01:00
Frank Ch. Eigler 01348c28a2 PR26756: add more prometheus metrics to debuginfod
Add an error_count{} family of metrics for each libc/libarchive/http
exception instance created during operation.  Add a family of fdcache*
metrics for tracking fdcache operations and status.  Test via a
injecting a permission-000 empty nothing.rpm in the testsuite.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-10-21 13:37:34 -04:00
Frank Ch. Eigler e402d84c59 debuginfod: suppress fdcache prefetching during dwz lookup
During a recent from-scratch reindexing of the rpm/deb corpus at
debuginfod.elfutils.org, we found the fdcache chewed up an abnormal
amount of $TMPDIR space.  This was due to internal .dwz lookups, which
triggered fdcache prefetching as for a webapi query, but there was not
a timely fdcache eviction pass to clean it up again.  Rather than add
that pass, it's better to suppress the prefetching completely, as an
internal .dwz search will only ever need that file, not any others
from the same archive.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-10-21 10:06:51 -04:00
Frank Ch. Eigler 04bcab70c7 debuginfod: store only canonicalized sref pathnames in database
Since PR25548, we let debuginfod answer /buildid/HEX/source/PATH
queries with both canonicalized and raw PATHs.  It canonicalizes
incoming paths, but still stored the raw paths in the database too.
This near-dupe storage is not needed, since the queries would always
find the canonicalized version too, so stop doing that.  This saves
database space/time.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-09-18 13:13:02 -04:00
Mark Wielaard e39b33d6be debuginfod: Fix BUILD_STATIC build.
The BUILD_STATIC build, as used by the coverage setup, was broken for
debuginfod because the DUMMY_LIBDEBUGINFOD case was mixed up. It should
include libcurl_LIBS when NOT doing a dummy build.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-09-17 23:05:26 +02:00
Mark Wielaard 4438f03c85 debuginfod-find.c: Fix license block comment. File is GPLv3+ only.
The license itself was correct, just the comment to get a copy of
the LGPL was wrong.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-09-16 16:55:16 +02:00
Mark Wielaard 0ba7476d36 debuginfod-find: Support compressed (kernel) ELF images.
By using dwelf_elf_begin instead of elf_begin we automatically get
support for determining the build-id of compressed (kernel) images.

https://sourceware.org/bugzilla/show_bug.cgi?id=26599

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-09-15 15:43:10 +02:00
Alice Zhang 8de6f9af46 debuginfod: DEBUGINFOD_URLS should accept scheme-free urls
Check scheme instead of effective url so that user may abbreviate
DEBUGINFOD_URL. Add one test for scheme free http url.

Notice that libcurl does not provide an almighty scheme free url
support, /path/to/something without FILE:// can not be recognized
in most circumstances, therefore for the neatness of our code
structure, DEBUGINFOD_ URL of scheme "FILE" must be input as URI.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
2020-07-05 17:00:33 +02:00
Mark Wielaard f7f0cdc59a debuginfod: Add --disable-libdebuginfod and --enable-libdebuginfod=dummy.
Make it possible to build just the debuginfod client or to create a
dummy libdebuginfod that doesn't link against libcurl. The dummy library
can be used for bootstrapping. For testing purposes you can also build
debuginfod against the dummy libdebuginfod but then the debuginfod
server will not be able to do delegation.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-07-04 01:30:07 +02:00
Frank Ch. Eigler acb453851c PR26195: adapt debuginfod to API change in libmicrohttpd-0.9.71
To make our code build with -Werror as well as against older libmicrohttpd,
we must conditionalize the data type (int vs. enum) returned by callbacks
and some mhd functions.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-07-02 14:54:12 +00:00
Mark Wielaard d45cc8a04a debuginfod: Make sure handle_data can be allocated and is always freed.
When allocating handle_data we should check for out of memory failures.
Also when the allocation has succeeded make sure we always clean up by
going to out1 on any future errors. So move the curl_multi_init call
earlier, because that goes to out0 on failure.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00
Mark Wielaard 90808ed559 debuginfod: Fix build_id hexadecimal length check.
When is debuginfod_query_server is given an hexadecimal string as
build-id build_id_len will be zero. We were checking the size of
the build_id_bytes destination string instead of the string length
of build_id input string. Make sure the input string is not too
big or strcpy might overwrite then end of the build_id_bytes array.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00
Mark Wielaard 6b677bf8e3 debuginfod: Make sure suffix can place zero terminator when copying filename
We need to make sure that we can always place a zero terminator at
the end of suffix when we are copying the filename. So add one more
char to the suffix array. And make sure that we can always add an
extra escape character when we need to escape the current character.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00
Mark Wielaard a7c5e3004b debuginfod: Handle not being able to fopen interval_path.
Although we check for and/or create the interval_path right before,
there is still a possibility that the fopen call fails. Handle that
as if the file is unreadable.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00