@@ -164,13 +164,14 @@ func testProcOvermountSubdir(t *testing.T, procRootFn procRootFunc, expectOvermo
164164 require .NoError (t , err )
165165 defer procExe .Close () //nolint:errcheck // test code
166166
167- // Get the handle that doProcThreadSelf is using internally when we
168- // test the external API.
169167 testProcRoot := procRoot
170168 if testProcRoot == nil {
171- testProcRoot , err = getProcRoot ()
169+ // If using the external API, we cannot get the procfs handled used
170+ // directly (because it gets created anew for each operation), so
171+ // instead just reuse procSelf for this.
172+ testProcRoot , err = openatFile (procSelf , "../../.." , unix .O_PATH , 0 )
172173 require .NoError (t , err )
173- // do not call testProcRoot.Close() -- it's a global handle
174+ defer testProcRoot .Close () //nolint:errcheck // test code
174175 }
175176
176177 // no overmount
@@ -222,22 +223,22 @@ func TestProcOvermountSubdir_clonePrivateProcMount(t *testing.T) {
222223 })
223224}
224225
225- func TestProcOvermountSubdir_doGetProcRoot (t * testing.T ) {
226+ func TestProcOvermountSubdir_getProcRoot (t * testing.T ) {
226227 withWithoutOpenat2 (t , true , func (t * testing.T ) {
227228 // We expect to not get overmounts if we have the new mount API.
228229 // FIXME: It's possible to hit overmounts if there are locked mounts
229230 // and we hit the AT_RECURSIVE case...
230- testProcOvermountSubdir (t , doGetProcRoot , ! hasNewMountAPI ())
231+ testProcOvermountSubdir (t , getProcRoot , ! hasNewMountAPI ())
231232 })
232233}
233234
234- func TestProcOvermountSubdir_doGetProcRoot_Mocked (t * testing.T ) {
235+ func TestProcOvermountSubdir_getProcRoot_Mocked (t * testing.T ) {
235236 if ! hasNewMountAPI () {
236237 t .Skip ("test requires fsopen/open_tree support" )
237238 }
238239 withWithoutOpenat2 (t , true , func (t * testing.T ) {
239240 testForceGetProcRoot (t , func (t * testing.T , expectOvermounts bool ) {
240- testProcOvermountSubdir (t , doGetProcRoot , expectOvermounts )
241+ testProcOvermountSubdir (t , getProcRoot , expectOvermounts )
241242 })
242243 })
243244}
@@ -246,7 +247,7 @@ func TestProcOvermountSubdir_ProcThreadSelf(t *testing.T) {
246247 withWithoutOpenat2 (t , true , func (t * testing.T ) {
247248 testForceProcThreadSelf (t , func (t * testing.T ) {
248249 dummyGetRoot := func () (* os.File , error ) { return nil , nil } //nolint:nilnil // intentional
249- // Use the same overmounts policy as doGetProcRoot .
250+ // Use the same overmounts policy as getProcRoot .
250251 testProcOvermountSubdir (t , dummyGetRoot , ! hasNewMountAPI ())
251252 })
252253 })
@@ -454,18 +455,18 @@ func TestProcOvermount_newPrivateProcMount(t *testing.T) {
454455 testProcOvermount (t , newPrivateProcMount , true )
455456}
456457
457- func TestProcOvermount_doGetProcRoot (t * testing.T ) {
458+ func TestProcOvermount_getProcRoot (t * testing.T ) {
458459 privateProcMount := canFsOpen () && ! testingForcePrivateProcRootOpenTree (nil )
459- testProcOvermount (t , doGetProcRoot , privateProcMount )
460+ testProcOvermount (t , getProcRoot , privateProcMount )
460461}
461462
462- func TestProcOvermount_doGetProcRoot_Mocked (t * testing.T ) {
463+ func TestProcOvermount_getProcRoot_Mocked (t * testing.T ) {
463464 if ! hasNewMountAPI () {
464465 t .Skip ("test requires fsopen/open_tree support" )
465466 }
466467 testForceGetProcRoot (t , func (t * testing.T , _ bool ) {
467468 privateProcMount := canFsOpen () && ! testingForcePrivateProcRootOpenTree (nil )
468- testProcOvermount (t , doGetProcRoot , privateProcMount )
469+ testProcOvermount (t , getProcRoot , privateProcMount )
469470 })
470471}
471472
0 commit comments