diff --git a/usr.sbin/bhyvectl/bhyvectl.c b/usr.sbin/bhyvectl/bhyvectl.c --- a/usr.sbin/bhyvectl/bhyvectl.c +++ b/usr.sbin/bhyvectl/bhyvectl.c @@ -249,12 +249,13 @@ } } -#ifdef BHYVE_SNAPSHOT static int -send_message(const char *vmname, nvlist_t *nvl) +ipc_send_message(const char *vmname, nvlist_t *request) { struct sockaddr_un addr; int err = 0, socket_fd; + const char* errmsg; + nvlist_t *reply; socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); if (socket_fd < 0) { @@ -275,18 +276,27 @@ goto done; } - if (nvlist_send(socket_fd, nvl) < 0) { - perror("nvlist_send() failed"); - err = errno; + reply = nvlist_xfer(socket_fd, request, 0); + request = NULL; + if (reply == NULL) { + perror("nvlist_xfer() failed"); + goto done; + } + if (nvlist_exists_string(reply, "error")) { + errmsg = nvlist_get_string(reply, "error"); + fprintf(stderr, "%s: IPC command failed: %s\n", __func__, errmsg); + err = -1; } done: - nvlist_destroy(nvl); + if (request != NULL) + nvlist_destroy(request); if (socket_fd >= 0) close(socket_fd); return (err); } +#ifdef BHYVE_SNAPSHOT static int open_directory(const char *file) { @@ -318,7 +328,7 @@ nvlist_add_bool(nvl, "suspend", suspend); nvlist_move_descriptor(nvl, "fddir", fd); - return (send_message(vmname, nvl)); + return (ipc_send_message(vmname, nvl)); } #endif