@@ -95,33 +95,74 @@ func (c *processComm) closeParent() {
95
95
// c.logPipeParent is kept alive for ForwardLogs
96
96
}
97
97
98
- type setnsProcess struct {
99
- cmd * exec.Cmd
100
- comm * processComm
101
- cgroupPaths map [string ]string
102
- rootlessCgroups bool
103
- manager cgroups.Manager
104
- intelRdtPath string
105
- config * initConfig
106
- fds []string
107
- process * Process
108
- bootstrapData io.Reader
109
- initProcessPid int
98
+ type containerProcess struct {
99
+ cmd * exec.Cmd
100
+ comm * processComm
101
+ config * initConfig
102
+ manager cgroups.Manager
103
+ fds []string
104
+ process * Process
105
+ bootstrapData io.Reader
106
+ container * Container
107
+ }
108
+
109
+ func (p * containerProcess ) pid () int {
110
+ return p .cmd .Process .Pid
110
111
}
111
112
112
- func (p * setnsProcess ) startTime () (uint64 , error ) {
113
+ func (p * containerProcess ) startTime () (uint64 , error ) {
113
114
stat , err := system .Stat (p .pid ())
114
115
return stat .StartTime , err
115
116
}
116
117
117
- func (p * setnsProcess ) signal (sig os.Signal ) error {
118
+ func (p * containerProcess ) signal (sig os.Signal ) error {
118
119
s , ok := sig .(unix.Signal )
119
120
if ! ok {
120
121
return errors .New ("os: unsupported signal type" )
121
122
}
122
123
return unix .Kill (p .pid (), s )
123
124
}
124
125
126
+ func (p * containerProcess ) externalDescriptors () []string {
127
+ return p .fds
128
+ }
129
+
130
+ func (p * containerProcess ) setExternalDescriptors (newFds []string ) {
131
+ p .fds = newFds
132
+ }
133
+
134
+ func (p * containerProcess ) forwardChildLogs () chan error {
135
+ return logs .ForwardLogs (p .comm .logPipeParent )
136
+ }
137
+
138
+ // terminate sends a SIGKILL to the forked process for the setns routine then waits to
139
+ // avoid the process becoming a zombie.
140
+ func (p * containerProcess ) terminate () error {
141
+ if p .cmd .Process == nil {
142
+ return nil
143
+ }
144
+ err := p .cmd .Process .Kill ()
145
+ if _ , werr := p .wait (); err == nil {
146
+ err = werr
147
+ }
148
+ return err
149
+ }
150
+
151
+ func (p * containerProcess ) wait () (* os.ProcessState , error ) { //nolint:unparam
152
+ err := p .cmd .Wait ()
153
+
154
+ // Return actual ProcessState even on Wait error
155
+ return p .cmd .ProcessState , err
156
+ }
157
+
158
+ type setnsProcess struct {
159
+ containerProcess
160
+ cgroupPaths map [string ]string
161
+ rootlessCgroups bool
162
+ intelRdtPath string
163
+ initProcessPid int
164
+ }
165
+
125
166
func (p * setnsProcess ) start () (retErr error ) {
126
167
defer p .comm .closeParent ()
127
168
@@ -327,60 +368,9 @@ func (p *setnsProcess) execSetns() error {
327
368
return nil
328
369
}
329
370
330
- // terminate sends a SIGKILL to the forked process for the setns routine then waits to
331
- // avoid the process becoming a zombie.
332
- func (p * setnsProcess ) terminate () error {
333
- if p .cmd .Process == nil {
334
- return nil
335
- }
336
- err := p .cmd .Process .Kill ()
337
- if _ , werr := p .wait (); err == nil {
338
- err = werr
339
- }
340
- return err
341
- }
342
-
343
- func (p * setnsProcess ) wait () (* os.ProcessState , error ) {
344
- err := p .cmd .Wait ()
345
-
346
- // Return actual ProcessState even on Wait error
347
- return p .cmd .ProcessState , err
348
- }
349
-
350
- func (p * setnsProcess ) pid () int {
351
- return p .cmd .Process .Pid
352
- }
353
-
354
- func (p * setnsProcess ) externalDescriptors () []string {
355
- return p .fds
356
- }
357
-
358
- func (p * setnsProcess ) setExternalDescriptors (newFds []string ) {
359
- p .fds = newFds
360
- }
361
-
362
- func (p * setnsProcess ) forwardChildLogs () chan error {
363
- return logs .ForwardLogs (p .comm .logPipeParent )
364
- }
365
-
366
371
type initProcess struct {
367
- cmd * exec.Cmd
368
- comm * processComm
369
- config * initConfig
370
- manager cgroups.Manager
372
+ containerProcess
371
373
intelRdtManager * intelrdt.Manager
372
- container * Container
373
- fds []string
374
- process * Process
375
- bootstrapData io.Reader
376
- }
377
-
378
- func (p * initProcess ) pid () int {
379
- return p .cmd .Process .Pid
380
- }
381
-
382
- func (p * initProcess ) externalDescriptors () []string {
383
- return p .fds
384
374
}
385
375
386
376
// getChildPid receives the final child's pid over the provided pipe.
@@ -797,27 +787,6 @@ func (p *initProcess) start() (retErr error) {
797
787
return nil
798
788
}
799
789
800
- func (p * initProcess ) wait () (* os.ProcessState , error ) {
801
- err := p .cmd .Wait ()
802
- return p .cmd .ProcessState , err
803
- }
804
-
805
- func (p * initProcess ) terminate () error {
806
- if p .cmd .Process == nil {
807
- return nil
808
- }
809
- err := p .cmd .Process .Kill ()
810
- if _ , werr := p .wait (); err == nil {
811
- err = werr
812
- }
813
- return err
814
- }
815
-
816
- func (p * initProcess ) startTime () (uint64 , error ) {
817
- stat , err := system .Stat (p .pid ())
818
- return stat .StartTime , err
819
- }
820
-
821
790
func (p * initProcess ) updateSpecState () error {
822
791
s , err := p .container .currentOCIState ()
823
792
if err != nil {
@@ -845,22 +814,6 @@ func (p *initProcess) createNetworkInterfaces() error {
845
814
return nil
846
815
}
847
816
848
- func (p * initProcess ) signal (sig os.Signal ) error {
849
- s , ok := sig .(unix.Signal )
850
- if ! ok {
851
- return errors .New ("os: unsupported signal type" )
852
- }
853
- return unix .Kill (p .pid (), s )
854
- }
855
-
856
- func (p * initProcess ) setExternalDescriptors (newFds []string ) {
857
- p .fds = newFds
858
- }
859
-
860
- func (p * initProcess ) forwardChildLogs () chan error {
861
- return logs .ForwardLogs (p .comm .logPipeParent )
862
- }
863
-
864
817
func pidGetFd (pid , srcFd int ) (* os.File , error ) {
865
818
pidFd , err := unix .PidfdOpen (pid , 0 )
866
819
if err != nil {
0 commit comments