diff --git a/go/cmd/entrypoint/daemon_util.go b/go/cmd/entrypoint/daemon_util.go index 8323c67..9bb5c2f 100644 --- a/go/cmd/entrypoint/daemon_util.go +++ b/go/cmd/entrypoint/daemon_util.go @@ -66,12 +66,11 @@ func newHTTPServer( ) ( *http.Server, error, ) { - l, err := net.Listen("unix", daemonEnvVars.HTTPSocketPath) + socketPath := daemon.HTTPSocketPath() + l, err := net.Listen("unix", socketPath) if err != nil { return nil, fmt.Errorf( - "failed to listen on socket %q: %w", - daemonEnvVars.HTTPSocketPath, - err, + "failed to listen on socket %q: %w", socketPath, err, ) } diff --git a/go/cmd/entrypoint/sub_cmd.go b/go/cmd/entrypoint/sub_cmd.go index 90b521c..c31dfb5 100644 --- a/go/cmd/entrypoint/sub_cmd.go +++ b/go/cmd/entrypoint/sub_cmd.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "isle/daemon" "isle/daemon/jsonrpc2" "os" "strings" @@ -110,7 +111,7 @@ func (ctx subCmdCtx) doSubCmd(subCmds ...subCmd) error { } daemonRCPClient := jsonrpc2.NewUnixHTTPClient( - daemonEnvVars.HTTPSocketPath, daemonHTTPRPCPath, + daemon.HTTPSocketPath(), daemonHTTPRPCPath, ) err := subCmd.do(subCmdCtx{ diff --git a/go/daemon/env.go b/go/daemon/env.go index 57136c6..6f13651 100644 --- a/go/daemon/env.go +++ b/go/daemon/env.go @@ -13,15 +13,18 @@ import ( "github.com/adrg/xdg" ) +// DEPRECATED +// // EnvVars are variables which are derived based on the environment which the // process is running in. +// +// TODO EnvVars should be private to this package. type EnvVars struct { - RuntimeDirPath string // TODO should be private to this package - StateDirPath string // TODO should be private to this package - HTTPSocketPath string + RuntimeDirPath string + StateDirPath string } -func getRPCSocketDirPath() string { +func getDefaultHTTPSocketDirPath() string { path, err := firstExistingDir( "/run", "/var/run", @@ -29,12 +32,27 @@ func getRPCSocketDirPath() string { "/dev/shm", ) if err != nil { - panic(fmt.Sprintf("Failed to find directory for RPC socket: %v", err)) + panic(fmt.Sprintf("Failed to find directory for HTTP socket: %v", err)) } return path } +// HTTPSocketPath returns the path to the daemon's HTTP socket which is used for +// RPC and other functionality. +var HTTPSocketPath = sync.OnceValue(func() string { + return envOr( + "ISLE_DAEMON_HTTP_SOCKET_PATH", + func() string { + return filepath.Join( + getDefaultHTTPSocketDirPath(), "isle-daemon.sock", + ) + }, + ) +}) + +// DEPRECATED +// // GetEnvVars will return the EnvVars of the current processes, as determined by // the process's environment. var GetEnvVars = sync.OnceValue(func() (v EnvVars) { @@ -51,13 +69,6 @@ var GetEnvVars = sync.OnceValue(func() (v EnvVars) { func() string { return filepath.Join(xdg.StateHome, "isle") }, ) - v.HTTPSocketPath = envOr( - "ISLE_SOCKET_PATH", - func() string { - return filepath.Join(getRPCSocketDirPath(), "isle-daemon.sock") - }, - ) - return }) diff --git a/tests/utils/shared-daemon-env.sh b/tests/utils/shared-daemon-env.sh index d4b8115..ab5b3e6 100644 --- a/tests/utils/shared-daemon-env.sh +++ b/tests/utils/shared-daemon-env.sh @@ -12,6 +12,6 @@ cat <