// createFDMap creates an FD map that contains stdin, stdout, and stderr. If
// console is true, then ioctl calls will be passed through to the host FD.
// Upon success, createFDMap dups then closes stdioFDs.
createFDMap creates an FD map that contains stdin, stdout, and stderr. If
console is true, then ioctl calls will be passed through to the host FD.
Upon success, createFDMap dups then closes stdioFDs.
// createFDMap creates an FD map that contains stdin stdout and stderr . If // console is true then ioctl calls will be passed through to the host FD . // Upon success createFDMap dups then closes stdioFDs .
func createFDMap(ctx context.Context, l *limits.LimitSet, console bool, stdioFDs []int) (*kernel.FDMap, error) {
	if len(stdioFDs) != 3 {
		return nil, fmt.Errorf("stdioFDs should contain exactly 3 FDs (stdin, stdout, and stderr), but %d FDs received", len(stdioFDs))
	}
	k := kernel.KernelFromContext(ctx)
	fdm := k.NewFDMap()
	defer fdm.DecRef()
	mounter := fs.FileOwnerFromContext(ctx)
	fdMap := map[int]int{
		0: stdioFDs[0],
		1: stdioFDs[1],
		2: stdioFDs[2],
	}
	var ttyFile *fs.File
	for appFD, hostFD := range fdMap {
		var appFile *fs.File
		if console && appFD < 3 {
			if ttyFile == nil {
				var err error
				appFile, err = host.ImportFile(ctx, hostFD, mounter, true )
				if err != nil {
					return nil, err
				}
				defer appFile.DecRef()
				ttyFile = appFile
			} else {
				appFile = ttyFile
			}
		} else {
			var err error
			appFile, err = host.ImportFile(ctx, hostFD, mounter, false )
			if err != nil {
				return nil, err
			}
			defer appFile.DecRef()
		}
		if err := fdm.NewFDAt(kdefs.FD(appFD), appFile, kernel.FDFlags{}, l); err != nil {
			return nil, err
		}
	}
	fdm.IncRef()
	return fdm, nil
}
func createFDMap ( ctx context . Context , l * limits . LimitSet , console bool , stdioFDs [ ] int ) ( * kernel . FDMap , error ) { if len ( stdioFDs ) != 3 { return nil , fmt . Errorf ( " " , len ( stdioFDs ) ) } k := kernel . KernelFromContext ( ctx ) fdm := k . NewFDMap ( ) defer fdm . DecRef ( ) mounter := fs . FileOwnerFromContext ( ctx ) fdMap := map [ int ] int { 0 : stdioFDs [ 0 ] , 1 : stdioFDs [ 1 ] , 2 : stdioFDs [ 2 ] , } var ttyFile * fs . File for appFD , hostFD := range fdMap { var appFile * fs . File if console && appFD < 3 { if ttyFile == nil { var err error appFile , err = host . ImportFile ( ctx , hostFD , mounter , true ) if err != nil { return nil , err } defer appFile . DecRef ( ) ttyFile = appFile } else { appFile = ttyFile } } else { var err error appFile , err = host . ImportFile ( ctx , hostFD , mounter , false ) if err != nil { return nil , err } defer appFile . DecRef ( ) } if err := fdm . NewFDAt ( kdefs . FD ( appFD ) , appFile , kernel . FDFlags { } , l ) ; err != nil { return nil , err } } fdm . IncRef ( ) return fdm , nil }
createFDMap creates an FD map that contains stdin, stdout, and stderr.
createFDMap creates an FD map that contains stdin stdout and stderr .
// Maps sandbox FD to host FD. // Import the file as a host TTY file. /* isTTY */ // Remember this in the TTY file, as we will // use it for the other stdio FDs. // Re-use the existing TTY file, as all three // stdio FDs must point to the same fs.File in // order to share TTY state, specifically the // foreground process group id. // Import the file as a regular host file. /* isTTY */ // Add the file to the FD map.