Add dynamic veth name

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-19 15:54:53 -08:00
parent 8430fbf11e
commit ab6864d0c0
4 changed files with 48 additions and 73 deletions

View file

@ -4,30 +4,12 @@ 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)
func GenerateRandomName(prefix string, size int) (string, error) {
id := make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, id); err != nil {
return "", err
}
return hex.EncodeToString(id), nil
return prefix + hex.EncodeToString(id)[:size], nil
}