Skip to content

Commit

Permalink
p2v: Print full curl error when failing to fetch SSH identify URL (RH…
Browse files Browse the repository at this point in the history
…BZ#1343423).
  • Loading branch information
rwmjones committed Jun 7, 2016
1 parent 3064c85 commit 0e0a350
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions p2v/ssh.c
Expand Up @@ -170,11 +170,18 @@ static int
curl_download (const char *url, const char *local_file)
{
char curl_config_file[] = "/tmp/curl.XXXXXX";
char error_file[] = "/tmp/curlerr.XXXXXX";
CLEANUP_FREE char *error_message = NULL;
int fd, r;
size_t i, len;
FILE *fp;
CLEANUP_FREE char *curl_cmd = NULL;

fd = mkstemp (error_file);
if (fd == -1)
error (EXIT_FAILURE, errno, "mkstemp: %s", error_file);
close (fd);

/* Use a secure curl config file because escaping is easier. */
fd = mkstemp (curl_config_file);
if (fd == -1)
Expand All @@ -199,8 +206,8 @@ curl_download (const char *url, const char *local_file)
fclose (fp);

/* Run curl to download the URL to a file. */
if (asprintf (&curl_cmd, "curl -f -o %s -K %s",
local_file, curl_config_file) == -1)
if (asprintf (&curl_cmd, "curl -f -s -S -o %s -K %s 2>%s",
local_file, curl_config_file, error_file) == -1)
error (EXIT_FAILURE, errno, "asprintf");

r = system (curl_cmd);
Expand All @@ -210,17 +217,20 @@ curl_download (const char *url, const char *local_file)

/* Did curl subprocess fail? */
if (WIFEXITED (r) && WEXITSTATUS (r) != 0) {
/* XXX Better error handling. The codes can be looked up in
* the curl(1) man page.
*/
set_ssh_error ("%s: curl error %d", url, WEXITSTATUS (r));
if (read_whole_file (error_file, &error_message, NULL) == 0)
set_ssh_error ("%s: %s", url, error_message);
else
set_ssh_error ("%s: curl error %d", url, WEXITSTATUS (r));
unlink (error_file);
return -1;
}
else if (!WIFEXITED (r)) {
set_ssh_error ("curl subprocess got a signal (%d)", r);
unlink (error_file);
return -1;
}

unlink (error_file);
return 0;
}

Expand Down

0 comments on commit 0e0a350

Please sign in to comment.