Skip to content

Commit

Permalink
protocol: Don't segfault if appliance crashes during FileIn upload (R…
Browse files Browse the repository at this point in the history
…HBZ#914931).

Instead of the segfault you now get a more informative error:

*stdin*:0: libguestfs: error: connection to daemon was closed unexpectedly.
This usually means the libguestfs appliance crashed.  Please enable
debugging (LIBGUESTFS_DEBUG=1) and rerun the command, then look at the
debug messages output prior to this error.
libguestfs: error: /dev/stdout: write: Broken pipe
libguestfs: error: file receive cancelled by daemon
  • Loading branch information
rwmjones committed Feb 23, 2013
1 parent d950e1a commit 7953128
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/proto.c
Expand Up @@ -483,6 +483,20 @@ UNEXPEOF_TEST_TOOL));
UNEXPEOF_TEST_TOOL));
}

static inline void
unexpected_closed_connection_from_daemon_error (guestfs_h *g)
{
#define UNEXPCLO_ERROR "connection to daemon was closed unexpectedly.\n"
if (!g->verbose)
error (g, _(UNEXPCLO_ERROR
"This usually means the libguestfs appliance crashed. Please enable\n"
"debugging (LIBGUESTFS_DEBUG=1) and rerun the command, then look at the\n"
"debug messages output prior to this error."));
else
error (g, _(UNEXPCLO_ERROR
"See earlier debug messages."));
}

static int
recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
{
Expand All @@ -491,6 +505,15 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
char lenbuf[4];
ssize_t nr;

/* RHBZ#914931: Along some (rare) paths, we might have closed the
* socket connection just before this function is called, so just
* return an error if this happens.
*/
if (g->sock == -1) {
unexpected_closed_connection_from_daemon_error (g);
return -1;
}

FD_ZERO (&rset);

if (g->fd[1] >= 0) /* Read qemu stdout for log messages & EOF. */
Expand Down Expand Up @@ -1035,7 +1058,12 @@ guestfs___recv (guestfs_h *g, const char *fn,
return 0;
}

/* Same as guestfs___recv, but it discards the reply message. */
/* Same as guestfs___recv, but it discards the reply message.
*
* Notes (XXX):
* (1) This returns an int, but all current callers ignore it.
* (2) The error string may end up being set twice on error paths.
*/
int
guestfs___recv_discard (guestfs_h *g, const char *fn)
{
Expand Down

0 comments on commit 7953128

Please sign in to comment.