Add independent Remote input helper with EOF and watchdog cleanup

This commit is contained in:
ak47 committed 2026-11-05 22:35:40 -05:00
1 parent cd9ae05bbe
commit 21d8904ee3
13 files changed
+1501 -20

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import (
"context"
"errors"
"flag"
"fmt"
"io"
"os"
"os/signal"
"syscall"
"git.stormux.org/storm/cthulhu/internal/platform/xorg"
"git.stormux.org/storm/cthulhu/internal/remoteinput"
)
func main() {
if err := run(); err != nil && !errors.Is(err, context.Canceled) {
// No key names, epoch, native diagnostics or argument/parser excerpts.
fmt.Fprintln(os.Stderr, "Remote input helper failed")
os.Exit(1)
}
}
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 {
return remoteinput.ErrProtocol
}
control, err := remoteinput.AdoptPipe(os.Stdin, false)
if err != nil {
return err
}
defer control.Close()
output, err := remoteinput.AdoptPipe(os.Stdout, true)
if err != nil {
return err
}
defer output.Close()
// Descriptor 3 is a separate, empty lifetime pipe. Its EOF must not wait
// behind control frames buffered before owner death or cancellation.
lifetime, err := remoteinput.AdoptPipe(os.NewFile(3, "remote-input-lifetime"), false)
if err != nil {
return err
}
defer lifetime.Close()
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
return xorg.ServeRemoteKeyHelper(ctx, *epoch, control, lifetime, output)
}