summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-10-31 15:27:43 +0000
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-03 17:55:16 +0000
commit3c488585bd9897c842c1708ddb413adee5a9b43a (patch)
tree4c7e2ca12da090cdf5b57438606b903a74bbdc2e
parentb8fa270e8937ed26e4e684050d221202b475c708 (diff)
downloadbubblewrap-3c488585bd9897c842c1708ddb413adee5a9b43a.tar.gz
userns-block-fd: Add support for Python 3
According to PEP 394, the python command is meant to be Python 2 until at least 2020, so in practice this script will be run with Python 2 for now (except on Arch Linux); but it seems good to be more future-proof. In Python 3, os.write() takes a bytestring (bytes object), not a text string (str/unicode object). In Python 2 ≥ 2.6, the b'' syntax is supported and gives a str object, because that was a bytestring in Python 2; either way, b'1' is an acceptable argument to os.write(). In Python ≥ 3.4, the result of os.pipe() is close-on-exec (non-inheritable) by default, so undo that where needed. Signed-off-by: Simon McVittie <smcv@collabora.com> Closes: #246 Approved by: giuseppe
-rwxr-xr-xdemos/userns-block-fd.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/demos/userns-block-fd.py b/demos/userns-block-fd.py
index 67b6d8b..4c68242 100755
--- a/demos/userns-block-fd.py
+++ b/demos/userns-block-fd.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import os, select, subprocess, json
+import os, select, subprocess, sys, json
pipe_info = os.pipe()
userns_block = os.pipe()
@@ -19,11 +19,15 @@ if pid != 0:
subprocess.call(["newuidmap", child_pid, "0", str(os.getuid()), "1"])
subprocess.call(["newgidmap", child_pid, "0", str(os.getgid()), "1"])
- os.write(userns_block[1], '1')
+ os.write(userns_block[1], b'1')
else:
os.close(pipe_info[0])
os.close(userns_block[1])
+ if sys.version_info >= (3, 4):
+ os.set_inheritable(pipe_info[1], True)
+ os.set_inheritable(userns_block[0], True)
+
args = ["bwrap",
"bwrap",
"--unshare-all",