From b2b11cc8fb2144c13f4f9138b4420248ea200fb6 Mon Sep 17 00:00:00 2001
From: LiangZhang <zhangliang5@Huawei.com>
Date: Sun, 27 Sep 2020 18:10:18 +0800
Subject: [PATCH] runtime: fix cmd params of direct use stratovirt binary

reason: when directly use stratovirt binary, not through bash, it will cause problem.

Signed-off-by: LiangZhang <zhangliang5@Huawei.com>
---
 virtcontainers/stratovirt.go | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/virtcontainers/stratovirt.go b/virtcontainers/stratovirt.go
index 6db8dc0..020135e 100644
--- a/virtcontainers/stratovirt.go
+++ b/virtcontainers/stratovirt.go
@@ -133,21 +133,21 @@ func (s *stratovirt) startSandbox(timeout int) error {
 	defer span.Finish()
 
 	var params []string
-	params = append(params, "-name "+fmt.Sprintf("sandbox-%s", s.id))
-	params = append(params, "-api-channel unix:"+s.socketPath)
+	params = append(params, "-name", fmt.Sprintf("sandbox-%s", s.id))
+	params = append(params, "-api-channel", fmt.Sprintf("unix:%s", s.socketPath))
 
 	if kernelPath, err := s.config.KernelAssetPath(); err == nil {
-		params = append(params, "-kernel "+kernelPath)
+		params = append(params, "-kernel", kernelPath)
 	}
 
 	if initrdPath, err := s.config.InitrdAssetPath(); err == nil {
-		params = append(params, "-initrd "+initrdPath)
+		params = append(params, "-initrd", initrdPath)
 	}
 
-	params = append(params, "-append "+s.getKernelCmdLine())
-	params = append(params, fmt.Sprintf("-smp %d", s.config.NumVCPUs))
-	params = append(params, fmt.Sprintf("-m %d", uint64(s.config.MemorySize)*1024*1024))
-	params = append(params, fmt.Sprintf("-chardev id=charconsole0,path=%s", s.consolePath))
+	params = append(params, "-append", s.getKernelCmdLine())
+	params = append(params, "-smp", fmt.Sprintf("%d", s.config.NumVCPUs))
+	params = append(params, "-m", fmt.Sprintf("%d", uint64(s.config.MemorySize)*1024*1024))
+	params = append(params, "-chardev", fmt.Sprintf("id=charconsole0,path=%s", s.consolePath))
 
 	// add devices to cmdline
 	for _, d := range s.devices {
@@ -156,14 +156,14 @@ func (s *stratovirt) startSandbox(timeout int) error {
 			name := v.Name()
 			mac := v.HardwareAddr()
 			tapName := v.NetworkPair().TapInterface.TAPIface.Name
-			params = append(params, fmt.Sprintf("-net id=%s,mac=%s,host_dev_name=%s", name, mac, tapName))
+			params = append(params, "-net", fmt.Sprintf("id=%s,mac=%s,host_dev_name=%s", name, mac, tapName))
 		case config.BlockDrive:
 			id := v.ID
 			path := v.File
-			params = append(params, fmt.Sprintf("-drive id=%s,file=%s", id, path))
+			params = append(params, "-drive", fmt.Sprintf("id=%s,file=%s", id, path))
 		case types.VSock:
 			v.VhostFd.Close()
-			params = append(params, fmt.Sprintf("-device vsock,id=vsock-id,guest-cid=%d", v.ContextID))
+			params = append(params, "-device", fmt.Sprintf("vsock,id=vsock-id,guest-cid=%d", v.ContextID))
 		default:
 			s.Logger().Error("Adding device type is unsupported")
 		}
@@ -175,7 +175,7 @@ func (s *stratovirt) startSandbox(timeout int) error {
 	// append logfile only on debug
 	if s.config.Debug {
 		dir := filepath.Join(store.RunVMStoragePath(), s.id)
-		params = append(params, fmt.Sprintf("-D %s/stratovirt.log", dir))
+		params = append(params, "-D", fmt.Sprintf("%s/stratovirt.log", dir))
 	}
 
 	// disable Seccomp
@@ -183,8 +183,6 @@ func (s *stratovirt) startSandbox(timeout int) error {
 		params = append(params, "-disable-seccomp")
 	}
 
-	s.Logger().Info("StratoVirt start with params: ", strings.Join(params, " "))
-
 	dir := filepath.Join(store.RunVMStoragePath(), s.id)
 	err := os.MkdirAll(dir, store.DirMode)
 	if err != nil {
@@ -205,6 +203,8 @@ func (s *stratovirt) startSandbox(timeout int) error {
 	}
 
 	cmd := exec.CommandContext(s.ctx, binPath, params...)
+	s.Logger().Info("StratoVirt start with params: ", cmd)
+
 	if err := cmd.Run(); err != nil {
 		s.Logger().WithField("Error starting hypervisor, please check the params", err).Error()
 		return err
-- 
1.8.3.1

