MCPcopy
hub / github.com/google/gvisor / createFDTable

Function createFDTable

runsc/boot/loader.go:2006–2040  ·  view source on GitHub ↗
(ctx context.Context, console bool, stdioFDs []*fd.FD, passFDs []fdMapping, user specs.User, containerName string)

Source from the content-addressed store, hash-verified

2004}
2005
2006func createFDTable(ctx context.Context, console bool, stdioFDs []*fd.FD, passFDs []fdMapping, user specs.User, containerName string) (*kernel.FDTable, *host.TTYFileDescription, error) {
2007 if len(stdioFDs) != 3 {
2008 return nil, nil, fmt.Errorf("stdioFDs should contain exactly 3 FDs (stdin, stdout, and stderr), but %d FDs received", len(stdioFDs))
2009 }
2010 fdMap := map[int]*fd.FD{
2011 0: stdioFDs[0],
2012 1: stdioFDs[1],
2013 2: stdioFDs[2],
2014 }
2015
2016 // Create the entries for the host files that were passed to our app.
2017 for _, customFD := range passFDs {
2018 if customFD.guest < 0 {
2019 return nil, nil, fmt.Errorf("guest file descriptors must be 0 or greater")
2020 }
2021 fdMap[customFD.guest] = customFD.host
2022 }
2023
2024 k := kernel.KernelFromContext(ctx)
2025 fdTable := k.NewFDTable()
2026 opts := fdimport.ImportOptions{
2027 Console: console,
2028 Restorable: true,
2029 UID: auth.KUID(user.UID),
2030 GID: auth.KGID(user.GID),
2031 ContainerName: containerName,
2032 SupportTTYs: true,
2033 }
2034 ttyFile, err := fdimport.Import(ctx, fdTable, fdMap, opts)
2035 if err != nil {
2036 fdTable.DecRef(ctx)
2037 return nil, nil, err
2038 }
2039 return fdTable, ttyFile, nil
2040}
2041
2042// portForward implements initiating a portForward connection in the sandbox. portForwardProxies
2043// represent a two connections each copying to each other (read ends to write ends) in goroutines.

Callers 1

Calls 7

DecRefMethod · 0.95
KernelFromContextFunction · 0.92
KUIDTypeAlias · 0.92
KGIDTypeAlias · 0.92
ImportFunction · 0.92
NewFDTableMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…