[Gllug] apt-get failing in chrooted python script...

Bruce Richardson itsbruce at workshy.org
Wed Sep 8 11:55:10 UTC 2010


On Wed, Sep 08, 2010 at 12:17:51AM +0100, general_email wrote:
> 
> Yes, that's whats so weird.
> 
> I'm using os.chroot() like so...
> 
> os.chroot('/home/r0g/AAA_BACKED_UP/Code/projects/Techbench/remaster/workspace/squashfs')

That isn't the path used in your original code snippet, but it does
match the error message in your original message.  If you don't give us
the code snippet you used to produce the actual error message, you are
only adding to the confusion.

> 
> The script seemingly manages to mount '/proc', '/sys' & '/dev/pts' OK, 
> which I assume it wouldn't if I weren't already in the chroot but then I 
> get the error...
> 
> E: Unable to change to 
> /home/r0g/AAA_BACKED_UP/Code/projects/Techbench/remaster/ - chdir (2: No 
> such file or directory)
> 
> Which of course there shouldn't be if the script is jailed in the first 
> folder which leaves the question: why is it apt-get trying to change to 
> a path outside the chroot and where did it find it!?

I thought I had explained this.  It's trying to change to the directory
that it previously retrieved using a getcwd() call (that is, to what was
the current working directory before it started doing something or
other).  So it's trying to restore the cwd to what it was when it was
run.  However, getcwd() is returning a bad value.  This can happen if a
chroot is badly set up, with the result that getcwd() returns a value
which has beening to the original context outside the chroot, rather
than a valid value within the chroot filesystem.

There is probably a bug in the os.chroot function in your particular
version of Python.  The reason I asked about symlinks was because the
path you gave in your code was not the same as the path in the error
message and this was the only way I could think of to reconcile the
mismatch (the Python os.chroot function has, in the past, barfed on
particular characters in the chroot path and I speculated that it might
this time be walking the patch - for whatever mad reason - and being
confused by a symlink).  However, it seems you just gave mismatched
information and that's a red herring.

> 
> Any suggestions as to how to continue debugging are more than welcome.

Don't keep trying to make big changes.  Don't make any changes till you
have more information.  If you want to actually find out what the
problem is, test first, increasing the level of debugging information as
required, until you have better information.  Then make small changes,
one at a time, to see what effect this has.  Simply changing things to
see if it makes a problem go away isn't debugging and doesn't teach you
anything.   And a big change like Python 2 to 3 is almost certain to
break other things.

-- 
Bruce

The ice-caps are melting, tra-la-la-la.  All the world is drowning,
tra-la-la-la-la.  -- Tiny Tim.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: Digital signature
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20100908/6ca39528/attachment.pgp>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list