File tree Expand file tree Collapse file tree 1 file changed +29
-17
lines changed
Expand file tree Collapse file tree 1 file changed +29
-17
lines changed Original file line number Diff line number Diff line change @@ -212,21 +212,46 @@ func (c *Container) Start(process *Process) error {
212212// after start returns but opens the fifo after start returns.
213213func (c * Container ) Run (process * Process ) error {
214214 c .m .Lock ()
215- defer c .m .Unlock ()
216215 if err := c .start (process ); err != nil {
216+ c .m .Unlock ()
217217 return err
218218 }
219219 if process .Init {
220- return c .exec ()
220+ err := c .exec ()
221+ if err != nil {
222+ c .m .Unlock ()
223+ return err
224+ }
225+ c .m .Unlock ()
226+ return c .PostStart ()
227+ }
228+ c .m .Unlock ()
229+ return nil
230+ }
231+
232+ func (c * Container ) PostStart () error {
233+ s , err := c .OCIState ()
234+ if err != nil {
235+ return err
236+ }
237+ if c .config .Hooks != nil {
238+ if err := c .config .Hooks .Run (configs .Poststart , s ); err != nil {
239+ return fmt .Errorf ("run poststart hook %w" , err )
240+ }
221241 }
222242 return nil
223243}
224244
225245// Exec signals the container to exec the users process at the end of the init.
226246func (c * Container ) Exec () error {
227247 c .m .Lock ()
228- defer c .m .Unlock ()
229- return c .exec ()
248+ err := c .exec ()
249+ if err != nil {
250+ c .m .Unlock ()
251+ return err
252+ }
253+ c .m .Unlock ()
254+ return c .PostStart ()
230255}
231256
232257func (c * Container ) exec () error {
@@ -353,19 +378,6 @@ func (c *Container) start(process *Process) (retErr error) {
353378
354379 if process .Init {
355380 c .fifo .Close ()
356- if c .config .Hooks != nil {
357- s , err := c .currentOCIState ()
358- if err != nil {
359- return err
360- }
361-
362- if err := c .config .Hooks .Run (configs .Poststart , s ); err != nil {
363- if err := ignoreTerminateErrors (parent .terminate ()); err != nil {
364- logrus .Warn (fmt .Errorf ("error running poststart hook: %w" , err ))
365- }
366- return err
367- }
368- }
369381 }
370382 return nil
371383}
You can’t perform that action at this time.
0 commit comments