@@ -32,17 +32,18 @@ func New(stateDir string, runtimeName, shimName string, runtimeArgs []string, ti
3232 return nil , err
3333 }
3434 s := & Supervisor {
35- stateDir : stateDir ,
36- containers : make (map [string ]* containerInfo ),
37- startTasks : startTasks ,
38- machine : machine ,
39- subscribers : make (map [chan Event ]struct {}),
40- tasks : make (chan Task , defaultBufferSize ),
41- monitor : monitor ,
42- runtime : runtimeName ,
43- runtimeArgs : runtimeArgs ,
44- shim : shimName ,
45- timeout : timeout ,
35+ stateDir : stateDir ,
36+ containers : make (map [string ]* containerInfo ),
37+ startTasks : startTasks ,
38+ machine : machine ,
39+ subscribers : make (map [chan Event ]struct {}),
40+ tasks : make (chan Task , defaultBufferSize ),
41+ monitor : monitor ,
42+ runtime : runtimeName ,
43+ runtimeArgs : runtimeArgs ,
44+ shim : shimName ,
45+ timeout : timeout ,
46+ containerExecSync : make (map [string ]map [string ]chan struct {}),
4647 }
4748 if err := setupEventLog (s , retainCount ); err != nil {
4849 return nil , err
@@ -171,6 +172,10 @@ type Supervisor struct {
171172 eventLog []Event
172173 eventLock sync.Mutex
173174 timeout time.Duration
175+ // This is used to ensure that exec process death events are sent
176+ // before the init process death
177+ containerExecSyncLock sync.Mutex
178+ containerExecSync map [string ]map [string ]chan struct {}
174179}
175180
176181// Stop closes all startTasks and sends a SIGTERM to each container's pid1 then waits for they to
@@ -401,3 +406,30 @@ func (s *Supervisor) handleTask(i Task) {
401406 close (i .ErrorCh ())
402407 }
403408}
409+
410+ func (s * Supervisor ) newExecSyncMap (containerID string ) {
411+ s .containerExecSyncLock .Lock ()
412+ s .containerExecSync [containerID ] = make (map [string ]chan struct {})
413+ s .containerExecSyncLock .Unlock ()
414+ }
415+
416+ func (s * Supervisor ) newExecSyncChannel (containerID , pid string ) {
417+ s .containerExecSyncLock .Lock ()
418+ s.containerExecSync [containerID ][pid ] = make (chan struct {})
419+ s .containerExecSyncLock .Unlock ()
420+ }
421+
422+ func (s * Supervisor ) getExecSyncChannel (containerID , pid string ) chan struct {} {
423+ s .containerExecSyncLock .Lock ()
424+ ch := s.containerExecSync [containerID ][pid ]
425+ s .containerExecSyncLock .Unlock ()
426+ return ch
427+ }
428+
429+ func (s * Supervisor ) getDeleteExecSyncMap (containerID string ) map [string ]chan struct {} {
430+ s .containerExecSyncLock .Lock ()
431+ chs := s .containerExecSync [containerID ]
432+ delete (s .containerExecSync , containerID )
433+ s .containerExecSyncLock .Unlock ()
434+ return chs
435+ }
0 commit comments