setupIO modifies the given process config according to the options.
(process *libcontainer.Process, container *libcontainer.Container, createTTY, detach bool, sockpath string)
| 97 | |
| 98 | // setupIO modifies the given process config according to the options. |
| 99 | func setupIO(process *libcontainer.Process, container *libcontainer.Container, createTTY, detach bool, sockpath string) (_ *tty, Err error) { |
| 100 | if createTTY { |
| 101 | process.Stdin = nil |
| 102 | process.Stdout = nil |
| 103 | process.Stderr = nil |
| 104 | t := &tty{} |
| 105 | if !detach { |
| 106 | if err := t.initHostConsole(); err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | parent, child, err := utils.NewSockPair("console") |
| 110 | if err != nil { |
| 111 | return nil, err |
| 112 | } |
| 113 | process.ConsoleSocket = child |
| 114 | t.postStart = append(t.postStart, parent, child) |
| 115 | t.consoleC = make(chan error, 1) |
| 116 | go func() { |
| 117 | t.consoleC <- t.recvtty(parent) |
| 118 | }() |
| 119 | } else { |
| 120 | // the caller of runc will handle receiving the console master |
| 121 | conn, err := net.Dial("unix", sockpath) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | defer func() { |
| 126 | if Err != nil { |
| 127 | conn.Close() |
| 128 | } |
| 129 | }() |
| 130 | t.postStart = append(t.postStart, conn) |
| 131 | socket, err := conn.(*net.UnixConn).File() |
| 132 | if err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | t.postStart = append(t.postStart, socket) |
| 136 | process.ConsoleSocket = socket |
| 137 | } |
| 138 | return t, nil |
| 139 | } |
| 140 | // when runc will detach the caller provides the stdio to runc via runc's 0,1,2 |
| 141 | // and the container's process inherits runc's stdio. |
| 142 | if detach { |
| 143 | inheritStdio(process) |
| 144 | return &tty{}, nil |
| 145 | } |
| 146 | |
| 147 | config := container.Config() |
| 148 | rootuid, err := config.HostRootUID() |
| 149 | if err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | rootgid, err := config.HostRootGID() |
| 153 | if err != nil { |
| 154 | return nil, err |
| 155 | } |
| 156 |
no test coverage detected
searching dependent graphs…