-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: print debug runtime information
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
"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) | ||
} |