forked from Ivasoft/github-actions
Fix container Id detection from cgroup as "12:rdma:/" is possible
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
29
plugin.go
29
plugin.go
@@ -168,17 +168,24 @@ func getContainerId() (string, error) {
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
if !scanner.Scan() {
|
||||
return "", errors.New("cgroup is empty")
|
||||
for scanner.Scan() {
|
||||
// The file name is the container identifier
|
||||
// Example: 12:rdma:/docker/a33940bf95ec6c57b6d79a3edfa784a1364ce840fb92c9a7f3951b9f7b0ccccb/docker/330d9b057fdd54b224cd38daf370524f7e8c567ccf95f33a2388f02c0b854982
|
||||
line := scanner.Text()
|
||||
pathOffset := strings.LastIndex(line, ":")
|
||||
if pathOffset == -1 {
|
||||
continue
|
||||
}
|
||||
|
||||
cgroup := line[pathOffset + 1:]
|
||||
|
||||
result := path.Base(cgroup)
|
||||
if result == "." || result == "/" {
|
||||
continue
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// The file name is the container identifier
|
||||
// Example: 12:rdma:/docker/a33940bf95ec6c57b6d79a3edfa784a1364ce840fb92c9a7f3951b9f7b0ccccb/docker/330d9b057fdd54b224cd38daf370524f7e8c567ccf95f33a2388f02c0b854982
|
||||
cgroup := scanner.Text()
|
||||
result := path.Base(cgroup)
|
||||
if result == "." {
|
||||
return "", errors.New("cgroup is unexpected")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return "", errors.New("no suitable cgroup entry found")
|
||||
}
|
||||
Reference in New Issue
Block a user