Some checks failed
Test / Create distribution (push) Successful in 1m21s
Test / Sandbox (push) Successful in 3m21s
Test / ShareFS (push) Successful in 4m30s
Test / Sandbox (race detector) (push) Successful in 5m49s
Test / Hakurei (race detector) (push) Successful in 7m6s
Test / Flake checks (push) Has been cancelled
Test / Hakurei (push) Has been cancelled
The API forces use of finalizer to close the read end of the setup pipe, which is no longer considered acceptable. Exporting this as part of package container also imposes unnecessary maintenance burden. Signed-off-by: Ophestra <cat@gensokyo.uk>
37 lines
698 B
Go
37 lines
698 B
Go
package container
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"errors"
|
|
"os"
|
|
"strconv"
|
|
"syscall"
|
|
)
|
|
|
|
var (
|
|
ErrReceiveEnv = errors.New("environment variable not set")
|
|
)
|
|
|
|
// Receive retrieves setup fd from the environment and receives params.
|
|
func Receive(key string, e any, fdp *uintptr) (func() error, error) {
|
|
var setup *os.File
|
|
|
|
if s, ok := os.LookupEnv(key); !ok {
|
|
return nil, ErrReceiveEnv
|
|
} else {
|
|
if fd, err := strconv.Atoi(s); err != nil {
|
|
return nil, optionalErrorUnwrap(err)
|
|
} else {
|
|
setup = os.NewFile(uintptr(fd), "setup")
|
|
if setup == nil {
|
|
return nil, syscall.EDOM
|
|
}
|
|
if fdp != nil {
|
|
*fdp = setup.Fd()
|
|
}
|
|
}
|
|
}
|
|
|
|
return setup.Close, gob.NewDecoder(setup).Decode(e)
|
|
}
|