281df74045
- https://github.com/containerd/go-runc/compare/ed1cbe1fc31f5fb2359d3a54b6330d1a097858b7...4f6e87ae043f859a38255247b49c9abc262d002f - https://github.com/containerd/cgroups/compare/29da22c6171a4316169f9205ab6c49f59b5b852f...c0710c92e8b3a44681d1321dcfd1360fc5c6c089 - runc (already ahead) - https://github.com/stevvooe/ttrpc/compare/76e68349ad9ab4d03d764c713826d31216715e4f...d4528379866b0ce7e9d71f3eb96f0582fc374577 Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 175cfdcfb521aa83f6a1441b0a4b99cb159f058d Component: engine
46 lines
906 B
Go
46 lines
906 B
Go
package runc
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"strconv"
|
|
"sync"
|
|
"syscall"
|
|
)
|
|
|
|
// ReadPidFile reads the pid file at the provided path and returns
|
|
// the pid or an error if the read and conversion is unsuccessful
|
|
func ReadPidFile(path string) (int, error) {
|
|
data, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
return strconv.Atoi(string(data))
|
|
}
|
|
|
|
const exitSignalOffset = 128
|
|
|
|
// exitStatus returns the correct exit status for a process based on if it
|
|
// was signaled or exited cleanly
|
|
func exitStatus(status syscall.WaitStatus) int {
|
|
if status.Signaled() {
|
|
return exitSignalOffset + int(status.Signal())
|
|
}
|
|
return status.ExitStatus()
|
|
}
|
|
|
|
var bytesBufferPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return bytes.NewBuffer(nil)
|
|
},
|
|
}
|
|
|
|
func getBuf() *bytes.Buffer {
|
|
return bytesBufferPool.Get().(*bytes.Buffer)
|
|
}
|
|
|
|
func putBuf(b *bytes.Buffer) {
|
|
b.Reset()
|
|
bytesBufferPool.Put(b)
|
|
}
|