Use uint32 as Event's Status type everywhere
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
4eb3147efc
commit
db9aed5a97
6 changed files with 26 additions and 20 deletions
|
@ -36,7 +36,7 @@ type Process interface {
|
||||||
ExitFD() int
|
ExitFD() int
|
||||||
// ExitStatus returns the exit status of the process or an error if it
|
// ExitStatus returns the exit status of the process or an error if it
|
||||||
// has not exited
|
// has not exited
|
||||||
ExitStatus() (int, error)
|
ExitStatus() (uint32, error)
|
||||||
// Spec returns the process spec that created the process
|
// Spec returns the process spec that created the process
|
||||||
Spec() specs.ProcessSpec
|
Spec() specs.ProcessSpec
|
||||||
// Signal sends the provided signal to the process
|
// Signal sends the provided signal to the process
|
||||||
|
@ -228,31 +228,31 @@ func (p *process) Resize(w, h int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) updateExitStatusFile(status int) (int, error) {
|
func (p *process) updateExitStatusFile(status uint32) (uint32, error) {
|
||||||
p.stateLock.Lock()
|
p.stateLock.Lock()
|
||||||
p.state = Stopped
|
p.state = Stopped
|
||||||
p.stateLock.Unlock()
|
p.stateLock.Unlock()
|
||||||
err := ioutil.WriteFile(filepath.Join(p.root, ExitStatusFile), []byte(fmt.Sprintf("%d", status)), 0644)
|
err := ioutil.WriteFile(filepath.Join(p.root, ExitStatusFile), []byte(fmt.Sprintf("%u", status)), 0644)
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
func (p *process) handleSigkilledShim(rst uint32, rerr error) (uint32, error) {
|
||||||
if p.cmd == nil || p.cmd.Process == nil {
|
if p.cmd == nil || p.cmd.Process == nil {
|
||||||
e := unix.Kill(p.pid, 0)
|
e := unix.Kill(p.pid, 0)
|
||||||
if e == syscall.ESRCH {
|
if e == syscall.ESRCH {
|
||||||
logrus.Warnf("containerd: %s:%s (pid %d) does not exist", p.container.id, p.id, p.pid)
|
logrus.Warnf("containerd: %s:%s (pid %d) does not exist", p.container.id, p.id, p.pid)
|
||||||
// The process died while containerd was down (probably of
|
// The process died while containerd was down (probably of
|
||||||
// SIGKILL, but no way to be sure)
|
// SIGKILL, but no way to be sure)
|
||||||
return p.updateExitStatusFile(255)
|
return p.updateExitStatusFile(UnknownStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's not the same process, just mark it stopped and set
|
// If it's not the same process, just mark it stopped and set
|
||||||
// the status to 255
|
// the status to the UnknownStatus value (i.e. 255)
|
||||||
if same, err := p.isSameProcess(); !same {
|
if same, err := p.isSameProcess(); !same {
|
||||||
logrus.Warnf("containerd: %s:%s (pid %d) is not the same process anymore (%v)", p.container.id, p.id, p.pid, err)
|
logrus.Warnf("containerd: %s:%s (pid %d) is not the same process anymore (%v)", p.container.id, p.id, p.pid, err)
|
||||||
// Create the file so we get the exit event generated once monitor kicks in
|
// Create the file so we get the exit event generated once monitor kicks in
|
||||||
// without having to go through all this process again
|
// without having to go through all this process again
|
||||||
return p.updateExitStatusFile(255)
|
return p.updateExitStatusFile(UnknownStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
ppid, err := readProcStatField(p.pid, 4)
|
ppid, err := readProcStatField(p.pid, 4)
|
||||||
|
@ -263,7 +263,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
||||||
logrus.Warnf("containerd: %s:%s shim died, killing associated process", p.container.id, p.id)
|
logrus.Warnf("containerd: %s:%s shim died, killing associated process", p.container.id, p.id)
|
||||||
unix.Kill(p.pid, syscall.SIGKILL)
|
unix.Kill(p.pid, syscall.SIGKILL)
|
||||||
if err != nil && err != syscall.ESRCH {
|
if err != nil && err != syscall.ESRCH {
|
||||||
return 255, fmt.Errorf("containerd: unable to SIGKILL %s:%s (pid %v): %v", p.container.id, p.id, p.pid, err)
|
return UnknownStatus, fmt.Errorf("containerd: unable to SIGKILL %s:%s (pid %v): %v", p.container.id, p.id, p.pid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for the process to die
|
// wait for the process to die
|
||||||
|
@ -276,7 +276,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
||||||
}
|
}
|
||||||
// Create the file so we get the exit event generated once monitor kicks in
|
// Create the file so we get the exit event generated once monitor kicks in
|
||||||
// without having to go through all this process again
|
// without having to go through all this process again
|
||||||
return p.updateExitStatusFile(128 + int(syscall.SIGKILL))
|
return p.updateExitStatusFile(128 + uint32(syscall.SIGKILL))
|
||||||
}
|
}
|
||||||
|
|
||||||
return rst, rerr
|
return rst, rerr
|
||||||
|
@ -296,7 +296,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
||||||
logrus.Debugf("containerd: ExitStatus(container: %s, process: %s): shim was SIGKILL'ed reaping its child with pid %d", p.container.id, p.id, p.pid)
|
logrus.Debugf("containerd: ExitStatus(container: %s, process: %s): shim was SIGKILL'ed reaping its child with pid %d", p.container.id, p.id, p.pid)
|
||||||
|
|
||||||
rerr = nil
|
rerr = nil
|
||||||
rst = 128 + int(shimStatus.Signal())
|
rst = 128 + uint32(shimStatus.Signal())
|
||||||
|
|
||||||
p.stateLock.Lock()
|
p.stateLock.Lock()
|
||||||
p.state = Stopped
|
p.state = Stopped
|
||||||
|
@ -306,7 +306,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
||||||
return rst, rerr
|
return rst, rerr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) ExitStatus() (rst int, rerr error) {
|
func (p *process) ExitStatus() (rst uint32, rerr error) {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(p.root, ExitStatusFile))
|
data, err := ioutil.ReadFile(filepath.Join(p.root, ExitStatusFile))
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
|
@ -315,17 +315,19 @@ func (p *process) ExitStatus() (rst int, rerr error) {
|
||||||
}()
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return -1, ErrProcessNotExited
|
return UnknownStatus, ErrProcessNotExited
|
||||||
}
|
}
|
||||||
return -1, err
|
return UnknownStatus, err
|
||||||
}
|
}
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return -1, ErrProcessNotExited
|
return UnknownStatus, ErrProcessNotExited
|
||||||
}
|
}
|
||||||
p.stateLock.Lock()
|
p.stateLock.Lock()
|
||||||
p.state = Stopped
|
p.state = Stopped
|
||||||
p.stateLock.Unlock()
|
p.stateLock.Unlock()
|
||||||
return strconv.Atoi(string(data))
|
|
||||||
|
i, err := strconv.ParseUint(string(data), 10, 32)
|
||||||
|
return uint32(i), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) Spec() specs.ProcessSpec {
|
func (p *process) Spec() specs.ProcessSpec {
|
||||||
|
|
|
@ -47,6 +47,10 @@ const (
|
||||||
// StartTimeFile holds the name of the file in which the process
|
// StartTimeFile holds the name of the file in which the process
|
||||||
// start time is saved
|
// start time is saved
|
||||||
StartTimeFile = "starttime"
|
StartTimeFile = "starttime"
|
||||||
|
|
||||||
|
// UnknownStatus is the value returned when a process exit
|
||||||
|
// status cannot be determined
|
||||||
|
UnknownStatus = 255
|
||||||
)
|
)
|
||||||
|
|
||||||
// Checkpoint holds information regarding a container checkpoint
|
// Checkpoint holds information regarding a container checkpoint
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
type DeleteTask struct {
|
type DeleteTask struct {
|
||||||
baseTask
|
baseTask
|
||||||
ID string
|
ID string
|
||||||
Status int
|
Status uint32
|
||||||
PID string
|
PID string
|
||||||
NoEvent bool
|
NoEvent bool
|
||||||
Process runtime.Process
|
Process runtime.Process
|
||||||
|
|
|
@ -63,7 +63,7 @@ type ExecExitTask struct {
|
||||||
baseTask
|
baseTask
|
||||||
ID string
|
ID string
|
||||||
PID string
|
PID string
|
||||||
Status int
|
Status uint32
|
||||||
Process runtime.Process
|
Process runtime.Process
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ func (p *testProcess) ExitFD() int {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *testProcess) ExitStatus() (int, error) {
|
func (p *testProcess) ExitStatus() (uint32, error) {
|
||||||
return -1, nil
|
return runtime.UnknownStatus, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *testProcess) Container() runtime.Container {
|
func (p *testProcess) Container() runtime.Container {
|
||||||
|
|
|
@ -186,7 +186,7 @@ type Event struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
PID string `json:"pid,omitempty"`
|
PID string `json:"pid,omitempty"`
|
||||||
Status int `json:"status,omitempty"`
|
Status uint32 `json:"status,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events returns an event channel that external consumers can use to receive updates
|
// Events returns an event channel that external consumers can use to receive updates
|
||||||
|
|
Loading…
Reference in a new issue