Skip to content

Commit

Permalink
Improve logging of curl_easy_perform() errors. (#100)
Browse files Browse the repository at this point in the history
Curl error messages can give valuable hints to debug problems.

Co-authored-by: Martin Lambers <[email protected]>
  • Loading branch information
marlam and Martin Lambers authored Oct 18, 2024
1 parent baa3f9c commit 68fcf22
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ char *API(const char* url, const char *method, char *headers[], const char* data
{
CURL* curl;
CURL_FETCH fetcher;
char curl_errorbuffer[CURL_ERROR_SIZE];

/* Prepare Headers... */
struct curl_slist* request_headers = NULL;
Expand All @@ -75,6 +76,7 @@ char *API(const char* url, const char *method, char *headers[], const char* data
long response_code = 999;

curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorbuffer);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, request_headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_callback);
Expand All @@ -89,7 +91,7 @@ char *API(const char* url, const char *method, char *headers[], const char* data
/* Perform the request */
if (curl_easy_perform(curl) != CURLE_OK)
{
log_message(LOG_ERR, SERVER_UNREACHABLE);
log_message(LOG_ERR, "Cannot contact server: %s", curl_errorbuffer);
tty_output(pamh, SERVER_UNREACHABLE);
}
/* Check response */
Expand Down

0 comments on commit 68fcf22

Please sign in to comment.