@@ -12,6 +12,15 @@ import (
1212 "github.com/docker/containerd/execution"
1313)
1414
15+ const (
16+ initProcessID = "init"
17+ )
18+
19+ const (
20+ PidFilename = "pid"
21+ StartTimeFilename = "starttime"
22+ )
23+
1524var (
1625 ErrRootEmpty = errors .New ("oci: runtime root cannot be an empty string" )
1726)
@@ -59,11 +68,11 @@ func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOp
5968 }
6069 }(container )
6170
62- initProcID , initStateDir , err := container .StateDir ().NewProcess ()
71+ initStateDir , err := container .StateDir ().NewProcess (initProcessID )
6372 if err != nil {
6473 return nil , err
6574 }
66- pidFile := filepath .Join (initStateDir , "pid" )
75+ pidFile := filepath .Join (initStateDir , PidFilename )
6776 err = r .runc .Create (ctx , id , o .Bundle , & runc.CreateOpts {
6877 PidFile : pidFile ,
6978 Console : oio .console ,
@@ -79,11 +88,7 @@ func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOp
7988 }
8089 }()
8190
82- pid , err := runc .ReadPidFile (pidFile )
83- if err != nil {
84- return nil , err
85- }
86- process , err := newProcess (initProcID , pid )
91+ process , err := newProcess (initProcessID , initStateDir , execution .Created )
8792 if err != nil {
8893 return nil , err
8994 }
@@ -112,7 +117,7 @@ func (r *OCIRuntime) load(runcC *runc.Container) (*execution.Container, error) {
112117 execution .StateDir (filepath .Join (r .root , runcC .ID )),
113118 runcC .ID ,
114119 runcC .Bundle ,
115- runcC .Status ,
120+ execution . Status ( runcC .Status ) ,
116121 int64 (runcC .Pid ),
117122 )
118123
@@ -121,19 +126,11 @@ func (r *OCIRuntime) load(runcC *runc.Container) (*execution.Container, error) {
121126 return nil , err
122127 }
123128 for _ , d := range dirs {
124- pid , err := runc .ReadPidFile (filepath .Join (d , "pid" ))
125- if err != nil {
126- if os .IsNotExist (err ) {
127- // Process died in between
128- continue
129- }
130- return nil , err
131- }
132- process , err := newProcess (filepath .Base (d ), pid )
129+ process , err := newProcess (filepath .Base (d ), d , execution .Running )
133130 if err != nil {
134131 return nil , err
135132 }
136- container .AddProcess (process , pid == runcC .Pid )
133+ container .AddProcess (process , process . Pid () == int64 ( runcC .Pid ) )
137134 }
138135
139136 return container , nil
@@ -201,17 +198,17 @@ func (r *OCIRuntime) StartProcess(ctx context.Context, c *execution.Container, o
201198 }
202199 }()
203200
204- procID , procStateDir , err := c .StateDir ().NewProcess ()
201+ procStateDir , err := c .StateDir ().NewProcess (o . ID )
205202 if err != nil {
206203 return nil , err
207204 }
208205 defer func () {
209206 if err != nil {
210- c .StateDir ().DeleteProcess (procID )
207+ c .StateDir ().DeleteProcess (o . ID )
211208 }
212209 }()
213210
214- pidFile := filepath .Join (procStateDir , "pid" )
211+ pidFile := filepath .Join (procStateDir , PidFilename )
215212 if err := r .runc .Exec (ctx , c .ID (), o .Spec , & runc.ExecOpts {
216213 PidFile : pidFile ,
217214 Detach : false ,
@@ -221,12 +218,8 @@ func (r *OCIRuntime) StartProcess(ctx context.Context, c *execution.Container, o
221218 }); err != nil {
222219 return nil , err
223220 }
224- pid , err := runc .ReadPidFile (pidFile )
225- if err != nil {
226- return nil , err
227- }
228221
229- process , err := newProcess (procID , pid )
222+ process , err := newProcess (o . ID , procStateDir , execution . Running )
230223 if err != nil {
231224 return nil , err
232225 }
0 commit comments