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)
}
+29 -4
View File
@@ -293,14 +293,39 @@ func run(ctx context.Context, arguments []string, stdout, stderr io.Writer) (res
return err
}
// resolvedDestination returns the cleaned absolute path with the parent
// directory (and a final symlink, even a dangling one) resolved, so aliases
// compare equal even when the target does not exist yet. Resolution errors
// fall back to the cleaned absolute path.
func resolvedDestination(path string, depth int) string {
absolute, err := filepath.Abs(path)
if err != nil {
return filepath.Clean(path)
}
directory, err := filepath.EvalSymlinks(filepath.Dir(absolute))
if err != nil {
return absolute
}
resolved := filepath.Join(directory, filepath.Base(absolute))
if depth < 40 {
if info, err := os.Lstat(resolved); err == nil && info.Mode()&os.ModeSymlink != 0 {
if target, err := os.Readlink(resolved); err == nil {
if !filepath.IsAbs(target) {
target = filepath.Join(directory, target)
}
return resolvedDestination(target, depth+1)
}
}
}
return resolved
}
// sameDestination reports whether two sink paths name the same file, via
// cleaned absolute paths or, when both exist, file identity (symlink and
// resolved absolute paths or, when both exist, file identity (symlink and
// ./ aliases). Sharing one file between the NDJSON and DuckDB sinks would
// corrupt both.
func sameDestination(a, b string) bool {
absA, errA := filepath.Abs(a)
absB, errB := filepath.Abs(b)
if errA == nil && errB == nil && absA == absB {
if resolvedDestination(a, 0) == resolvedDestination(b, 0) {
return true
}
infoA, errA := os.Stat(a)
+13 -1
View File
@@ -311,11 +311,23 @@ func TestAppendRequiresDebugSink(t *testing.T) {
}
func TestDebugFileAndDBSameFileRejected(t *testing.T) {
shared := filepath.Join(t.TempDir(), "debug.out")
directory := t.TempDir()
shared := filepath.Join(directory, "debug.out")
alias := filepath.Dir(shared) + string(filepath.Separator) + "." + string(filepath.Separator) + "debug.out"
// A dangling symlink and a symlinked parent must alias the absent target.
dangling := filepath.Join(directory, "debug-link")
if err := os.Symlink(shared, dangling); err != nil {
t.Fatal(err)
}
linkedDirectory := filepath.Join(directory, "linked")
if err := os.Symlink(directory, linkedDirectory); err != nil {
t.Fatal(err)
}
for _, arguments := range [][]string{
{"--debug-file", shared, "--debug-db", shared},
{"--debug-file", shared, "--debug-db", alias},
{"--debug-file", dangling, "--debug-db", shared},
{"--debug-file", filepath.Join(linkedDirectory, "debug.out"), "--debug-db", shared},
} {
var output bytes.Buffer
err := run(context.Background(), arguments, &output, &output)