Agent review pass.

This commit is contained in:
hjozwiak committed 2026-11-24 11:12:17 -05:00
1 parent e9b2e9508b
commit 64ee749a8e
105 files changed
+2098 -320

No files matched your search

+20 -7
View File
@@ -7,12 +7,11 @@ package main
import (
"context"
"errors"
"flag"
"fmt"
"io"
"os"
"os/signal"
"syscall"
"time"
"git.stormux.org/storm/cthulhu/internal/platform/xorg"
"git.stormux.org/storm/cthulhu/internal/remoteinput"
@@ -27,10 +26,10 @@ func main() {
}
func run() error {
flags := flag.NewFlagSet("cthulhu-input-helper", flag.ContinueOnError)
flags.SetOutput(io.Discard)
epoch := flags.Uint64("epoch", 0, "private input epoch")
if flags.Parse(os.Args[1:]) != nil || flags.NArg() != 0 || *epoch == 0 {
// The helper takes no arguments: the lease epoch arrives as the
// first frame over the private control pipe, never in argv where
// /proc/<pid>/cmdline would expose it to every local process.
if len(os.Args) != 1 {
return remoteinput.ErrProtocol
}
control, err := remoteinput.AdoptPipe(os.Stdin, false)
@@ -50,7 +49,21 @@ func run() error {
return err
}
defer lifetime.Close()
// Consume the epoch before installing signal handling or opening
// any native target: until then no keys can be held, so a signal
// may simply terminate the process, and a missing or malformed
// Hello fails within one watchdog instead of blocking forever.
if err := control.SetReadDeadline(time.Now().Add(remoteinput.Watchdog)); err != nil {
return remoteinput.ErrProtocol
}
epoch, err := remoteinput.ReadEpoch(control)
if err != nil {
return err
}
if err := control.SetReadDeadline(time.Time{}); err != nil {
return remoteinput.ErrProtocol
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
return xorg.ServeRemoteKeyHelper(ctx, *epoch, control, lifetime, output)
return xorg.ServeRemoteKeyHelper(ctx, epoch, control, lifetime, output)
}