@@ -2176,9 +2176,9 @@ class NamespacesTests(unittest.TestCase):
2176
2176
"""Tests for os.unshare() and os.setns()."""
2177
2177
2178
2178
@support .requires_subprocess ()
2179
- def subprocess (self , file_path ):
2179
+ def subprocess (self , code ):
2180
2180
import subprocess
2181
- with subprocess .Popen ((sys .executable , file_path ),
2181
+ with subprocess .Popen ((sys .executable , '-c' , code ),
2182
2182
stdout = subprocess .PIPE ,
2183
2183
stderr = subprocess .PIPE ,
2184
2184
encoding = "utf-8"
@@ -2195,7 +2195,22 @@ def subprocess(self, file_path):
2195
2195
@unittest .skipUnless (os .path .exists ('/proc/self/ns/uts' ), 'need /proc/self/ns/uts' )
2196
2196
@support .requires_linux_version (3 , 0 , 0 )
2197
2197
def test_unshare_setns (self ):
2198
- rc , out , err = self .subprocess (support .findfile ("namespaces-test.py" ))
2198
+ rc , out , err = self .subprocess ("""if 1:
2199
+ import os
2200
+ import sys
2201
+ fd = os.open('/proc/self/ns/uts', os.O_RDONLY)
2202
+ try:
2203
+ print(os.readlink('/proc/self/ns/uts'))
2204
+ os.unshare(os.CLONE_NEWUTS)
2205
+ print(os.readlink('/proc/self/ns/uts'))
2206
+ os.setns(fd, os.CLONE_NEWUTS)
2207
+ print(os.readlink('/proc/self/ns/uts'))
2208
+ except OSError as e:
2209
+ sys.stderr.write(str(e.errno))
2210
+ sys.exit(2)
2211
+ finally:
2212
+ os.close(fd)
2213
+ """ )
2199
2214
2200
2215
if rc == 2 :
2201
2216
e = int (err [0 ])
0 commit comments