]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod: file:// URLs: handle curl resp. code
authorKonrad Kleine <kkleine@redhat.com>
Wed, 26 Feb 2020 15:00:43 +0000 (10:00 -0500)
committerMark Wielaard <mark@klomp.org>
Wed, 26 Feb 2020 20:10:40 +0000 (21:10 +0100)
When file:// is used for DEBUGINFOD_URLS, then the response code for a
successful server query is 0 and not 200.

Using file:// can be helpful when you want to test your
debuginfod-client integration against a mocked file tree that mimics the
HTTP URLs from the debuginfod server. This way you don't have to run the
debuginfod server at all.

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

Signed-off-by: Konrad Kleine <kkleine@redhat.com>
debuginfod/ChangeLog
debuginfod/debuginfod-client.c
tests/ChangeLog
tests/run-debuginfod-find.sh

index 16e1430952e2c1569cd22a1295d6f73cc595e4b5..7097050493f56179ee650ccee954fc1c36cfd40b 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-26  Konrad Kleine <kkleine@redhat.com>
+
+       * debuginfod-client.c (debuginfod_query_server): Handle curl's
+       response code correctly when DEBUGINFOD_URLS begin with file://
+
 2020-02-25  Frank Ch. Eigler  <fche@redhat.com>
 
        * debuginfod.cxx (parse_opt): Treat -R as if -Z.rpm .
index 186aa90a53bd1d9dbab9a7d5c153d1f2aa50735c..c1174486edfe6dfa7a0fd1cde6a7972a03b12627 100644 (file)
@@ -716,20 +716,34 @@ debuginfod_query_server (debuginfod_client *c,
           else
             {
               /* Query completed without an error. Confirm that the
-                 response code is 200 and set verified_handle.  */
-              long resp_code = 500;
-              CURLcode curl_res;
-
-              curl_res = curl_easy_getinfo(target_handle,
-                                           CURLINFO_RESPONSE_CODE,
-                                           &resp_code);
+                 response code is 200 when using HTTP/HTTPS and 0 when
+                 using file:// and set verified_handle.  */
 
-              if (curl_res == CURLE_OK
-                  && resp_code == 200
-                  && msg->easy_handle != NULL)
+              if (msg->easy_handle != NULL)
                 {
-                  verified_handle = msg->easy_handle;
-                  break;
+                  char *effective_url = NULL;
+                  long resp_code = 500;
+                  CURLcode ok1 = curl_easy_getinfo (target_handle,
+                                                   CURLINFO_EFFECTIVE_URL,
+                                                   &effective_url);
+                  CURLcode ok2 = curl_easy_getinfo (target_handle,
+                                                   CURLINFO_RESPONSE_CODE,
+                                                   &resp_code);
+                  if(ok1 == CURLE_OK && ok2 == CURLE_OK && effective_url)
+                    {
+                      if (strncmp (effective_url, "http", 4) == 0)
+                        if (resp_code == 200)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                      if (strncmp (effective_url, "file", 4) == 0)
+                        if (resp_code == 0)
+                          {
+                            verified_handle = msg->easy_handle;
+                            break;
+                          }
+                    }
                 }
             }
         }
index 32ca1ce0bcc7934aa8f5f13e8f7f5e2d5b98f94c..98e5c95488566255c15fa5f96e10993ba1217842 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-26  Konrad Kleine <kkleine@redhat.com>
+
+       * run-debuginfod-find.sh: added tests for DEBUGINFOD_URLS beginning
+       with "file://"
+
 2020-02-21  Mark Wielaard  <mark@klomp.org>
 
        * Makefile.am (TESTS_ENVIRONMENT): Explicitly unset DEBUGINFOD_URLS.
index 2964e7c077e5ed93e2e72b6b94499789de7dee96..0facc5557e2705cb9989c22f14ecbf4454f11434 100755 (executable)
@@ -40,7 +40,7 @@ cleanup()
   if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
   if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
 
-  rm -rf F R D L Z ${PWD}/.client_cache*
+  rm -rf F R D L Z ${PWD}/mocktree ${PWD}/.client_cache*
   exit_cleanup
 }
 
@@ -396,4 +396,20 @@ kill -int $PID3
 wait $PID3
 PID3=0
 
+########################################################################
+# Test fetching a file using file:// . No debuginfod server needs to be run for
+# this test.
+local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
+mkdir -p ${local_dir}
+echo "int main() { return 0; }" > ${local_dir}/main.c
+
+# first test that is doesn't work, when no DEBUGINFOD_URLS is set
+DEBUGINFOD_URLS=""
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
+
+# Now test is with proper DEBUGINFOD_URLS
+DEBUGINFOD_URLS="file://${PWD}/mocktree/"
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
+cmp $filename ${local_dir}/main.c
+
 exit 0