@@ -36,7 +36,7 @@ type Process interface {
3636 ExitFD () int
3737 // ExitStatus returns the exit status of the process or an error if it
3838 // has not exited
39- ExitStatus () (int , error )
39+ ExitStatus () (uint32 , error )
4040 // Spec returns the process spec that created the process
4141 Spec () specs.ProcessSpec
4242 // Signal sends the provided signal to the process
@@ -228,31 +228,31 @@ func (p *process) Resize(w, h int) error {
228228 return err
229229}
230230
231- func (p * process ) updateExitStatusFile (status int ) (int , error ) {
231+ func (p * process ) updateExitStatusFile (status uint32 ) (uint32 , error ) {
232232 p .stateLock .Lock ()
233233 p .state = Stopped
234234 p .stateLock .Unlock ()
235- err := ioutil .WriteFile (filepath .Join (p .root , ExitStatusFile ), []byte (fmt .Sprintf ("%d " , status )), 0644 )
235+ err := ioutil .WriteFile (filepath .Join (p .root , ExitStatusFile ), []byte (fmt .Sprintf ("%u " , status )), 0644 )
236236 return status , err
237237}
238238
239- func (p * process ) handleSigkilledShim (rst int , rerr error ) (int , error ) {
239+ func (p * process ) handleSigkilledShim (rst uint32 , rerr error ) (uint32 , error ) {
240240 if p .cmd == nil || p .cmd .Process == nil {
241241 e := unix .Kill (p .pid , 0 )
242242 if e == syscall .ESRCH {
243243 logrus .Warnf ("containerd: %s:%s (pid %d) does not exist" , p .container .id , p .id , p .pid )
244244 // The process died while containerd was down (probably of
245245 // SIGKILL, but no way to be sure)
246- return p .updateExitStatusFile (255 )
246+ return p .updateExitStatusFile (UnknownStatus )
247247 }
248248
249249 // If it's not the same process, just mark it stopped and set
250- // the status to 255
250+ // the status to the UnknownStatus value (i.e. 255)
251251 if same , err := p .isSameProcess (); ! same {
252252 logrus .Warnf ("containerd: %s:%s (pid %d) is not the same process anymore (%v)" , p .container .id , p .id , p .pid , err )
253253 // Create the file so we get the exit event generated once monitor kicks in
254254 // without having to go through all this process again
255- return p .updateExitStatusFile (255 )
255+ return p .updateExitStatusFile (UnknownStatus )
256256 }
257257
258258 ppid , err := readProcStatField (p .pid , 4 )
@@ -263,7 +263,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
263263 logrus .Warnf ("containerd: %s:%s shim died, killing associated process" , p .container .id , p .id )
264264 unix .Kill (p .pid , syscall .SIGKILL )
265265 if err != nil && err != syscall .ESRCH {
266- return 255 , fmt .Errorf ("containerd: unable to SIGKILL %s:%s (pid %v): %v" , p .container .id , p .id , p .pid , err )
266+ return UnknownStatus , fmt .Errorf ("containerd: unable to SIGKILL %s:%s (pid %v): %v" , p .container .id , p .id , p .pid , err )
267267 }
268268
269269 // wait for the process to die
@@ -276,7 +276,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
276276 }
277277 // Create the file so we get the exit event generated once monitor kicks in
278278 // without having to go through all this process again
279- return p .updateExitStatusFile (128 + int (syscall .SIGKILL ))
279+ return p .updateExitStatusFile (128 + uint32 (syscall .SIGKILL ))
280280 }
281281
282282 return rst , rerr
@@ -296,7 +296,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
296296 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 )
297297
298298 rerr = nil
299- rst = 128 + int (shimStatus .Signal ())
299+ rst = 128 + uint32 (shimStatus .Signal ())
300300
301301 p .stateLock .Lock ()
302302 p .state = Stopped
@@ -306,7 +306,7 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
306306 return rst , rerr
307307}
308308
309- func (p * process ) ExitStatus () (rst int , rerr error ) {
309+ func (p * process ) ExitStatus () (rst uint32 , rerr error ) {
310310 data , err := ioutil .ReadFile (filepath .Join (p .root , ExitStatusFile ))
311311 defer func () {
312312 if rerr != nil {
@@ -315,17 +315,19 @@ func (p *process) ExitStatus() (rst int, rerr error) {
315315 }()
316316 if err != nil {
317317 if os .IsNotExist (err ) {
318- return - 1 , ErrProcessNotExited
318+ return UnknownStatus , ErrProcessNotExited
319319 }
320- return - 1 , err
320+ return UnknownStatus , err
321321 }
322322 if len (data ) == 0 {
323- return - 1 , ErrProcessNotExited
323+ return UnknownStatus , ErrProcessNotExited
324324 }
325325 p .stateLock .Lock ()
326326 p .state = Stopped
327327 p .stateLock .Unlock ()
328- return strconv .Atoi (string (data ))
328+
329+ i , err := strconv .ParseUint (string (data ), 10 , 32 )
330+ return uint32 (i ), err
329331}
330332
331333func (p * process ) Spec () specs.ProcessSpec {
0 commit comments