Skip to content

Commit

Permalink
feat: print debug runtime information
Browse files Browse the repository at this point in the history
  • Loading branch information
joshiste committed Aug 21, 2023
1 parent 1e9dcf5 commit 5923764
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
19 changes: 19 additions & 0 deletions extruntime/extruntime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package extruntime

import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
"runtime"
)

func LogRuntimeInformation(level zerolog.Level) {
if !log.WithLevel(level).Enabled() {
return
}

log.WithLevel(level).Msgf("Go Runtime information: os=%s; arch=%s", runtime.GOOS, runtime.GOARCH)
log.WithLevel(level).Msgf("Process information: pid=%d; uid=%d; gid=%d", os.Getpid(), os.Getuid(), os.Getgid())
logCapsInformation(level)
logSeccompInformation(level)
}
13 changes: 13 additions & 0 deletions extruntime/extruntime_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build darwin

package extruntime

import (
"github.com/rs/zerolog"
)

func logCapsInformation(_ zerolog.Level) {
}

func logSeccompInformation(_ zerolog.Level) {
}
42 changes: 42 additions & 0 deletions extruntime/extruntime_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build linux

package extruntime

import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/seccomp/libseccomp-golang"

Check failure on line 8 in extruntime/extruntime_linux.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/seccomp/libseccomp-golang; to add it:
"os"
"os/exec"
"strconv"
)

func logCapsInformation(level zerolog.Level) {
caps, err := exec.Command("getpcaps", strconv.Itoa(os.Getpid())).CombinedOutput()
if err != nil {
log.WithLevel(level).Msgf("Process capabilities: %s", string(caps))
} else {
log.WithLevel(level).Msgf("Process capabilities: %s", err)
}
}
func logSeccompInformation(level zerolog.Level) {
ctx, err := seccomp.NewContext(seccomp.ActLog)
if err != nil {
log.WithLevel(level).Msgf("Seccomp: %s", err)
return
}
defer ctx.Release()

if err := ctx.Load(); err != nil {
log.WithLevel(level).Msgf("Seccomp: %s", err)
return
}

mode, err := ctx.GetMode()
if err != nil {
log.WithLevel(level).Msgf("Seccomp: %s", err)
return
}

log.WithLevel(level).Msgf("Seccomp: mode=%s", err)
}

0 comments on commit 5923764

Please sign in to comment.