FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian Kernel

 
 
LinkBack Thread Tools
 
Old 11-18-2009, 07:30 PM
David Cantrell
 
Default Move libcurl initialization to urlinstTransfer() (#537870).

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@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 11-18-2009, 08:58 PM
Chris Lumens
 
Default Move libcurl initialization to urlinstTransfer() (#537870).

> 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.

That's too bad, but okay. At least we know what's going on.

> /* 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);

We shouldn't need to call curl_easy_reset since we're getting rid of the
handle at the end of every call to urlinstTransfer, right?

- Chris

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 11-18-2009, 09:31 PM
David Cantrell
 
Default Move libcurl initialization to urlinstTransfer() (#537870).

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 18 Nov 2009, Chris Lumens wrote:


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.


That's too bad, but okay. At least we know what's going on.


/* 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);


We shouldn't need to call curl_easy_reset since we're getting rid of the
handle at the end of every call to urlinstTransfer, right?


That's a good point. I'll remove the curl_easy_reset() line and test.
Assuming loader doesn't explode and spew library guts all over me, I'll
commit.

- --
David Cantrell <dcantrell@redhat.com>

Red Hat / Honolulu, HI

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAksEddIACgkQ5hsjjIy1VknAdQCfUtYVnb/s4Y9LRB6WpVQ5ySXy
7bkAnjKOqPN4a4r+wsqvM1H63c5+0QFG
=x9gX
-----END PGP SIGNATURE-----

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

Thread Tools




All times are GMT. The time now is 06:55 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org