mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
ciao-launcher, qemu: Move launchQemu to qemu
The launcher function launchQemu has been moved to the qemu package and is now called LaunchQemu. Signed-off-by: Mark Ryan <mark.d.ryan@intel.com>
This commit is contained in:
parent
344aa22bd2
commit
306f54a907
62
qemu.go
Normal file
62
qemu.go
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
// Copyright (c) 2016 Intel Corporation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
*/
|
||||
|
||||
package qemu
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// LaunchQemu can be used to launch a new qemu instance by invoking the
|
||||
// qemu-system-x86_64 binary.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// This function writes its log output via logger parameter.
|
||||
//
|
||||
// The function will block until the launched qemu process exits. "", nil
|
||||
// will be returned if the launch succeeds. Otherwise a string containing
|
||||
// the contents of stderr + a Go error object will be returned.
|
||||
func LaunchQemu(ctx context.Context, params []string, fds []*os.File, logger QMPLog) (string, error) {
|
||||
errStr := ""
|
||||
cmd := exec.Command("qemu-system-x86_64", params...)
|
||||
if fds != nil {
|
||||
logger.Infof("Adding extra file %v", fds)
|
||||
cmd.ExtraFiles = fds
|
||||
}
|
||||
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
logger.Infof("launching qemu with: %v", params)
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
logger.Errorf("Unable to launch qemu: %v", err)
|
||||
errStr = stderr.String()
|
||||
logger.Errorf("%s", errStr)
|
||||
}
|
||||
return errStr, err
|
||||
}
|
3
qmp.go
3
qmp.go
@ -29,9 +29,6 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Code to launch qemu
|
||||
// move to package and document
|
||||
|
||||
// QMPLog is a logging interface used by the qemu package to log various
|
||||
// interesting pieces of information. Rather than introduce a dependency
|
||||
// on a given logging package, qemu presents this interface that allows
|
||||
|
Loading…
Reference in New Issue
Block a user