diff options
Diffstat (limited to 'migration-exec.c')
-rw-r--r-- | migration-exec.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/migration-exec.c b/migration-exec.c index 0dd5aff..ab1dea2 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -20,14 +20,16 @@ #include "sysemu.h" #include "buffered_file.h" #include "block.h" +#include <sys/types.h> +#include <sys/wait.h> //#define DEBUG_MIGRATION_EXEC #ifdef DEBUG_MIGRATION_EXEC -#define dprintf(fmt, ...) \ +#define DPRINTF(fmt, ...) \ do { printf("migration-exec: " fmt, ## __VA_ARGS__); } while (0) #else -#define dprintf(fmt, ...) \ +#define DPRINTF(fmt, ...) \ do { } while (0) #endif @@ -43,13 +45,21 @@ static int file_write(FdMigrationState *s, const void * buf, size_t size) static int exec_close(FdMigrationState *s) { - dprintf("exec_close\n"); + int ret = 0; + DPRINTF("exec_close\n"); if (s->opaque) { - qemu_fclose(s->opaque); + ret = qemu_fclose(s->opaque); s->opaque = NULL; s->fd = -1; + if (ret != -1 && + WIFEXITED(ret) + && WEXITSTATUS(ret) == 0) { + ret = 0; + } else { + ret = -1; } - return 0; + } + return ret; } MigrationState *exec_start_outgoing_migration(const char *command, @@ -63,18 +73,18 @@ MigrationState *exec_start_outgoing_migration(const char *command, f = popen(command, "w"); if (f == NULL) { - dprintf("Unable to popen exec target\n"); + DPRINTF("Unable to popen exec target\n"); goto err_after_alloc; } s->fd = fileno(f); if (s->fd == -1) { - dprintf("Unable to retrieve file descriptor for popen'd handle\n"); + DPRINTF("Unable to retrieve file descriptor for popen'd handle\n"); goto err_after_open; } if (fcntl(s->fd, F_SETFD, O_NONBLOCK) == -1) { - dprintf("Unable to set nonblocking mode on file descriptor\n"); + DPRINTF("Unable to set nonblocking mode on file descriptor\n"); goto err_after_open; } @@ -116,9 +126,9 @@ static void exec_accept_incoming_migration(void *opaque) goto err; } qemu_announce_self(); - dprintf("successfully loaded vm state\n"); + DPRINTF("successfully loaded vm state\n"); /* we've successfully migrated, close the fd */ - qemu_set_fd_handler2(qemu_popen_fd(f), NULL, NULL, NULL, NULL); + qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL); vm_start(); err: @@ -129,14 +139,14 @@ int exec_start_incoming_migration(const char *command) { QEMUFile *f; - dprintf("Attempting to start an incoming migration\n"); + DPRINTF("Attempting to start an incoming migration\n"); f = qemu_popen_cmd(command, "r"); if(f == NULL) { - dprintf("Unable to apply qemu wrapper to popen file\n"); + DPRINTF("Unable to apply qemu wrapper to popen file\n"); return -errno; } - qemu_set_fd_handler2(qemu_popen_fd(f), NULL, + qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, exec_accept_incoming_migration, NULL, (void *)(unsigned long)f); |