Initial commit of libcontainer
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
f8923d8060
commit
81d2c67492
20 changed files with 1531 additions and 0 deletions
33
libcontainer/utils/utils.go
Normal file
33
libcontainer/utils/utils.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue