From 7f29b37a32a2214d4f025f31bbf9ab9f86fa3eac Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Wed, 18 Dec 2024 17:20:01 +0900 Subject: [PATCH] proc: setup payload send Generic setup payload encoder adapted from fshim. Signed-off-by: Ophestra Umiker --- internal/proc/fd.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/proc/fd.go b/internal/proc/fd.go index 1d63427..5400abe 100644 --- a/internal/proc/fd.go +++ b/internal/proc/fd.go @@ -12,6 +12,16 @@ var ( ErrInvalid = errors.New("bad file descriptor") ) +func Setup(extraFiles *[]*os.File) (int, *gob.Encoder, error) { + if r, w, err := os.Pipe(); err != nil { + return -1, nil, err + } else { + fd := 3 + len(*extraFiles) + *extraFiles = append(*extraFiles, r) + return fd, gob.NewEncoder(w), nil + } +} + func Receive(key string, e any) (func() error, error) { var setup *os.File