From 0172016a535e25f6c1052aaa3a8b7a1616b1bf28 Mon Sep 17 00:00:00 2001 From: Rodrigo Campos Date: Mon, 3 Apr 2023 15:49:07 +0200 Subject: [PATCH] libcontainer: Add generic parseFdsFromEnv() We will add code that uses this function in future patches. So let's just split it to a new function now and reuse it later. Signed-off-by: Rodrigo Campos --- libcontainer/factory_linux.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index d10a27810..4cb4a88bf 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -215,17 +215,17 @@ func validateID(id string) error { return nil } -func parseMountFds() ([]int, error) { - fdsJSON := os.Getenv("_LIBCONTAINER_MOUNT_FDS") +func parseFdsFromEnv(envVar string) ([]int, error) { + fdsJSON := os.Getenv(envVar) if fdsJSON == "" { // Always return the nil slice if no fd is present. return nil, nil } - var mountFds []int - if err := json.Unmarshal([]byte(fdsJSON), &mountFds); err != nil { - return nil, fmt.Errorf("Error unmarshalling _LIBCONTAINER_MOUNT_FDS: %w", err) + var fds []int + if err := json.Unmarshal([]byte(fdsJSON), &fds); err != nil { + return nil, fmt.Errorf("Error unmarshalling %v: %w", envVar, err) } - return mountFds, nil + return fds, nil }