|
|
e76f14 |
From 6440601758720bd1390e768a8f26f313d7bb4ca9 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Tue, 7 Jun 2016 14:50:47 +0100
|
|
|
e76f14 |
Subject: [PATCH] p2v: Print full curl error when failing to fetch SSH identify
|
|
|
e76f14 |
URL (RHBZ#1343423).
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit 0e0a350c02b9c4d7a4108d2743ee1a61ce88a1f1)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
p2v/ssh.c | 23 +++++++++++++++++------
|
|
|
e76f14 |
1 file changed, 17 insertions(+), 6 deletions(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/p2v/ssh.c b/p2v/ssh.c
|
|
|
e76f14 |
index c4d7e2e..ce2b17b 100644
|
|
|
e76f14 |
--- a/p2v/ssh.c
|
|
|
e76f14 |
+++ b/p2v/ssh.c
|
|
|
e76f14 |
@@ -45,6 +45,7 @@
|
|
|
e76f14 |
#include <inttypes.h>
|
|
|
e76f14 |
#include <unistd.h>
|
|
|
e76f14 |
#include <errno.h>
|
|
|
e76f14 |
+#include <error.h>
|
|
|
e76f14 |
#include <locale.h>
|
|
|
e76f14 |
#include <assert.h>
|
|
|
e76f14 |
#include <libintl.h>
|
|
|
e76f14 |
@@ -168,11 +169,18 @@ static int
|
|
|
e76f14 |
curl_download (const char *url, const char *local_file)
|
|
|
e76f14 |
{
|
|
|
e76f14 |
char curl_config_file[] = "/tmp/curl.XXXXXX";
|
|
|
e76f14 |
+ char error_file[] = "/tmp/curlerr.XXXXXX";
|
|
|
e76f14 |
+ CLEANUP_FREE char *error_message = NULL;
|
|
|
e76f14 |
int fd, r;
|
|
|
e76f14 |
size_t i, len;
|
|
|
e76f14 |
FILE *fp;
|
|
|
e76f14 |
CLEANUP_FREE char *curl_cmd = NULL;
|
|
|
e76f14 |
|
|
|
e76f14 |
+ fd = mkstemp (error_file);
|
|
|
e76f14 |
+ if (fd == -1)
|
|
|
e76f14 |
+ error (EXIT_FAILURE, errno, "mkstemp: %s", error_file);
|
|
|
e76f14 |
+ close (fd);
|
|
|
e76f14 |
+
|
|
|
e76f14 |
/* Use a secure curl config file because escaping is easier. */
|
|
|
e76f14 |
fd = mkstemp (curl_config_file);
|
|
|
e76f14 |
if (fd == -1) {
|
|
|
e76f14 |
@@ -201,8 +209,8 @@ curl_download (const char *url, const char *local_file)
|
|
|
e76f14 |
fclose (fp);
|
|
|
e76f14 |
|
|
|
e76f14 |
/* Run curl to download the URL to a file. */
|
|
|
e76f14 |
- if (asprintf (&curl_cmd, "curl -f -o %s -K %s",
|
|
|
e76f14 |
- local_file, curl_config_file) == -1) {
|
|
|
e76f14 |
+ if (asprintf (&curl_cmd, "curl -f -s -S -o %s -K %s 2>%s",
|
|
|
e76f14 |
+ local_file, curl_config_file, error_file) == -1) {
|
|
|
e76f14 |
perror ("asprintf");
|
|
|
e76f14 |
exit (EXIT_FAILURE);
|
|
|
e76f14 |
}
|
|
|
e76f14 |
@@ -216,17 +224,20 @@ curl_download (const char *url, const char *local_file)
|
|
|
e76f14 |
|
|
|
e76f14 |
/* Did curl subprocess fail? */
|
|
|
e76f14 |
if (WIFEXITED (r) && WEXITSTATUS (r) != 0) {
|
|
|
e76f14 |
- /* XXX Better error handling. The codes can be looked up in
|
|
|
e76f14 |
- * the curl(1) man page.
|
|
|
e76f14 |
- */
|
|
|
e76f14 |
- set_ssh_error ("%s: curl error %d", url, WEXITSTATUS (r));
|
|
|
e76f14 |
+ if (read_whole_file (error_file, &error_message, NULL) == 0)
|
|
|
e76f14 |
+ set_ssh_error ("%s: %s", url, error_message);
|
|
|
e76f14 |
+ else
|
|
|
e76f14 |
+ set_ssh_error ("%s: curl error %d", url, WEXITSTATUS (r));
|
|
|
e76f14 |
+ unlink (error_file);
|
|
|
e76f14 |
return -1;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
else if (!WIFEXITED (r)) {
|
|
|
e76f14 |
set_ssh_error ("curl subprocess got a signal (%d)", r);
|
|
|
e76f14 |
+ unlink (error_file);
|
|
|
e76f14 |
return -1;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
+ unlink (error_file);
|
|
|
e76f14 |
return 0;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
--
|
|
|
7af31e |
1.8.3.1
|
|
|
e76f14 |
|