@@ -134,7 +134,7 @@ func clonePrivateProcMount() (_ *os.File, Err error) {
134
134
// we can be sure there are no over-mounts and so if the root is valid then
135
135
// we're golden. Otherwise, we have to deal with over-mounts.
136
136
procfsHandle , err := openTree (nil , "/proc" , unix .OPEN_TREE_CLONE )
137
- if err != nil || testingForcePrivateProcRootOpenTreeAtRecursive (procfsHandle ) {
137
+ if err != nil || hookForcePrivateProcRootOpenTreeAtRecursive (procfsHandle ) {
138
138
procfsHandle , err = openTree (nil , "/proc" , unix .OPEN_TREE_CLONE | unix .AT_RECURSIVE )
139
139
}
140
140
if err != nil {
@@ -152,13 +152,13 @@ func clonePrivateProcMount() (_ *os.File, Err error) {
152
152
}
153
153
154
154
func privateProcRoot () (* os.File , error ) {
155
- if ! hasNewMountApi () || testingForceGetProcRootUnsafe () {
155
+ if ! hasNewMountApi () || hookForceGetProcRootUnsafe () {
156
156
return nil , fmt .Errorf ("new mount api: %w" , unix .ENOTSUP )
157
157
}
158
158
// Try to create a new procfs mount from scratch if we can. This ensures we
159
159
// can get a procfs mount even if /proc is fake (for whatever reason).
160
160
procRoot , err := newPrivateProcMount ()
161
- if err != nil || testingForcePrivateProcRootOpenTree (procRoot ) {
161
+ if err != nil || hookForcePrivateProcRootOpenTree (procRoot ) {
162
162
// Try to clone /proc then...
163
163
procRoot , err = clonePrivateProcMount ()
164
164
}
@@ -227,10 +227,10 @@ func procThreadSelf(procRoot *os.File, subpath string) (_ *os.File, _ procThread
227
227
228
228
// Figure out what prefix we want to use.
229
229
threadSelf := "thread-self/"
230
- if ! hasProcThreadSelf () || testingForceProcSelfTask () {
230
+ if ! hasProcThreadSelf () || hookForceProcSelfTask () {
231
231
/// Pre-3.17 kernels don't have /proc/thread-self, so do it manually.
232
232
threadSelf = "self/task/" + strconv .Itoa (unix .Gettid ()) + "/"
233
- if _ , err := fstatatFile (procRoot , threadSelf , unix .AT_SYMLINK_NOFOLLOW ); err != nil || testingForceProcSelf () {
233
+ if _ , err := fstatatFile (procRoot , threadSelf , unix .AT_SYMLINK_NOFOLLOW ); err != nil || hookForceProcSelf () {
234
234
// In this case, we running in a pid namespace that doesn't match
235
235
// the /proc mount we have. This can happen inside runc.
236
236
//
@@ -424,3 +424,18 @@ func checkProcSelfFdPath(path string, file *os.File) error {
424
424
}
425
425
return nil
426
426
}
427
+
428
+ // Test hooks
429
+ var hookForcePrivateProcRootOpenTree = func (_ * os.File ) bool {
430
+ return false
431
+ }
432
+
433
+ var hookForcePrivateProcRootOpenTreeAtRecursive = hookForcePrivateProcRootOpenTree
434
+
435
+ var hookForceGetProcRootUnsafe = func () bool {
436
+ return false
437
+ }
438
+
439
+ var hookForceProcSelfTask = hookForceGetProcRootUnsafe
440
+
441
+ var hookForceProcSelf = hookForceGetProcRootUnsafe
0 commit comments