diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-21 01:49:36 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-21 01:49:36 +0900 |
| commit | 766dd89ffa198a315b043230f904636461c41efe (patch) | |
| tree | 163290a35109da0cae36c6453fc4b56529cf4d54 /cmd/hsu | |
| parent | 699c19e972a3cbcc714403aedffcb5ff74386cfc (diff) | |
internal: clean up build strings
These names are less ambiguous and should be understandable without reading the source code.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/hsu')
| -rw-r--r-- | cmd/hsu/main.go | 12 | ||||
| -rw-r--r-- | cmd/hsu/package.nix | 2 | ||||
| -rw-r--r-- | cmd/hsu/path.go | 20 |
3 files changed, 12 insertions, 22 deletions
diff --git a/cmd/hsu/main.go b/cmd/hsu/main.go index 27b97b5c..5901087c 100644 --- a/cmd/hsu/main.go +++ b/cmd/hsu/main.go @@ -26,6 +26,11 @@ const ( identityMax = 9999 ) +// hakureiPath is the absolute path to Hakurei. +// +// This is set by the linker. +var hakureiPath string + func main() { log.SetFlags(0) log.SetPrefix("hsu: ") @@ -43,13 +48,18 @@ func main() { log.Fatal("this program must not be started by root") } + if !path.IsAbs(hakureiPath) { + log.Fatal("this program is compiled incorrectly") + return + } + var toolPath string pexe := path.Join("/proc", strconv.Itoa(os.Getppid()), "exe") if p, err := os.Readlink(pexe); err != nil { log.Fatalf("cannot read parent executable path: %v", err) } else if strings.HasSuffix(p, " (deleted)") { log.Fatal("hakurei executable has been deleted") - } else if p != mustCheckPath(hmain) { + } else if p != hakureiPath { log.Fatal("this program must be started by hakurei") } else { toolPath = p diff --git a/cmd/hsu/package.nix b/cmd/hsu/package.nix index 5fce566b..6075cdb1 100644 --- a/cmd/hsu/package.nix +++ b/cmd/hsu/package.nix @@ -19,5 +19,5 @@ buildGoModule { ldflags = lib.attrsets.foldlAttrs ( ldflags: name: value: ldflags ++ [ "-X main.${name}=${value}" ] - ) [ "-s -w" ] { hmain = "${hakurei}/libexec/hakurei"; }; + ) [ "-s -w" ] { hakureiPath = "${hakurei}/libexec/hakurei"; }; } diff --git a/cmd/hsu/path.go b/cmd/hsu/path.go deleted file mode 100644 index 53aa9d10..00000000 --- a/cmd/hsu/path.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "log" - "path" -) - -const compPoison = "INVALIDINVALIDINVALIDINVALIDINVALID" - -var ( - hmain = compPoison -) - -func mustCheckPath(p string) string { - if p != compPoison && p != "" && path.IsAbs(p) { - return p - } - log.Fatal("this program is compiled incorrectly") - return compPoison -} |
