mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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 <rodrigoca@microsoft.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user