diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-10-23 21:46:21 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-10-23 21:46:21 +0900 |
| commit | 6bc5be7e5a2334274adf2945ad6d29d063a7086b (patch) | |
| tree | d99223898a282b7ea40c41330b5748a3b5f2b310 /internal/environ.go | |
| parent | e35c5fe3ed995d352c001bd7e35bd1214ca583da (diff) | |
internal: wrap calls to os standard library functions
This change helps tests stub out and simulate OS behaviour during the sealing process. This also removes dependency on XDG_RUNTIME_DIR as the internal.System implementation provided to App provides a compat directory inside the tmpdir-based share when XDG_RUNTIME_DIR is unavailable.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/environ.go')
| -rw-r--r-- | internal/environ.go | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/internal/environ.go b/internal/environ.go deleted file mode 100644 index 8f03cb34..00000000 --- a/internal/environ.go +++ /dev/null @@ -1,58 +0,0 @@ -package internal - -import ( - "os" - "path" - "strconv" - "sync" - - "git.ophivana.moe/security/fortify/internal/fmsg" -) - -// state that remain constant for the lifetime of the process -// fetched and cached here - -const ( - xdgRuntimeDir = "XDG_RUNTIME_DIR" -) - -// SystemConstants contains state from the operating system -type SystemConstants struct { - // path to shared directory e.g. /tmp/fortify.%d - SharePath string `json:"share_path"` - // XDG_RUNTIME_DIR value e.g. /run/user/%d - RuntimePath string `json:"runtime_path"` - // application runtime directory e.g. /run/user/%d/fortify - RunDirPath string `json:"run_dir_path"` -} - -var ( - scVal SystemConstants - scOnce sync.Once -) - -func copySC() { - sc := SystemConstants{ - SharePath: path.Join(os.TempDir(), "fortify."+strconv.Itoa(os.Geteuid())), - } - - fmsg.VPrintf("process share directory at %q", sc.SharePath) - - // runtimePath, runDirPath - if r, ok := os.LookupEnv(xdgRuntimeDir); !ok { - fmsg.Println("variable", xdgRuntimeDir, "unset") - os.Exit(1) - } else { - sc.RuntimePath = r - sc.RunDirPath = path.Join(sc.RuntimePath, "fortify") - fmsg.VPrintf("XDG runtime directory at %q", sc.RunDirPath) - } - - scVal = sc -} - -// GetSC returns a populated SystemConstants value -func GetSC() SystemConstants { - scOnce.Do(copySC) - return scVal -} |
