@@ -204,28 +204,16 @@ func (c *Container) Set(config configs.Config) error {
204204func (c * Container ) Start (process * Process ) error {
205205 c .m .Lock ()
206206 defer c .m .Unlock ()
207- if c .config .Cgroups .Resources .SkipDevices {
208- return errors .New ("can't start container with SkipDevices set" )
209- }
210- if process .Init {
211- if err := c .createExecFifo (); err != nil {
212- return err
213- }
214- }
215- if err := c .start (process ); err != nil {
216- if process .Init {
217- c .deleteExecFifo ()
218- }
219- return err
220- }
221- return nil
207+ return c .start (process )
222208}
223209
224210// Run immediately starts the process inside the container. Returns an error if
225211// the process fails to start. It does not block waiting for the exec fifo
226212// after start returns but opens the fifo after start returns.
227213func (c * Container ) Run (process * Process ) error {
228- if err := c .Start (process ); err != nil {
214+ c .m .Lock ()
215+ defer c .m .Unlock ()
216+ if err := c .start (process ); err != nil {
229217 return err
230218 }
231219 if process .Init {
@@ -314,6 +302,23 @@ type openResult struct {
314302}
315303
316304func (c * Container ) start (process * Process ) (retErr error ) {
305+ if c .config .Cgroups .Resources .SkipDevices {
306+ return errors .New ("can't start container with SkipDevices set" )
307+ }
308+ if process .Init {
309+ if c .initProcessStartTime != 0 {
310+ return errors .New ("container already has init process" )
311+ }
312+ if err := c .createExecFifo (); err != nil {
313+ return err
314+ }
315+ defer func () {
316+ if retErr != nil {
317+ c .deleteExecFifo ()
318+ }
319+ }()
320+ }
321+
317322 parent , err := c .newParentProcess (process )
318323 if err != nil {
319324 return fmt .Errorf ("unable to create new parent process: %w" , err )
@@ -417,9 +422,6 @@ func (c *Container) createExecFifo() error {
417422 }
418423
419424 fifoName := filepath .Join (c .stateDir , execFifoFilename )
420- if _ , err := os .Stat (fifoName ); err == nil {
421- return fmt .Errorf ("exec fifo %s already exists" , fifoName )
422- }
423425 if err := unix .Mkfifo (fifoName , 0o622 ); err != nil {
424426 return & os.PathError {Op : "mkfifo" , Path : fifoName , Err : err }
425427 }
0 commit comments