github.com/runcom/containerd@v0.0.0-20160708090337-9bff9f934c0d/supervisor/exit.go (about) 1 package supervisor 2 3 import ( 4 "time" 5 6 "github.com/Sirupsen/logrus" 7 "github.com/docker/containerd/runtime" 8 ) 9 10 // ExitTask holds needed parameters to execute the exit task 11 type ExitTask struct { 12 baseTask 13 Process runtime.Process 14 } 15 16 func (s *Supervisor) exit(t *ExitTask) error { 17 start := time.Now() 18 proc := t.Process 19 status, err := proc.ExitStatus() 20 if err != nil { 21 logrus.WithFields(logrus.Fields{ 22 "error": err, 23 "pid": proc.ID(), 24 "id": proc.Container().ID(), 25 "systemPid": proc.SystemPid(), 26 }).Error("containerd: get exit status") 27 } 28 logrus.WithFields(logrus.Fields{ 29 "pid": proc.ID(), 30 "status": status, 31 "id": proc.Container().ID(), 32 "systemPid": proc.SystemPid(), 33 }).Debug("containerd: process exited") 34 35 // if the process is the the init process of the container then 36 // fire a separate event for this process 37 if proc.ID() != runtime.InitProcessID { 38 ne := &ExecExitTask{ 39 ID: proc.Container().ID(), 40 PID: proc.ID(), 41 Status: status, 42 Process: proc, 43 } 44 s.SendTask(ne) 45 return nil 46 } 47 container := proc.Container() 48 ne := &DeleteTask{ 49 ID: container.ID(), 50 Status: status, 51 PID: proc.ID(), 52 } 53 s.SendTask(ne) 54 55 ExitProcessTimer.UpdateSince(start) 56 57 return nil 58 } 59 60 // ExecExitTask holds needed parameters to execute the exec exit task 61 type ExecExitTask struct { 62 baseTask 63 ID string 64 PID string 65 Status int 66 Process runtime.Process 67 } 68 69 func (s *Supervisor) execExit(t *ExecExitTask) error { 70 container := t.Process.Container() 71 // exec process: we remove this process without notifying the main event loop 72 if err := container.RemoveProcess(t.PID); err != nil { 73 logrus.WithField("error", err).Error("containerd: find container for pid") 74 } 75 s.notifySubscribers(Event{ 76 Timestamp: time.Now(), 77 ID: t.ID, 78 Type: StateExit, 79 PID: t.PID, 80 Status: t.Status, 81 }) 82 return nil 83 }