Skip to content

Commit

Permalink
libcontainer: Replace GetProcessStartTime with Stat_t.StartTime
Browse files Browse the repository at this point in the history
And convert the various start-time properties from strings to uint64s.
This removes all internal consumers of the deprecated
GetProcessStartTime function.

Signed-off-by: W. Trevor King <[email protected]>
  • Loading branch information
wking committed Jun 14, 2017
1 parent 439eaa3 commit abd39d1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion libcontainer/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type BaseState struct {
InitProcessPid int `json:"init_process_pid"`

// InitProcessStartTime is the init process start time in clock cycles since boot time.
InitProcessStartTime string `json:"init_process_start"`
InitProcessStartTime uint64 `json:"init_process_start"`

// Created is the unix timestamp for the creation time of the container in UTC
Created time.Time `json:"created"`
Expand Down
10 changes: 5 additions & 5 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type linuxContainer struct {
cgroupManager cgroups.Manager
initArgs []string
initProcess parentProcess
initProcessStartTime string
initProcessStartTime uint64
criuPath string
m sync.Mutex
criuVersion int
Expand Down Expand Up @@ -1370,11 +1370,11 @@ func (c *linuxContainer) refreshState() error {
// and a new process has been created with the same pid, in this case, the
// container would already be stopped.
func (c *linuxContainer) doesInitProcessExist(initPid int) (bool, error) {
startTime, err := system.GetProcessStartTime(initPid)
stat, err := system.Stat(initPid)
if err != nil {
return false, newSystemErrorWithCausef(err, "getting init process %d start time", initPid)
return false, newSystemErrorWithCausef(err, "getting init process %d status", initPid)
}
if c.initProcessStartTime != startTime {
if c.initProcessStartTime != stat.StartTime {
return false, nil
}
return true, nil
Expand Down Expand Up @@ -1427,7 +1427,7 @@ func (c *linuxContainer) isPaused() (bool, error) {

func (c *linuxContainer) currentState() (*State, error) {
var (
startTime string
startTime uint64
externalDescriptors []string
pid = -1
)
Expand Down
10 changes: 5 additions & 5 deletions libcontainer/container_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (m *mockCgroupManager) Freeze(state configs.FreezerState) error {

type mockProcess struct {
_pid int
started string
started uint64
}

func (m *mockProcess) terminate() error {
Expand All @@ -63,7 +63,7 @@ func (m *mockProcess) pid() int {
return m._pid
}

func (m *mockProcess) startTime() (string, error) {
func (m *mockProcess) startTime() (uint64, error) {
return m.started, nil
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func TestGetContainerState(t *testing.T) {
},
initProcess: &mockProcess{
_pid: pid,
started: "010",
started: 10,
},
cgroupManager: &mockCgroupManager{
pids: []int{1, 2, 3},
Expand All @@ -174,8 +174,8 @@ func TestGetContainerState(t *testing.T) {
if state.InitProcessPid != pid {
t.Fatalf("expected pid %d but received %d", pid, state.InitProcessPid)
}
if state.InitProcessStartTime != "010" {
t.Fatalf("expected process start time 010 but received %s", state.InitProcessStartTime)
if state.InitProcessStartTime != 10 {
t.Fatalf("expected process start time 10 but received %ds", state.InitProcessStartTime)
}
paths := state.CgroupPaths
if paths == nil {
Expand Down
12 changes: 7 additions & 5 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type parentProcess interface {
wait() (*os.ProcessState, error)

// startTime returns the process start time.
startTime() (string, error)
startTime() (uint64, error)

signal(os.Signal) error

Expand All @@ -55,8 +55,9 @@ type setnsProcess struct {
bootstrapData io.Reader
}

func (p *setnsProcess) startTime() (string, error) {
return system.GetProcessStartTime(p.pid())
func (p *setnsProcess) startTime() (uint64, error) {
stat, err := system.Stat(p.pid())
return stat.StartTime, err
}

func (p *setnsProcess) signal(sig os.Signal) error {
Expand Down Expand Up @@ -384,8 +385,9 @@ func (p *initProcess) terminate() error {
return err
}

func (p *initProcess) startTime() (string, error) {
return system.GetProcessStartTime(p.pid())
func (p *initProcess) startTime() (uint64, error) {
stat, err := system.Stat(p.pid())
return stat.StartTime, err
}

func (p *initProcess) sendConfig() error {
Expand Down
12 changes: 6 additions & 6 deletions libcontainer/restored_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ func newRestoredProcess(pid int, fds []string) (*restoredProcess, error) {
if err != nil {
return nil, err
}
started, err := system.GetProcessStartTime(pid)
stat, err := system.Stat(pid)
if err != nil {
return nil, err
}
return &restoredProcess{
proc: proc,
processStartTime: started,
processStartTime: stat.StartTime,
fds: fds,
}, nil
}

type restoredProcess struct {
proc *os.Process
processStartTime string
processStartTime uint64
fds []string
}

Expand Down Expand Up @@ -60,7 +60,7 @@ func (p *restoredProcess) wait() (*os.ProcessState, error) {
return st, nil
}

func (p *restoredProcess) startTime() (string, error) {
func (p *restoredProcess) startTime() (uint64, error) {
return p.processStartTime, nil
}

Expand All @@ -81,7 +81,7 @@ func (p *restoredProcess) setExternalDescriptors(newFds []string) {
// a persisted state.
type nonChildProcess struct {
processPid int
processStartTime string
processStartTime uint64
fds []string
}

Expand All @@ -101,7 +101,7 @@ func (p *nonChildProcess) wait() (*os.ProcessState, error) {
return nil, newGenericError(fmt.Errorf("restored process cannot be waited on"), SystemError)
}

func (p *nonChildProcess) startTime() (string, error) {
func (p *nonChildProcess) startTime() (uint64, error) {
return p.processStartTime, nil
}

Expand Down

0 comments on commit abd39d1

Please sign in to comment.