@@ -43,9 +43,8 @@ func getDefaultImagePath() string {
4343 return filepath .Join (cwd , "checkpoint" )
4444}
4545
46- // newProcess returns a new libcontainer Process with the arguments from the
47- // spec and stdio from the current process.
48- func newProcess (p specs.Process ) (* libcontainer.Process , error ) {
46+ // newProcess converts [specs.Process] to [libcontainer.Process].
47+ func newProcess (p * specs.Process ) (* libcontainer.Process , error ) {
4948 lp := & libcontainer.Process {
5049 Args : p .Args ,
5150 Env : p .Env ,
@@ -89,7 +88,7 @@ func newProcess(p specs.Process) (*libcontainer.Process, error) {
8988}
9089
9190// setupIO modifies the given process config according to the options.
92- func setupIO (process * libcontainer.Process , rootuid , rootgid int , createTTY , detach bool , sockpath string ) (* tty , error ) {
91+ func setupIO (process * libcontainer.Process , container * libcontainer. Container , createTTY , detach bool , sockpath string ) (* tty , error ) {
9392 if createTTY {
9493 process .Stdin = nil
9594 process .Stdout = nil
@@ -135,6 +134,17 @@ func setupIO(process *libcontainer.Process, rootuid, rootgid int, createTTY, det
135134 inheritStdio (process )
136135 return & tty {}, nil
137136 }
137+
138+ config := container .Config ()
139+ rootuid , err := config .HostRootUID ()
140+ if err != nil {
141+ return nil , err
142+ }
143+ rootgid , err := config .HostRootGID ()
144+ if err != nil {
145+ return nil , err
146+ }
147+
138148 return setupProcessPipes (process , rootuid , rootgid )
139149}
140150
@@ -210,7 +220,7 @@ func (r *runner) run(config *specs.Process) (int, error) {
210220 if err = r .checkTerminal (config ); err != nil {
211221 return - 1 , err
212222 }
213- process , err := newProcess (* config )
223+ process , err := newProcess (config )
214224 if err != nil {
215225 return - 1 , err
216226 }
@@ -232,20 +242,12 @@ func (r *runner) run(config *specs.Process) (int, error) {
232242 }
233243 process .ExtraFiles = append (process .ExtraFiles , os .NewFile (uintptr (i ), "PreserveFD:" + strconv .Itoa (i )))
234244 }
235- rootuid , err := r .container .Config ().HostRootUID ()
236- if err != nil {
237- return - 1 , err
238- }
239- rootgid , err := r .container .Config ().HostRootGID ()
240- if err != nil {
241- return - 1 , err
242- }
243245 detach := r .detach || (r .action == CT_ACT_CREATE )
244246 // Setting up IO is a two stage process. We need to modify process to deal
245247 // with detaching containers, and then we get a tty after the container has
246248 // started.
247249 handler := newSignalHandler (r .enableSubreaper , r .notifySocket )
248- tty , err := setupIO (process , rootuid , rootgid , config .Terminal , detach , r .consoleSocket )
250+ tty , err := setupIO (process , r . container , config .Terminal , detach , r .consoleSocket )
249251 if err != nil {
250252 return - 1 , err
251253 }
0 commit comments