Skip to content

Commit e96edad

Browse files
committed
fix: Error passing arguments to chblade-exec-os.
Signed-off-by: Super-long <0x4f4f4f4f@gmail.com>
1 parent 9a34645 commit e96edad

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

exec/os/executor.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/chaosblade-io/chaosblade-spec-go/util"
2626
os_exec "os/exec"
2727
"path"
28-
"strings"
2928
"syscall"
3029
)
3130

@@ -47,26 +46,27 @@ func (e *Executor) Exec(uid string, ctx context.Context, model *spec.ExpModel) *
4746
return sshExecutor.Exec(uid, ctx, model)
4847
}
4948

50-
var args string
51-
var flags string
49+
var mode string
50+
var argsArray []string
51+
52+
_, isDestroy := spec.IsDestroy(ctx)
53+
if isDestroy {
54+
mode = spec.Destroy
55+
} else {
56+
mode = spec.Create
57+
}
58+
59+
argsArray = append(argsArray, mode, model.Target, model.ActionName, fmt.Sprintf("--uid=%s", uid))
5260
for k, v := range model.ActionFlags {
5361
if v == "" || k == "timeout" {
5462
continue
5563
}
56-
flags = fmt.Sprintf("%s --%s=%s", flags, k, v)
64+
argsArray = append(argsArray, fmt.Sprintf("--%s=%s", k, v))
5765
}
5866

59-
_, isDestroy := spec.IsDestroy(ctx)
60-
61-
if isDestroy {
62-
args = fmt.Sprintf("%s %s %s%s uid=%s", spec.Destroy, model.Target, model.ActionName, flags, uid)
63-
} else {
64-
args = fmt.Sprintf("%s %s %s%s uid=%s", spec.Create, model.Target, model.ActionName, flags, uid)
65-
}
6667
chaosOsBin := path.Join(util.GetProgramPath(), "bin", spec.ChaosOsBin)
67-
argsArray := strings.Split(args, " ")
6868
command := os_exec.CommandContext(ctx, chaosOsBin, argsArray...)
69-
log.Debugf(ctx, "run command, %s %s", chaosOsBin, args)
69+
log.Debugf(ctx, "run command, %s %v", chaosOsBin, argsArray)
7070

7171
if model.ActionProcessHang && !isDestroy {
7272
if err := command.Start(); err != nil {

0 commit comments

Comments
 (0)