- return errno;
-}
-
-static int file_write(FdMigrationState *s, const void * buf, size_t size)
-{
- return write(s->fd, buf, size);
-}
-
-static int exec_close(FdMigrationState *s)
-{
- dprintf("exec_close\n");
- if (s->opaque) {
- qemu_fclose(s->opaque);
- s->opaque = NULL;
- s->fd = -1;
- }
- return 0;
-}
-
-MigrationState *exec_start_outgoing_migration(const char *command,
- int64_t bandwidth_limit,
- int detach)
-{
- FdMigrationState *s;
- FILE *f;
-
- s = qemu_mallocz(sizeof(*s));
-
- f = popen(command, "w");
- if (f == NULL) {
- dprintf("Unable to popen exec target\n");
- goto err_after_alloc;
+ s->file = qemu_popen_cmd(command, "w");
+ if (s->file == NULL) {
+ error_setg_errno(errp, errno, "failed to popen the migration target");
+ return;