(Fix): replaced the broken ForkExec (which relaunched the same binary with made-up flags) with a direct session.Spawn call that drops privileges and runs the desktop in-process.

This commit is contained in:
2026-07-18 21:41:27 +05:30
parent 37a9ea0278
commit 863ed82298

View File

@@ -19,6 +19,7 @@ import (
"latchd/auth" "latchd/auth"
"latchd/config" "latchd/config"
"latchd/login" "latchd/login"
"latchd/session"
"latchd/tui/bg" "latchd/tui/bg"
) )
@@ -144,39 +145,27 @@ func spawnSession(res *login.Result) error {
return nil return nil
} }
log.Printf("spawning %s → %s (%s)", res.Username, res.Env.Title, res.Env.Kind) log.Printf("spawning %s → %s (%s)", res.Username, res.Env.Title, res.Env.Kind)
creds, err := auth.Validate(res.Username, res.Password, res.Config.PAMService) creds, err := auth.Validate(res.Username, res.Password, res.Config.PAMService)
if err != nil { if err != nil {
return fmt.Errorf("auth: %w", err) return fmt.Errorf("auth: %w", err)
} }
defer creds.CloseSession() defer creds.CloseSession()
pid, err := syscall.ForkExec("/proc/self/exe", []string{ if err := creds.OpenSession(); err != nil {
"latchd-session", return fmt.Errorf("pam session: %w", err)
"--user", creds.Username, }
"--uid", fmt.Sprintf("%d", creds.UID),
"--gid", fmt.Sprintf("%d", creds.PrimaryGID), sess, err := session.Spawn(&res.Env, creds.UID, creds.PrimaryGID, creds.AllGIDs, &res.Config)
"--home", creds.HomeDir,
"--shell", creds.Shell,
"--env-kind", res.Env.Kind,
"--env-exec", res.Env.XinitrcPath,
"--tty", fmt.Sprintf("%d", res.Config.TTY),
}, &syscall.ProcAttr{
Env: os.Environ(),
Dir: creds.HomeDir,
Files: []uintptr{0, 1, 2},
Sys: &syscall.SysProcAttr{Setsid: true},
})
if err != nil { if err != nil {
return fmt.Errorf("fork: %w", err) return fmt.Errorf("spawn: %w", err)
} }
creds.OpenSession() err = sess.Wait()
if err != nil {
var ws syscall.WaitStatus log.Printf("session exited: %v", err)
if _, err := syscall.Wait4(pid, &ws, 0, nil); err != nil {
return fmt.Errorf("wait: %w", err)
} }
log.Printf("session pid %d exited %d", pid, ws.ExitStatus()) log.Printf("session pid %d ended", sess.PID())
return nil return nil
} }