Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12863

Re: Can't use subprocess.Popen() after os.chroot() - why?

From Nobody <nobody@nowhere.com>
Subject Re: Can't use subprocess.Popen() after os.chroot() - why?
Date 2011-09-07 02:01 +0100
Message-Id <pan.2011.09.07.01.01.11.196000@nowhere.com>
Newsgroups comp.lang.python
References <b46caa73-f7a7-4154-8643-cf77b052d31e@glegroupsg2000goo.googlegroups.com>
Organization Zen Internet

Show all headers | View raw


On Sun, 04 Sep 2011 07:22:07 -0700, Erik wrote:

> I'm trying to do the following: 

> os.chroot("/tmp/my_chroot")
> p = Popen("/bin/date", stdin=PIPE, stdout=PIPE, stderr=PIPE)

> but the Popen call is dying with the following exception:

> LookupError: unknown encoding: string-escape
> 
> Am I missing something here? does the chroot environment need to be
> populated with more than just the date executable in this case?

Yes. It also needs to include any parts of the Python run-time which
Python will try to load while executing subsequent code. In this case, the
module which implements the string-escape encoding.

But fixing that will probably show up yet more files which need to exist
within the pseudo-root. E.g. any shared libraries which the executable
needs (probably at least libc), and any data files which those libraries
need (in the case of /bin/date, it may need /etc/timezone; many programs
may require locale data if you aren't in the "C" locale, and so on).

Whether from Python or from C, chroot() requires a good understanding of
the low-level details of your operating system. If you don't know how to
build a minimal Linux distribution from scratch, you're going to have to
learn many of those details in order to use chroot().

For any non-trivial chroot() usage, it's often easier to install a small
newlib+busybox-based Linux distribution under the pseudo-root than to try
to re-use files from and existing (presumably glibc+coreutils-based)
desktop/server distribution.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Can't use subprocess.Popen() after os.chroot() - why? Erik <erik.williamson@gmail.com> - 2011-09-04 07:22 -0700
  Re: Can't use subprocess.Popen() after os.chroot() - why? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-09-04 17:25 +0200
    Re: Can't use subprocess.Popen() after os.chroot() - why? Hans Mulder <hansmu@xs4all.nl> - 2011-09-04 19:36 +0200
  Re: Can't use subprocess.Popen() after os.chroot() - why? Nobody <nobody@nowhere.com> - 2011-09-07 02:01 +0100

csiph-web