@@ -52,16 +52,15 @@ type parentProcess interface {
5252 forwardChildLogs ()
5353}
5454
55- type readWritePair struct {
56- r * os.File
57- w * os.File
55+ type filePair struct {
56+ parent * os.File
57+ child * os.File
5858}
5959
6060type setnsProcess struct {
6161 cmd * exec.Cmd
62- parentPipe * os.File
63- childPipe * os.File
64- logPipe readWritePair
62+ messageSockPair filePair
63+ logFilePair filePair
6564 cgroupPaths map [string ]string
6665 rootlessCgroups bool
6766 intelRdtPath string
@@ -85,16 +84,16 @@ func (p *setnsProcess) signal(sig os.Signal) error {
8584}
8685
8786func (p * setnsProcess ) start () (err error ) {
88- defer p .parentPipe .Close ()
87+ defer p .messageSockPair . parent .Close ()
8988 err = p .cmd .Start ()
9089 // close the write-side of the pipes (controlled by child)
91- p .childPipe .Close ()
92- p .logPipe . w .Close ()
90+ p .messageSockPair . child .Close ()
91+ p .logFilePair . child .Close ()
9392 if err != nil {
9493 return newSystemErrorWithCause (err , "starting setns process" )
9594 }
9695 if p .bootstrapData != nil {
97- if _ , err := io .Copy (p .parentPipe , p .bootstrapData ); err != nil {
96+ if _ , err := io .Copy (p .messageSockPair . parent , p .bootstrapData ); err != nil {
9897 return newSystemErrorWithCause (err , "copying bootstrap data to pipe" )
9998 }
10099 }
@@ -120,11 +119,11 @@ func (p *setnsProcess) start() (err error) {
120119 if err := setupRlimits (p .config .Rlimits , p .pid ()); err != nil {
121120 return newSystemErrorWithCause (err , "setting rlimits for process" )
122121 }
123- if err := utils .WriteJSON (p .parentPipe , p .config ); err != nil {
122+ if err := utils .WriteJSON (p .messageSockPair . parent , p .config ); err != nil {
124123 return newSystemErrorWithCause (err , "writing config to pipe" )
125124 }
126125
127- ierr := parseSync (p .parentPipe , func (sync * syncT ) error {
126+ ierr := parseSync (p .messageSockPair . parent , func (sync * syncT ) error {
128127 switch sync .Type {
129128 case procReady :
130129 // This shouldn't happen.
@@ -137,7 +136,7 @@ func (p *setnsProcess) start() (err error) {
137136 }
138137 })
139138
140- if err := unix .Shutdown (int (p .parentPipe .Fd ()), unix .SHUT_WR ); err != nil {
139+ if err := unix .Shutdown (int (p .messageSockPair . parent .Fd ()), unix .SHUT_WR ); err != nil {
141140 return newSystemErrorWithCause (err , "calling shutdown on init pipe" )
142141 }
143142 // Must be done after Shutdown so the child will exit and we can wait for it.
@@ -163,7 +162,7 @@ func (p *setnsProcess) execSetns() error {
163162 return newSystemError (& exec.ExitError {ProcessState : status })
164163 }
165164 var pid * pid
166- if err := json .NewDecoder (p .parentPipe ).Decode (& pid ); err != nil {
165+ if err := json .NewDecoder (p .messageSockPair . parent ).Decode (& pid ); err != nil {
167166 p .cmd .Wait ()
168167 return newSystemErrorWithCause (err , "reading pid from init pipe" )
169168 }
@@ -217,14 +216,13 @@ func (p *setnsProcess) setExternalDescriptors(newFds []string) {
217216}
218217
219218func (p * setnsProcess ) forwardChildLogs () {
220- go logs .ForwardLogs (p .logPipe . r )
219+ go logs .ForwardLogs (p .logFilePair . parent )
221220}
222221
223222type initProcess struct {
224223 cmd * exec.Cmd
225- parentPipe * os.File
226- childPipe * os.File
227- logPipe readWritePair
224+ messageSockPair filePair
225+ logFilePair filePair
228226 config * initConfig
229227 manager cgroups.Manager
230228 intelRdtManager intelrdt.Manager
@@ -246,7 +244,7 @@ func (p *initProcess) externalDescriptors() []string {
246244// getChildPid receives the final child's pid over the provided pipe.
247245func (p * initProcess ) getChildPid () (int , error ) {
248246 var pid pid
249- if err := json .NewDecoder (p .parentPipe ).Decode (& pid ); err != nil {
247+ if err := json .NewDecoder (p .messageSockPair . parent ).Decode (& pid ); err != nil {
250248 p .cmd .Wait ()
251249 return - 1 , err
252250 }
@@ -282,12 +280,12 @@ func (p *initProcess) waitForChildExit(childPid int) error {
282280}
283281
284282func (p * initProcess ) start () error {
285- defer p .parentPipe .Close ()
283+ defer p .messageSockPair . parent .Close ()
286284 err := p .cmd .Start ()
287285 p .process .ops = p
288286 // close the write-side of the pipes (controlled by child)
289- p .childPipe .Close ()
290- p .logPipe . w .Close ()
287+ p .messageSockPair . child .Close ()
288+ p .logFilePair . child .Close ()
291289 if err != nil {
292290 p .process .ops = nil
293291 return newSystemErrorWithCause (err , "starting init process command" )
@@ -313,7 +311,7 @@ func (p *initProcess) start() error {
313311 }
314312 }()
315313
316- if _ , err := io .Copy (p .parentPipe , p .bootstrapData ); err != nil {
314+ if _ , err := io .Copy (p .messageSockPair . parent , p .bootstrapData ); err != nil {
317315 return newSystemErrorWithCause (err , "copying bootstrap data to pipe" )
318316 }
319317 childPid , err := p .getChildPid ()
@@ -341,7 +339,7 @@ func (p *initProcess) start() error {
341339 }
342340 // Now it's time to setup cgroup namesapce
343341 if p .config .Config .Namespaces .Contains (configs .NEWCGROUP ) && p .config .Config .Namespaces .PathOf (configs .NEWCGROUP ) == "" {
344- if _ , err := p .parentPipe .Write ([]byte {createCgroupns }); err != nil {
342+ if _ , err := p .messageSockPair . parent .Write ([]byte {createCgroupns }); err != nil {
345343 return newSystemErrorWithCause (err , "sending synchronization value to init process" )
346344 }
347345 }
@@ -368,7 +366,7 @@ func (p *initProcess) start() error {
368366 sentResume bool
369367 )
370368
371- ierr := parseSync (p .parentPipe , func (sync * syncT ) error {
369+ ierr := parseSync (p .messageSockPair . parent , func (sync * syncT ) error {
372370 switch sync .Type {
373371 case procReady :
374372 // set rlimits, this has to be done here because we lose permissions
@@ -404,7 +402,7 @@ func (p *initProcess) start() error {
404402 }
405403 }
406404 // Sync with child.
407- if err := writeSync (p .parentPipe , procRun ); err != nil {
405+ if err := writeSync (p .messageSockPair . parent , procRun ); err != nil {
408406 return newSystemErrorWithCause (err , "writing syncT 'run'" )
409407 }
410408 sentRun = true
@@ -433,7 +431,7 @@ func (p *initProcess) start() error {
433431 }
434432 }
435433 // Sync with child.
436- if err := writeSync (p .parentPipe , procResume ); err != nil {
434+ if err := writeSync (p .messageSockPair . parent , procResume ); err != nil {
437435 return newSystemErrorWithCause (err , "writing syncT 'resume'" )
438436 }
439437 sentResume = true
@@ -450,7 +448,7 @@ func (p *initProcess) start() error {
450448 if p .config .Config .Namespaces .Contains (configs .NEWNS ) && ! sentResume {
451449 return newSystemError (fmt .Errorf ("could not synchronise after executing prestart hooks with container process" ))
452450 }
453- if err := unix .Shutdown (int (p .parentPipe .Fd ()), unix .SHUT_WR ); err != nil {
451+ if err := unix .Shutdown (int (p .messageSockPair . parent .Fd ()), unix .SHUT_WR ); err != nil {
454452 return newSystemErrorWithCause (err , "shutting down init pipe" )
455453 }
456454
@@ -494,7 +492,7 @@ func (p *initProcess) sendConfig() error {
494492 // send the config to the container's init process, we don't use JSON Encode
495493 // here because there might be a problem in JSON decoder in some cases, see:
496494 // https://github.com/docker/docker/issues/14203#issuecomment-174177790
497- return utils .WriteJSON (p .parentPipe , p .config )
495+ return utils .WriteJSON (p .messageSockPair . parent , p .config )
498496}
499497
500498func (p * initProcess ) createNetworkInterfaces () error {
@@ -527,7 +525,7 @@ func (p *initProcess) setExternalDescriptors(newFds []string) {
527525}
528526
529527func (p * initProcess ) forwardChildLogs () {
530- go logs .ForwardLogs (p .logPipe . r )
528+ go logs .ForwardLogs (p .logFilePair . parent )
531529}
532530
533531func getPipeFds (pid int ) ([]string , error ) {
0 commit comments