fortify/internal/executable.go
Ophestra 468696f611
All checks were successful
Test / Create distribution (push) Successful in 18s
Test / Run NixOS test (push) Successful in 47s
internal: beforeExit before reachable fatal calls
These are the only two calls to log.Fatal* reachable during suspended output. Call fmsg.BeforeExit here to catch that.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-02-16 19:03:34 +09:00

29 lines
427 B
Go

package internal
import (
"log"
"os"
"sync"
"git.gensokyo.uk/security/fortify/internal/fmsg"
)
var (
executable string
executableOnce sync.Once
)
func copyExecutable() {
if name, err := os.Executable(); err != nil {
fmsg.BeforeExit()
log.Fatalf("cannot read executable path: %v", err)
} else {
executable = name
}
}
func MustExecutable() string {
executableOnce.Do(copyExecutable)
return executable
}