(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/config"
"latchd/login"
"latchd/session"
"latchd/tui/bg"
)
@@ -144,39 +145,27 @@ func spawnSession(res *login.Result) error {
return nil
}
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)
if err != nil {
return fmt.Errorf("auth: %w", err)
}
defer creds.CloseSession()
pid, err := syscall.ForkExec("/proc/self/exe", []string{
"latchd-session",
"--user", creds.Username,
"--uid", fmt.Sprintf("%d", creds.UID),
"--gid", fmt.Sprintf("%d", creds.PrimaryGID),
"--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 := creds.OpenSession(); err != nil {
return fmt.Errorf("pam session: %w", err)
}
sess, err := session.Spawn(&res.Env, creds.UID, creds.PrimaryGID, creds.AllGIDs, &res.Config)
if err != nil {
return fmt.Errorf("fork: %w", err)
return fmt.Errorf("spawn: %w", err)
}
creds.OpenSession()
var ws syscall.WaitStatus
if _, err := syscall.Wait4(pid, &ws, 0, nil); err != nil {
return fmt.Errorf("wait: %w", err)
err = sess.Wait()
if err != nil {
log.Printf("session exited: %v", err)
}
log.Printf("session pid %d exited %d", pid, ws.ExitStatus())
log.Printf("session pid %d ended", sess.PID())
return nil
}