summaryrefslogtreecommitdiff
path: root/internal/ior.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-27 18:33:40 +0200
committerPaul Buetow <paul@buetow.org>2026-02-27 18:33:40 +0200
commit3783d23b8d608c3bf4a2dedd6b4bfb9165439bed (patch)
tree69bf24794994d4cdd0e01e337de0510f7d5139b8 /internal/ior.go
parent1cf64c3e43b1bdc2b6443fd24db8028f3c96c6da (diff)
internal: validate live CLI mode behavior
Diffstat (limited to 'internal/ior.go')
-rw-r--r--internal/ior.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/internal/ior.go b/internal/ior.go
index bf0fb1f..cdddc24 100644
--- a/internal/ior.go
+++ b/internal/ior.go
@@ -4,6 +4,7 @@ import "C"
import (
"context"
+ "errors"
"fmt"
"os"
"os/signal"
@@ -35,6 +36,9 @@ var (
runTraceFn = runTrace
runTraceWithContextFn = runTraceWithContext
runTUIFn = tui.RunWithTraceStarter
+ getEUID = os.Geteuid
+
+ errRootPrivilegesRequired = errors.New("tracing requires root privileges (run with sudo)")
)
type tracepointModule interface {
@@ -140,12 +144,22 @@ func Run() error {
}
func dispatchRun(cfg flags.Flags) error {
+ if err := validateRunConfig(cfg); err != nil {
+ return err
+ }
if shouldRunTraceMode(cfg) {
return runTraceFn()
}
return runTUIFn(tuiTraceStarterFromRunTrace(runTraceWithContextFn))
}
+func validateRunConfig(cfg flags.Flags) error {
+ if cfg.LiveFlamegraph && cfg.FlamegraphEnable {
+ return errors.New("-live and -flamegraph are mutually exclusive")
+ }
+ return nil
+}
+
func shouldRunTraceMode(cfg flags.Flags) bool {
return cfg.PlainMode || cfg.FlamegraphEnable || cfg.LiveFlamegraph || cfg.PprofEnable
}
@@ -202,6 +216,10 @@ func runTrace() error {
}
func runTraceWithContext(parentCtx context.Context, started chan<- struct{}, configure func(*eventLoop)) error {
+ if getEUID() != 0 {
+ return errRootPrivilegesRequired
+ }
+
verbose := started == nil
logln := func(...any) {}
if verbose {
@@ -328,5 +346,5 @@ func signalTraceStarted(started chan<- struct{}) {
}
func shouldAutoStopByDuration(cfg flags.Flags) bool {
- return cfg.PlainMode || cfg.FlamegraphEnable || cfg.PprofEnable
+ return cfg.PlainMode || cfg.FlamegraphEnable || cfg.LiveFlamegraph || cfg.PprofEnable
}