Skip to content

Commit

Permalink
Merge pull request #1427 from steiler/fixvirtcheck
Browse files Browse the repository at this point in the history
fixing virt check, not closing files too early
  • Loading branch information
hellt committed Jun 9, 2023
2 parents aa874ca + 5800661 commit 486d2c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
- 'nodes/**'
- 'types/**'
- 'utils/**'
- 'netconf/**'
- 'labels/**'
- 'internal/**'
- 'errors/**'
- 'cert/**'
- 'border0_api/**'
- '.github/workflows/cicd.yml'
- 'go.mod'
- 'Makefile'
Expand Down
13 changes: 9 additions & 4 deletions virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ func VerifyVirtSupport() bool {

f, err := os.Open("/proc/2/status")
if err != nil {
log.Debug("proc/2/status file was not found. This means we run in a container and no virt checks are possible")
log.Debug("/proc/2/status file was not found. This means we run in a container and no virt checks are possible")
return true
}
f.Close()
defer f.Close() //skipcq: GO-S2307

// read first line of a /proc/2/status file to check if it contains kthreadd
// if it doesn't, we are in a container
scanner := bufio.NewScanner(f)

scanner.Scan()
if !strings.Contains(scanner.Text(), "kthreadd") {
log.Debug("proc/2/status first line doesn't contain kthreadd. This means we run in a container and no virt checks are possible")
log.Debug("/proc/2/status first line doesn't contain kthreadd. This means we run in a container and no virt checks are possible")
return true
}

Expand All @@ -44,7 +44,7 @@ func VerifyVirtSupport() bool {
log.Debugf("Error checking VirtSupport: %v", err)
return false
}
f.Close()
defer f.Close() //skipcq: GO-S2307

scanner = bufio.NewScanner(f)

Expand All @@ -62,5 +62,10 @@ func VerifyVirtSupport() bool {
return false
}

err = f.Sync()
if err != nil {
return false
}

return false
}

0 comments on commit 486d2c6

Please sign in to comment.