Commit 42dc0de4 by Stéphane Graber Committed by GitHub

Merge pull request #1392 from cjwatson/start-ephemeral-python32

Make lxc-start-ephemeral Python 3.2-compatible
parents 4893a431 e0e34b7e
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
import argparse import argparse
import gettext import gettext
import lxc import lxc
import locale
import os import os
import sys import sys
import subprocess import subprocess
...@@ -363,9 +364,14 @@ if os.path.exists("/proc/self/ns/pid"): ...@@ -363,9 +364,14 @@ if os.path.exists("/proc/self/ns/pid"):
if args.user: if args.user:
username = args.user username = args.user
line = subprocess.check_output( # This should really just use universal_newlines=True, but we do
["getent", "passwd", username], # the decoding by hand instead for compatibility with Python
universal_newlines=True).rstrip("\n") # 3.2; that used locale.getpreferredencoding() internally rather
# than locale.getpreferredencoding(False), and the former breaks
# here because we can't reload codecs at this point unless the
# container has the same version of Python installed.
line = subprocess.check_output(["getent", "passwd", username])
line = line.decode(locale.getpreferredencoding(False)).rstrip("\n")
_, _, pw_uid, pw_gid, _, pw_dir, _ = line.split(":", 6) _, _, pw_uid, pw_gid, _, pw_dir, _ = line.split(":", 6)
pw_uid = int(pw_uid) pw_uid = int(pw_uid)
pw_gid = int(pw_gid) pw_gid = int(pw_gid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment