Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the error "cgroup2 path not found" #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions exec/executor_common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *CommonExecutor) Name() string {

func (r *CommonExecutor) Exec(uid string, ctx context.Context, expModel *spec.ExpModel) *spec.Response {
if err := r.SetClient(expModel); err != nil {
log.Errorf(ctx, spec.ContainerExecFailed.Sprintf("GetClient", err))
log.Errorf(ctx, spec.ContainerExecFailed.Sprintf("GetClient,error: %v", err))
return spec.ResponseFailWithFlags(spec.ContainerExecFailed, "GetClient", err)
}
containerId := expModel.ActionFlags[ContainerIdFlag.Name]
Expand All @@ -67,7 +67,7 @@ func (r *CommonExecutor) Exec(uid string, ctx context.Context, expModel *spec.Ex
}
pid, err, code := r.Client.GetPidById(ctx, container.ContainerId)
if err != nil {
log.Errorf(ctx, err.Error())
log.Errorf(ctx, "GetPidById,error: %v", err)
return spec.ResponseFail(code, err.Error(), nil)
}

Expand Down Expand Up @@ -114,6 +114,13 @@ func (r *CommonExecutor) Exec(uid string, ctx context.Context, expModel *spec.Ex
chaosOsBin := path.Join(util.GetProgramPath(), spec.BinPath, spec.ChaosOsBin)
argsArray := strings.Split(args, " ")

log.Debugf(ctx, "chaosOsBin full path: %s", chaosOsBin)

// 检查文件是否存在
if _, err := os.Stat(chaosOsBin); os.IsNotExist(err) {
log.Debugf(ctx, "chaos_os binary not found at: %s", chaosOsBin)
}

command := exec.CommandContext(ctx, chaosOsBin, argsArray...)
output, err := command.CombinedOutput()
outMsg := string(output)
Expand Down Expand Up @@ -163,19 +170,22 @@ func execForHangAction(uid string, ctx context.Context, expModel *spec.ExpModel,
if isCgroupV2 {
g, err := cgroupsv2.PidGroupPath(int(pid))
if err != nil {
sprintf := fmt.Sprintf("loading cgroup2 for %d, err ", pid, err.Error())
sprintf := fmt.Sprintf("loading cgroup2 for %d, err %s", pid, err.Error())
return spec.ReturnFail(spec.OsCmdExecFailed, sprintf)
}
cg, err := cgroupsv2.LoadManager("/sys/fs/cgroup/", g)

cgPath := path.Join(cgroupRoot, g)
cg, err := cgroupsv2.LoadManager(cgroupRoot, cgPath)
if err != nil {
if err != cgroupsv2.ErrCgroupDeleted {
if cg, err = cgroupsv2.NewManager(cgroupRoot, cgPath, nil); err != nil {
sprintf := fmt.Sprintf("cgroups V2 new manager failed, %s", err.Error())
return spec.ReturnFail(spec.OsCmdExecFailed, sprintf)
}
} else {
sprintf := fmt.Sprintf("cgroups V2 load failed, %s", err.Error())
return spec.ReturnFail(spec.OsCmdExecFailed, sprintf)
}
if cg, err = cgroupsv2.NewManager("/sys/fs/cgroup", cgroupRoot, nil); err != nil {
sprintf := fmt.Sprintf("cgroups V2 new manager failed, %s", err.Error())
return spec.ReturnFail(spec.OsCmdExecFailed, sprintf)
}
}
if err := command.Start(); err != nil {
sprintf := fmt.Sprintf("command start failed, %s", err.Error())
Expand Down