Skip to content

Commit

Permalink
Do not open kcore in init()
Browse files Browse the repository at this point in the history
Otherwise, "pwru --help" might fail it it does not run as root.

Signed-off-by: Martynas Pumputis <[email protected]>
  • Loading branch information
brb committed Sep 13, 2024
1 parent 4a5c234 commit ca38cef
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/asm/x86/x86.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (
"fmt"
"log"
"os"
"sync"

"golang.org/x/arch/x86/x86asm"
)

var (
kcore *os.File
kcoreElf *elf.File
kcore *os.File
kcoreElf *elf.File
kcoreOnce sync.Once
)

func init() {
func parseKCore() {
var err error
if kcore, err = os.Open("/proc/kcore"); err != nil {
log.Fatalf("failed to open /proc/kcore: %s", err)
Expand All @@ -26,6 +28,8 @@ func init() {
}

func GetCallees(addr uint64, leng int) (callees []uint64, err error) {
kcoreOnce.Do(parseKCore)

if leng == 0 {
leng = 100000
}
Expand Down

0 comments on commit ca38cef

Please sign in to comment.