@@ -153,15 +153,17 @@ func (o *CreateOpts) args() (out []string, err error) {
153153// Create creates a new container and returns its pid if it was created successfully
154154func (r * Runc ) Create (context context.Context , id , bundle string , opts * CreateOpts ) error {
155155 args := []string {"create" , "--bundle" , bundle }
156- if opts != nil {
157- oargs , err := opts .args ()
158- if err != nil {
159- return err
160- }
161- args = append (args , oargs ... )
156+ if opts == nil {
157+ opts = & CreateOpts {}
162158 }
159+
160+ oargs , err := opts .args ()
161+ if err != nil {
162+ return err
163+ }
164+ args = append (args , oargs ... )
163165 cmd := r .command (context , append (args , id )... )
164- if opts != nil && opts .IO != nil {
166+ if opts .IO != nil {
165167 opts .Set (cmd )
166168 }
167169 cmd .ExtraFiles = opts .ExtraFiles
@@ -178,7 +180,7 @@ func (r *Runc) Create(context context.Context, id, bundle string, opts *CreateOp
178180 if err != nil {
179181 return err
180182 }
181- if opts != nil && opts .IO != nil {
183+ if opts .IO != nil {
182184 if c , ok := opts .IO .(StartCloser ); ok {
183185 if err := c .CloseAfterStart (); err != nil {
184186 return err
@@ -230,6 +232,9 @@ func (o *ExecOpts) args() (out []string, err error) {
230232// Exec executes an additional process inside the container based on a full
231233// OCI Process specification
232234func (r * Runc ) Exec (context context.Context , id string , spec specs.Process , opts * ExecOpts ) error {
235+ if opts == nil {
236+ opts = & ExecOpts {}
237+ }
233238 if opts .Started != nil {
234239 defer close (opts .Started )
235240 }
@@ -244,15 +249,13 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
244249 return err
245250 }
246251 args := []string {"exec" , "--process" , f .Name ()}
247- if opts != nil {
248- oargs , err := opts .args ()
249- if err != nil {
250- return err
251- }
252- args = append (args , oargs ... )
252+ oargs , err := opts .args ()
253+ if err != nil {
254+ return err
253255 }
256+ args = append (args , oargs ... )
254257 cmd := r .command (context , append (args , id )... )
255- if opts != nil && opts .IO != nil {
258+ if opts .IO != nil {
256259 opts .Set (cmd )
257260 }
258261 if cmd .Stdout == nil && cmd .Stderr == nil {
@@ -270,7 +273,7 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
270273 if opts .Started != nil {
271274 opts .Started <- cmd .Process .Pid
272275 }
273- if opts != nil && opts .IO != nil {
276+ if opts .IO != nil {
274277 if c , ok := opts .IO .(StartCloser ); ok {
275278 if err := c .CloseAfterStart (); err != nil {
276279 return err
@@ -287,19 +290,20 @@ func (r *Runc) Exec(context context.Context, id string, spec specs.Process, opts
287290// Run runs the create, start, delete lifecycle of the container
288291// and returns its exit status after it has exited
289292func (r * Runc ) Run (context context.Context , id , bundle string , opts * CreateOpts ) (int , error ) {
293+ if opts == nil {
294+ opts = & CreateOpts {}
295+ }
290296 if opts .Started != nil {
291297 defer close (opts .Started )
292298 }
293299 args := []string {"run" , "--bundle" , bundle }
294- if opts != nil {
295- oargs , err := opts .args ()
296- if err != nil {
297- return - 1 , err
298- }
299- args = append (args , oargs ... )
300+ oargs , err := opts .args ()
301+ if err != nil {
302+ return - 1 , err
300303 }
304+ args = append (args , oargs ... )
301305 cmd := r .command (context , append (args , id )... )
302- if opts != nil && opts .IO != nil {
306+ if opts .IO != nil {
303307 opts .Set (cmd )
304308 }
305309 ec , err := Monitor .Start (cmd )
0 commit comments