mirror of
https://github.com/clearlinux/docker.git
synced 2026-06-16 02:35:49 +00:00
e45d0eb532
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com> Signed-off-by: James Hunt <james.o.hunt@intel.com> Signed-off-by: Michael Doherty <michael.i.doherty@intel.com>
52 lines
720 B
Go
52 lines
720 B
Go
// +build linux
|
|
|
|
package clr
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
ErrCannotParse = errors.New("cannot parse raw input")
|
|
)
|
|
|
|
type clrInfo struct {
|
|
Running bool
|
|
Pid int
|
|
}
|
|
|
|
func parseClrInfo(name, raw string) (*clrInfo, error) {
|
|
if raw == "" {
|
|
return nil, ErrCannotParse
|
|
}
|
|
var (
|
|
err error
|
|
info = &clrInfo{}
|
|
)
|
|
|
|
fields := strings.Fields(strings.TrimSpace(raw))
|
|
|
|
// The format is expected to be:
|
|
//
|
|
// <pid> <name> <state>
|
|
//
|
|
if len(fields) != 3 {
|
|
return nil, ErrCannotParse
|
|
}
|
|
|
|
info.Pid, err = strconv.Atoi(fields[0])
|
|
if err != nil {
|
|
return nil, ErrCannotParse
|
|
}
|
|
|
|
if fields[1] != name {
|
|
return nil, ErrCannotParse
|
|
}
|
|
|
|
info.Running = fields[2] == "running"
|
|
|
|
return info, nil
|
|
}
|