Merge pull request #36 from rbradford/use-context-for-launch

qemu: Use the supplied context.Context for launching
This commit is contained in:
Rob Bradford 2018-08-14 18:11:35 +01:00 committed by GitHub
commit d8f80cafe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1235,7 +1235,7 @@ type Config struct {
// Path is the qemu binary path.
Path string
// Ctx is not used at the moment.
// Ctx is the context used when launching qemu.
Ctx context.Context
// Name is the qemu guest name
@ -1632,7 +1632,12 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
return "", err
}
return LaunchCustomQemu(config.Ctx, config.Path, config.qemuParams,
ctx := config.Ctx
if ctx == nil {
ctx = context.Background()
}
return LaunchCustomQemu(ctx, config.Path, config.qemuParams,
config.fds, nil, logger)
}
@ -1640,10 +1645,6 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) {
//
// The path parameter is used to pass the qemu executable path.
//
// The ctx parameter is not currently used but has been added so that the
// signature of this function will not need to change when launch cancellation
// is implemented.
//
// params is a slice of options to pass to qemu-system-x86_64 and fds is a
// list of open file descriptors that are to be passed to the spawned qemu
// process. The attrs parameter can be used to control aspects of the
@ -1668,7 +1669,7 @@ func LaunchCustomQemu(ctx context.Context, path string, params []string, fds []*
}
/* #nosec */
cmd := exec.Command(path, params...)
cmd := exec.CommandContext(ctx, path, params...)
if len(fds) > 0 {
logger.Infof("Adding extra file %v", fds)
cmd.ExtraFiles = fds