aboutsummaryrefslogtreecommitdiffhomepage
path: root/sandbox/executable.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-17 02:55:36 +0900
committerOphestra <cat@gensokyo.uk>2025-03-17 02:55:36 +0900
commit24618ab9a1524e8b8986a9bf67667288e642fcf1 (patch)
treeb3f2a71a2c9bedf937d0fec00092ad9133cb3ec9 /sandbox/executable.go
parent9ce4706a0766880c072cccd2643d66f614a6a16b (diff)
sandbox: move out of internal
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'sandbox/executable.go')
-rw-r--r--sandbox/executable.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/sandbox/executable.go b/sandbox/executable.go
new file mode 100644
index 00000000..5f73d238
--- /dev/null
+++ b/sandbox/executable.go
@@ -0,0 +1,26 @@
+package sandbox
+
+import (
+ "log"
+ "os"
+ "sync"
+)
+
+var (
+ executable string
+ executableOnce sync.Once
+)
+
+func copyExecutable() {
+ if name, err := os.Executable(); err != nil {
+ msg.BeforeExit()
+ log.Fatalf("cannot read executable path: %v", err)
+ } else {
+ executable = name
+ }
+}
+
+func MustExecutable() string {
+ executableOnce.Do(copyExecutable)
+ return executable
+}