1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/libcontainer/utils/utils.go
Michael Crosby e8abaf217b Initial commit of libcontainer
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
2014-02-21 14:56:15 -08:00

33 lines
602 B
Go

package utils
import (
"crypto/rand"
"encoding/hex"
"io"
"os"
"syscall"
)
func WaitOnPid(pid int) (exitcode int, err error) {
child, err := os.FindProcess(pid)
if err != nil {
return -1, err
}
state, err := child.Wait()
if err != nil {
return -1, err
}
return getExitCode(state), nil
}
func getExitCode(state *os.ProcessState) int {
return state.Sys().(syscall.WaitStatus).ExitStatus()
}
func GenerateRandomName(size int) (string, error) {
id := make([]byte, size)
if _, err := io.ReadFull(rand.Reader, id); err != nil {
return "", err
}
return hex.EncodeToString(id), nil
}