- return errno;
-}
-
-static int file_write(MigrationState *s, const void * buf, size_t size)
-{
- return write(s->fd, buf, size);
-}
-
-static int exec_close(MigrationState *s)
-{
- int ret = 0;
- DPRINTF("exec_close\n");
- if (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 ret;
-}
-
-int exec_start_outgoing_migration(MigrationState *s, const char *command)
-{
- FILE *f;
-
- f = popen(command, "w");
- if (f == NULL) {
- DPRINTF("Unable to popen exec target\n");
- goto err_after_popen;
+ s->file = qemu_popen_cmd(command, "w");
+ if (s->file == NULL) {
+ error_setg_errno(errp, errno, "failed to popen the migration target");
+ return;