Skip to content

Commit

Permalink
> fix vgpu-monitor panic due to cache file size incorrect
Browse files Browse the repository at this point in the history
Signed-off-by: Kebe <[email protected]>
  • Loading branch information
kebe7jun committed May 24, 2024
1 parent 3c0c045 commit 0cc987e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/vGPUmonitor/cudevshr.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func mmapcachefile(filename string, nc *nvidiaCollector) error {
fmt.Println("openfile error=", err.Error())
return err
}
ss, _ := f.Stat()
if ss.Size() < int64(unsafe.Sizeof(*m)) {
return fmt.Errorf("cache file %s size %d is less than %d", filename, ss.Size(), unsafe.Sizeof(*m))
}
data, err := syscall.Mmap(int(f.Fd()), 0, int(unsafe.Sizeof(*m)), syscall.PROT_WRITE|syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
return err
Expand Down

0 comments on commit 0cc987e

Please sign in to comment.