aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/proc
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-17 02:48:32 +0900
committerOphestra <cat@gensokyo.uk>2025-03-17 02:48:32 +0900
commit9ce4706a0766880c072cccd2643d66f614a6a16b (patch)
tree075e4cf906065ca9c3eb6bacb6820b5786b6d496 /helper/proc
parent9a1f8e129fe0f9919981b8a1d345a9b455bd76de (diff)
sandbox: move params setup functions
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'helper/proc')
-rw-r--r--helper/proc/fd.go48
1 files changed, 0 insertions, 48 deletions
diff --git a/helper/proc/fd.go b/helper/proc/fd.go
deleted file mode 100644
index abf8f36a..00000000
--- a/helper/proc/fd.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package proc
-
-import (
- "encoding/gob"
- "errors"
- "os"
- "strconv"
-)
-
-var (
- ErrNotSet = errors.New("environment variable not set")
- ErrInvalid = errors.New("bad file descriptor")
-)
-
-// Setup appends the read end of a pipe for payload transmission and returns its fd.
-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
- }
-}
-
-// Receive retrieves payload pipe fd from the environment,
-// receives its payload and returns the Close method of the pipe.
-func Receive(key string, e any, v **os.File) (func() error, error) {
- var setup *os.File
-
- if s, ok := os.LookupEnv(key); !ok {
- return nil, ErrNotSet
- } else {
- if fd, err := strconv.Atoi(s); err != nil {
- return nil, err
- } else {
- setup = os.NewFile(uintptr(fd), "setup")
- if setup == nil {
- return nil, ErrInvalid
- }
- if v != nil {
- *v = setup
- }
- }
- }
-
- return setup.Close, gob.NewDecoder(setup).Decode(e)
-}