summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Sanci <nsanci@redhat.com>2021-09-16 09:49:04 -0400
committerFrank Ch. Eigler <fche@redhat.com>2021-09-21 14:01:58 -0400
commit18f0c0e8a8d2feff0721852b18db826caf732d2d (patch)
tree6cfb09033513705bf3c90e297f2140f5c62626ed
parent28db5f16c44fa7bbd24b221b65aa4d133753355c (diff)
downloadelfutils-18f0c0e8a8d2feff0721852b18db826caf732d2d.tar.gz
28284 first only
-rw-r--r--debuginfod/debuginfod.cxx66
1 files changed, 49 insertions, 17 deletions
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 2b9a1c41..c58c4fda 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -1047,6 +1047,7 @@ add_mhd_last_modified (struct MHD_Response *resp, time_t mtime)
static struct MHD_Response*
handle_buildid_f_match (bool internal_req_t,
+ bool describe,
int64_t b_mtime,
const string& b_source0,
int *result_fd)
@@ -1075,21 +1076,32 @@ handle_buildid_f_match (bool internal_req_t,
close(fd);
return 0;
}
+ struct MHD_Response* r;
+ /* if describing make a buffer with a body of length 1 */
+ if (describe)
+ {
+ inc_metric ("http_responses_total","result","file-describe");
+ r = MHD_create_response_from_buffer (0, (void*)"", MHD_RESPMEM_PERSISTENT);
+ }
+ /* create a response with the file's body */
+ else
+ {
+ inc_metric ("http_responses_total","result","file");
+ r = MHD_create_response_from_fd ((uint64_t) s.st_size, fd);
+ }
- inc_metric ("http_responses_total","result","file");
- struct MHD_Response* r = MHD_create_response_from_fd ((uint64_t) s.st_size, fd);
if (r == 0)
{
if (verbose)
- obatched(clog) << "cannot create fd-response for " << b_source0 << endl;
+ obatched(clog) << "cannot create response for " << b_source0 << endl;
close(fd);
}
else
{
MHD_add_response_header (r, "Content-Type", "application/octet-stream");
std::string file = b_source0.substr(b_source0.find_last_of("/")+1, b_source0.length());
+ MHD_add_response_header (r, "X-DEBUGINFOD-FILE", file.c_str());
MHD_add_response_header (r, "X-DEBUGINFOD-SIZE", to_string(s.st_size).c_str() );
- MHD_add_response_header (r, "X-DEBUGINFOD-FILE", file.c_str() );
add_mhd_last_modified (r, s.st_mtime);
if (verbose > 1)
obatched(clog) << "serving file " << b_source0 << endl;
@@ -1516,6 +1528,7 @@ string canonicalized_archive_entry_pathname(struct archive_entry *e)
static struct MHD_Response*
handle_buildid_r_match (bool internal_req_p,
+ bool describe,
int64_t b_mtime,
const string& b_source0,
const string& b_source1,
@@ -1546,12 +1559,20 @@ handle_buildid_r_match (bool internal_req_p,
fdcache.clear(b_source0, b_source1);
break; // branch out of if "loop", to try new libarchive fetch attempt
}
-
- struct MHD_Response* r = MHD_create_response_from_fd (fs.st_size, fd);
+ struct MHD_Response* r;
+ if (describe)
+ {
+ inc_metric ("http_responses_total","result","file-describe");
+ r = MHD_create_response_from_buffer (0, (void*)"", MHD_RESPMEM_PERSISTENT);
+ }
+ else
+ {
+ r = MHD_create_response_from_fd (fs.st_size, fd);
+ }
if (r == 0)
{
if (verbose)
- obatched(clog) << "cannot create fd-response for " << b_source0 << endl;
+ obatched(clog) << "cannot create response for " << b_source0 << endl;
close(fd);
break; // branch out of if "loop", to try new libarchive fetch attempt
}
@@ -1559,9 +1580,9 @@ handle_buildid_r_match (bool internal_req_p,
inc_metric ("http_responses_total","result","archive fdcache");
MHD_add_response_header (r, "Content-Type", "application/octet-stream");
+ MHD_add_response_header (r, "X-DEBUGINFOD-FILE", b_source1.c_str());
MHD_add_response_header (r, "X-DEBUGINFOD-SIZE", to_string(fs.st_size).c_str());
MHD_add_response_header (r, "X-DEBUGINFOD-ARCHIVE", b_source0.c_str());
- MHD_add_response_header (r, "X-DEBUGINFOD-FILE", b_source1.c_str());
add_mhd_last_modified (r, fs.st_mtime);
if (verbose > 1)
obatched(clog) << "serving fdcache archive " << b_source0 << " file " << b_source1 << endl;
@@ -1725,6 +1746,7 @@ handle_buildid_r_match (bool internal_req_p,
static struct MHD_Response*
handle_buildid_match (bool internal_req_p,
+ bool describe,
int64_t b_mtime,
const string& b_stype,
const string& b_source0,
@@ -1734,9 +1756,9 @@ handle_buildid_match (bool internal_req_p,
try
{
if (b_stype == "F")
- return handle_buildid_f_match(internal_req_p, b_mtime, b_source0, result_fd);
+ return handle_buildid_f_match(internal_req_p, describe, b_mtime, b_source0, result_fd);
else if (b_stype == "R")
- return handle_buildid_r_match(internal_req_p, b_mtime, b_source0, b_source1, result_fd);
+ return handle_buildid_r_match(internal_req_p, describe, b_mtime, b_source0, b_source1, result_fd);
}
catch (const reportable_exception &e)
{
@@ -1803,6 +1825,7 @@ static struct MHD_Response*
handle_buildid (MHD_Connection* conn,
const string& buildid /* unsafe */,
const string& artifacttype /* unsafe */,
+ const bool describe,
const string& suffix /* unsafe */,
int *result_fd)
{
@@ -1883,11 +1906,11 @@ handle_buildid (MHD_Connection* conn,
if (verbose > 1)
obatched(clog) << "found mtime=" << b_mtime << " stype=" << b_stype
- << " source0=" << b_source0 << " source1=" << b_source1 << endl;
+ << " source0=" << b_source0 << " source1=" << b_source1 << " describe="<< describe << endl;
// Try accessing the located match.
// XXX: in case of multiple matches, attempt them in parallel?
- auto r = handle_buildid_match (conn ? false : true,
+ auto r = handle_buildid_match (conn ? false : true, describe,
b_mtime, b_stype, b_source0, b_source1, result_fd);
if (r)
return r;
@@ -1956,6 +1979,7 @@ and will not query the upstream servers");
(const unsigned char*) buildid.c_str(),
0, suffix.c_str(), NULL);
}
+
else
fd = -errno; /* Set by debuginfod_begin. */
debuginfod_pool_end (client);
@@ -1967,7 +1991,13 @@ and will not query the upstream servers");
int rc = fstat (fd, &s);
if (rc == 0)
{
- auto r = MHD_create_response_from_fd ((uint64_t) s.st_size, fd);
+ struct MHD_Response *r = 0;
+ if (describe)
+ {
+ r = MHD_create_response_from_buffer(0, (void*)"", MHD_RESPMEM_PERSISTENT);
+ }
+ else r = MHD_create_response_from_fd ((uint64_t) s.st_size, fd);
+
if (r)
{
MHD_add_response_header (r, "Content-Type", "application/octet-stream");
@@ -2165,11 +2195,12 @@ handler_cb (void * /*cls*/,
struct timespec ts_start, ts_end;
clock_gettime (CLOCK_MONOTONIC, &ts_start);
double afteryou = 0.0;
+ bool describe = (string(method) == "HEAD");
try
{
- if (string(method) != "GET")
- throw reportable_exception(400, "we support GET only");
+ if (string(method) != "GET" && !describe)
+ throw reportable_exception(400, "we only support GET and HEAD if using \'describe\'.");
/* Start decoding the URL. */
size_t slash1 = url_copy.find('/', 1);
@@ -2217,7 +2248,7 @@ handler_cb (void * /*cls*/,
// get the resulting fd so we can report its size
int fd;
- r = handle_buildid(connection, buildid, artifacttype, suffix, &fd);
+ r = handle_buildid(connection, buildid, artifacttype, describe, suffix, &fd);
if (r)
{
struct stat fs;
@@ -2250,6 +2281,7 @@ handler_cb (void * /*cls*/,
}
rc = MHD_queue_response (connection, MHD_HTTP_OK, r);
+ obatched(clog) << "describe" << describe<< "response "<<r<< " connection "<<connection<<endl;
http_code = MHD_HTTP_OK;
MHD_destroy_response (r);
}
@@ -2334,7 +2366,7 @@ dwarf_extract_source_paths (Elf *elf, set<string>& debug_sourcefiles)
struct MHD_Response *r = 0;
try
{
- r = handle_buildid (0, buildid, "debuginfo", "", &alt_fd);
+ r = handle_buildid (0, buildid, "debuginfo", false, "", &alt_fd);
}
catch (const reportable_exception& e)
{