Remove OLLIE_ELEVATE_SOCKET from config: derived from XDG_RUNTIME_DIR convention
- Removed from env.go managed list and defaults map - main.go and shell.go derive path from XDG_RUNTIME_DIR directly - main.go sets OLLIE_ELEVATE_SOCKET in process env for subprocesses
This commit is contained in:
parent
38efa3c985
commit
1372a6b55b
|
|
@ -89,14 +89,12 @@ func runServer(sockPath string) {
|
|||
// Server creation deferred until after elevate broker is ready (see below)
|
||||
|
||||
// Start elevation broker
|
||||
elevateSocket := os.Getenv("OLLIE_ELEVATE_SOCKET")
|
||||
if elevateSocket == "" {
|
||||
xdg := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if xdg == "" {
|
||||
xdg = fmt.Sprintf("/run/user/%d", os.Getuid())
|
||||
}
|
||||
elevateSocket = filepath.Join(xdg, "ollie", "elevate.sock")
|
||||
xdg := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if xdg == "" {
|
||||
xdg = fmt.Sprintf("/run/user/%d", os.Getuid())
|
||||
}
|
||||
elevateSocket := filepath.Join(xdg, "ollie", "elevate.sock")
|
||||
os.Setenv("OLLIE_ELEVATE_SOCKET", elevateSocket) //nolint:errcheck
|
||||
policyPath := filepath.Join(paths.DataDir(), "elevate-policy.yaml")
|
||||
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import (
|
|||
// managed is the ordered list of env vars that ollie exposes to frontends.
|
||||
var managed = []string{
|
||||
"OLLIE_CFG_PATH",
|
||||
"OLLIE_ELEVATE_SOCKET",
|
||||
}
|
||||
|
||||
// EnsureDefaults loads ~/.config/ollie/env and sets default values for any
|
||||
|
|
@ -24,13 +23,8 @@ var managed = []string{
|
|||
func EnsureDefaults() {
|
||||
home, _ := os.UserHomeDir()
|
||||
LoadFile(filepath.Join(home, ".config", "ollie", "env"))
|
||||
xdgRuntime := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if xdgRuntime == "" {
|
||||
xdgRuntime = fmt.Sprintf("/run/user/%d", os.Getuid())
|
||||
}
|
||||
defaults := map[string]string{
|
||||
"OLLIE_CFG_PATH": filepath.Join(home, ".config", "ollie"),
|
||||
"OLLIE_ELEVATE_SOCKET": filepath.Join(xdgRuntime, "ollie", "elevate.sock"),
|
||||
"OLLIE_CFG_PATH": filepath.Join(home, ".config", "ollie"),
|
||||
}
|
||||
for k, v := range defaults {
|
||||
if os.Getenv(k) == "" {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ func TestEnsureDefaults(t *testing.T) {
|
|||
os.Unsetenv(k)
|
||||
}
|
||||
EnsureDefaults()
|
||||
for _, k := range []string{"OLLIE_CFG_PATH", "OLLIE_ELEVATE_SOCKET"} {
|
||||
for _, k := range []string{"OLLIE_CFG_PATH"} {
|
||||
if v := os.Getenv(k); v == "" {
|
||||
t.Errorf("%s not set after EnsureDefaults", k)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,14 +125,11 @@ func (e *Server) executeElevatedSudo(ctx context.Context, cmd, dir string, timeo
|
|||
}
|
||||
|
||||
func (e *Server) executeElevatedOpts(ctx context.Context, cmd, dir string, timeout int, sudo bool, doDetach ...bool) (string, error) {
|
||||
sockPath := os.Getenv("OLLIE_ELEVATE_SOCKET")
|
||||
if sockPath == "" {
|
||||
xdg := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if xdg == "" {
|
||||
return "", fmt.Errorf("elevation not available: no XDG_RUNTIME_DIR")
|
||||
}
|
||||
sockPath = filepath.Join(xdg, "ollie", "elevate.sock")
|
||||
xdg := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if xdg == "" {
|
||||
return "", fmt.Errorf("elevation not available: no XDG_RUNTIME_DIR")
|
||||
}
|
||||
sockPath := filepath.Join(xdg, "ollie", "elevate.sock")
|
||||
|
||||
wantDetach := len(doDetach) > 0 && doDetach[0]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue