[PATCH] Move libcurl initialization to urlinstTransfer() (#537870).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Recent trees have been giving errors when we get to the stage2 download
point, such as this one:

    Unable to retrieve http://download.fedoraproject.org/pub/fedora/linux/development/x86_64/os//images/install.img.

libcurl needs to be initialized inside urlinstTransfer() so it has the
latest network state for the system.  The above error is caused by old
DNS settings.  libcurl won't automatically do a res_init(), so we need
to set up a new curl instance and use that.

Since this patch moves curl usage to be exclusively within
urlinstTransfer(), move 'curl' to that function as well and remove it
from loaderData.

Add curl cleanup calls at the end of urlinstTransfer().
---
 loader/loader.c |    4 ----
 loader/loader.h |    3 ---
 loader/urls.c   |   35 ++++++++++++++++++++++-------------
 3 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/loader/loader.c b/loader/loader.c
index 12e46c5..e78419e 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -54,7 +54,6 @@
 #include <linux/serial.h>
 #include <linux/vt.h>
 
-#include <curl/curl.h>
 #include <glib.h>
 
 #ifdef USE_MTRACE
@@ -1933,9 +1932,6 @@ int main(int argc, char ** argv) {
     loaderData.fw_search_pathz_len = -1;
     loaderData.dhcpTimeout = -1;
 
-    curl_global_init(CURL_GLOBAL_SSL);
-    loaderData.curl = curl_easy_init();
-
     extraArgs[0] = NULL;
     parseCmdLineFlags(&loaderData, cmdLine);
 
diff --git a/loader/loader.h b/loader/loader.h
index ffb4087..910afd6 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -18,7 +18,6 @@
  */
 
 #include <stdint.h>
-#include <curl/curl.h>
 
 #ifndef LOADER_H
 #define LOADER_H
@@ -158,8 +157,6 @@ struct loaderData_s {
 
     int inferredStage2, invalidRepoParam;
 
-    CURL *curl;
-
     /* Proxy info needs to be in the loaderData so we can get these
      * settings off the command line, too.
      */
diff --git a/loader/urls.c b/loader/urls.c
index 495516a..0d1c92b 100644
--- a/loader/urls.c
+++ b/loader/urls.c
@@ -37,6 +37,7 @@
 #include <unistd.h>
 #include <netdb.h>
 #include <errno.h>
+#include <curl/curl.h>
 
 #include "lang.h"
 #include "loader.h"
@@ -103,6 +104,7 @@ int splitProxyParam(char *param, char **user, char **password, char **host,
 int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
                     char **extraHeaders, char *dest) {
     struct progressCBdata *cb_data;
+    CURL *curl = NULL;
     CURLcode status;
     struct curl_slist *headers = NULL;
     char *version;
@@ -112,34 +114,38 @@ int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
 
     f = fopen(dest, "w");
 
+    /* Initialize libcurl */
+    curl_global_init(CURL_GLOBAL_SSL);
+    curl = curl_easy_init();
+
     /* Clear out all the old settings, since libcurl preserves them for as
      * long as you use the same handle and settings might have changed.
      */
-    curl_easy_reset(loaderData->curl);
+    curl_easy_reset(curl);
 
     if (asprintf(&version, "anaconda/%s", VERSION) == -1) {
         logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__);
         abort();
     }
 
-    curl_easy_setopt(loaderData->curl, CURLOPT_USERAGENT, version);
-    curl_easy_setopt(loaderData->curl, CURLOPT_URL, ui->url);
-    curl_easy_setopt(loaderData->curl, CURLOPT_WRITEDATA, f);
+    curl_easy_setopt(curl, CURLOPT_USERAGENT, version);
+    curl_easy_setopt(curl, CURLOPT_URL, ui->url);
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);
 
     /* If a proxy was provided, add the options for that now. */
     if (loaderData->proxy && strcmp(loaderData->proxy, "")) {
-        curl_easy_setopt(loaderData->curl, CURLOPT_PROXY, loaderData->proxy);
+        curl_easy_setopt(curl, CURLOPT_PROXY, loaderData->proxy);
 
         if (loaderData->proxyPort && strcmp(loaderData->proxyPort, ""))
-            curl_easy_setopt(loaderData->curl, CURLOPT_PROXYPORT,
+            curl_easy_setopt(curl, CURLOPT_PROXYPORT,
                              strtol(loaderData->proxyPort, NULL, 10));
 
         if (loaderData->proxyUser && strcmp(loaderData->proxyUser, ""))
-            curl_easy_setopt(loaderData->curl, CURLOPT_PROXYUSERNAME,
+            curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME,
                              loaderData->proxyUser);
 
         if (loaderData->proxyPassword && strcmp(loaderData->proxyPassword, ""))
-            curl_easy_setopt(loaderData->curl, CURLOPT_PROXYPASSWORD,
+            curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD,
                              loaderData->proxyPassword);
     }
 
@@ -149,7 +155,7 @@ int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
             headers = curl_slist_append(headers, extraHeaders[i]);
         }
 
-        curl_easy_setopt(loaderData->curl, CURLOPT_HTTPHEADER, headers);
+        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
     }
 
     /* Only set up the progress bar if we've got a UI to display it. */
@@ -164,13 +170,13 @@ int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
 
         cb_data = winProgressBar(70, 5, _("Retrieving"), "%s %s...", _("Retrieving"), filename);
 
-        curl_easy_setopt(loaderData->curl, CURLOPT_NOPROGRESS, 0);
-        curl_easy_setopt(loaderData->curl, CURLOPT_PROGRESSFUNCTION, progress_cb);
-        curl_easy_setopt(loaderData->curl, CURLOPT_PROGRESSDATA, cb_data);
+        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+        curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_cb);
+        curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, cb_data);
     }
 
     /* Finally, do the transfer. */
-    status = curl_easy_perform(loaderData->curl);
+    status = curl_easy_perform(curl);
     if (status)
         logMessage(ERROR, "Error downloading %s: %s", ui->url, curl_easy_strerror(status));
 
@@ -183,6 +189,9 @@ int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
     fclose(f);
     free(version);
 
+    curl_easy_cleanup(curl);
+    curl_global_cleanup();
+
     return status;
 }
 
-- 
1.6.5.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux