Debian Bug report logs - #395062
add additional bind mount points to chroot

version graph

Package: schroot; Maintainer for schroot is Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>; Source for schroot is src:schroot (PTS, buildd, popcon).

Reported by: Kees Cook <kees@outflux.net>

Date: Tue, 24 Oct 2006 18:33:10 UTC

Severity: wishlist

Tags: patch

Merged with 427047

Found in versions schroot/1.0.2-1, schroot/1.1.4-1

Fixed in version schroot/1.1.6-1

Done: Roger Leigh <rleigh@debian.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Kees Cook <kees@outflux.net>:
New Bug report received and forwarded. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Kees Cook <kees@outflux.net>
To: submit@bugs.debian.org
Subject: add additional bind mount points to chroot
Date: Tue, 24 Oct 2006 11:16:36 -0700
[Message part 1 (text/plain, inline)]
Package: schroot
Version: 1.0.2-1
Severity: wishlist
Tags: patch

When using schroot, I have a need to bind additional mount points into 
the chroot (for example, I use /scratch for builds, since my /home mount 
is on NFS).  Hopefully my solution for this is appropriate.

The attached patch adds the schroot.conf key "mount-extra", which the 
setup/10mount script uses as a colon-separates list of additional bind 
mounts.  

-- 
Kees Cook                                            @outflux.net
[schroot-mount-extra.patch (text/plain, attachment)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Roger Leigh <rleigh@whinlatter.ukfsn.org>:
Extra info received and forwarded to list. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #10 received at 395062@bugs.debian.org (full text, mbox, reply):

From: Roger Leigh <rleigh@whinlatter.ukfsn.org>
To: Kees Cook <kees@outflux.net>
Cc: 395062@bugs.debian.org
Subject: Re: [Buildd-tools-devel] Bug#395062: add additional bind mount points to chroot
Date: Fri, 27 Oct 2006 23:29:17 +0100
[Message part 1 (text/plain, inline)]
Kees Cook <kees@outflux.net> writes:

> When using schroot, I have a need to bind additional mount points into 
> the chroot (for example, I use /scratch for builds, since my /home mount 
> is on NFS).  Hopefully my solution for this is appropriate.
>
> The attached patch adds the schroot.conf key "mount-extra", which the 
> setup/10mount script uses as a colon-separates list of additional bind 
> mounts.  

Thanks for proposing this.  schroot (1.0) is currently frozen for
etch, but changes can go into the trunk.

I would very much like to allow easier customisation of the setup and
session scripts, but I would also like to keep the configuration file
as clean and simple as possible: I don't want to add a new
configuration option for every tweakable aspect of the scripts,
because I'd like to keep it /user/ extensible.  There are quite a
number of other things that people want to customise, so I'd prefer to
take a more general approach here.

An alternative approach I've been considering is to source a shell
script at the start of each setup script which would simply set a few
shell variables in the form

FOO="bar"

which could then be used by any of the scripts.  The configuration to
use could then be specified by a single configuration file option,
such as

  setup-script-config=/etc/schroot/custom-config

This could be unique to one chroot, or could be shared by different
chroots.  As it would be a shell script, it can be easily adapted by
users who want to allow customisation of their own setup scripts.

Does this sound OK?


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
[Message part 2 (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Kees Cook <kees@outflux.net>:
Extra info received and forwarded to list. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #15 received at 395062@bugs.debian.org (full text, mbox, reply):

From: Kees Cook <kees@outflux.net>
To: Roger Leigh <rleigh@whinlatter.ukfsn.org>
Cc: 395062@bugs.debian.org
Subject: Re: [Buildd-tools-devel] Bug#395062: add additional bind mount points to chroot
Date: Fri, 27 Oct 2006 15:44:53 -0700
On Fri, Oct 27, 2006 at 11:29:17PM +0100, Roger Leigh wrote:
>   setup-script-config=/etc/schroot/custom-config
> 
> This could be unique to one chroot, or could be shared by different
> chroots.  As it would be a shell script, it can be easily adapted by
> users who want to allow customisation of their own setup scripts.
> 
> Does this sound OK?

I think it could be made to work.  I wanted to use the "mount" shell 
functions to do the work.  Perhaps take my changes to the 10mount 
script, and then if CHROOT_MOUNT_EXTRA is defined in the 
'setup-script-config', it would do the right things as far as mounting?

I love the idea of making easier to customize, but I want to make sure I 
can still get into the 10mount script easily.  :)

Thanks!

-- 
Kees Cook                                            @outflux.net



Information forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Roger Leigh <rleigh@whinlatter.ukfsn.org>:
Extra info received and forwarded to list. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #20 received at 395062@bugs.debian.org (full text, mbox, reply):

From: Roger Leigh <rleigh@whinlatter.ukfsn.org>
To: Kees Cook <kees@outflux.net>, Peter Rabbitson <rabbit@rabbit.us>
Cc: 395062@bugs.debian.org, 427047@bugs.debian.org
Subject: Re: Bug#395062: [Buildd-tools-devel] Bug#395062: add additional bind mount points to chroot
Date: Sun, 08 Jul 2007 11:21:24 +0100
[Message part 1 (text/plain, inline)]
Kees Cook <kees@outflux.net> writes:

> On Fri, Oct 27, 2006 at 11:29:17PM +0100, Roger Leigh wrote:
>>   setup-script-config=/etc/schroot/custom-config
>> 
>> This could be unique to one chroot, or could be shared by different
>> chroots.  As it would be a shell script, it can be easily adapted by
>> users who want to allow customisation of their own setup scripts.
>> 
>> Does this sound OK?
>
> I think it could be made to work.  I wanted to use the "mount" shell 
> functions to do the work.  Perhaps take my changes to the 10mount 
> script, and then if CHROOT_MOUNT_EXTRA is defined in the 
> 'setup-script-config', it would do the right things as far as mounting?
>
> I love the idea of making easier to customize, but I want to make sure I 
> can still get into the 10mount script easily.  :)

I have now committed this into SVN.  There is an additional
script-config configuration option to specify a shell script under
/etc/schroot.  All the setup scripts now source this script, and so
now it will be possible to modify all the scripts to add customisation
hooks.

This is all in upstream SVN at
  svn://svn.debian.org/svn/buildd-tools/trunk/schroot

Now this is in place, things like the fstab file suggested by Peter
for #427047 may be added in to the script config file.

#395062 could be solved either by adding a list of mounts to the
config file (replacing the current hardcoded list), or alternatively
if could use the fstab arrangement proposed in #427047.  Since these
two bug reports have similar solutions, I'm sure we can work something
that will work for everyone.


Any comments?


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
[Message part 2 (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Raúl Sánchez Siles <rasasi78@gmail.com>:
Extra info received and forwarded to list. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #25 received at 395062@bugs.debian.org (full text, mbox, reply):

From: Raúl Sánchez Siles <rasasi78@gmail.com>
To: 395062@bugs.debian.org
Subject: Not found on repo.
Date: Mon, 7 Jan 2008 23:03:32 +0100
[Message part 1 (text/plain, inline)]
Hello:

  This is quite the same as in #427047.

  You said that the patch is commited on svn as of 08 Jul 2007, but there have 
been 2 releases since then 1.1.5-1 and 1.1.5-1.1, and also checked the svn 
repository but the patch doesn't seem to be applied.

  It even applies partially against svn repo.

  Thanks.

-- 
     Raúl Sánchez Siles
----->Proud Debian user<-----
Linux registered user #416098
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Roger Leigh <rleigh@whinlatter.ukfsn.org>:
Extra info received and forwarded to list. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #30 received at 395062@bugs.debian.org (full text, mbox, reply):

From: Roger Leigh <rleigh@whinlatter.ukfsn.org>
To: Raúl Sánchez Siles <rasasi78@gmail.com>
Cc: 427047@bugs.debian.org, 395062@bugs.debian.org
Subject: Re: [Buildd-tools-devel] Bug#427047: Not found on recent version or svn.
Date: Mon, 07 Jan 2008 23:14:03 +0000
[Message part 1 (text/plain, inline)]
Raúl Sánchez Siles <rasasi78@gmail.com> writes:

>   Hello:

Hi!

>   You said that the patch is commited on svn as of 08 Jul 2007, but
> there have been 2 releases since then 1.1.5-1 and 1.1.5-1.1, and
> also checked the svn repository but the patch doesn't seem to be
> applied.
>
>   I would expect it on bin/schroot/setup dir.

The patch I applied was to enable a general mechanism for allowing
user customisation of the setup scripts.  This is in the current
release.  The generic bit is the "script-config" option (default in
/etc/schroot/script-defaults.  This file gets sourced by the setup
scripts to modify their behaviour.  You could add an FSTAB option here
for 10mount to use.

The next step now involves using this general mechanism for allowing
custom mounts.  This has not yet been added--I'm still not sure of the
best approach here, though reading a separate file with the list of
mounts in it in the format of /etc/fstab is probably the best way to
go.  However, there is of course the issue of parsing the file format.
I think a C++ $libexecdir/schroot-mount wrapper calling setmntent()
and getmntent(), then calling mount(1) with the appropriate options
for each mount in turn is the most portable approach here.  Otherwise,
we can't portably read things like embedded spaces and escapes without
platform-specific knowledge.

BTW, schroot moved from SVN to GIT.  You can get the latest version
from

  git://git.debian.org/git/buildd-tools/schroot.git

(git clone git://git.debian.org/git/buildd-tools/schroot.git)


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
[Message part 2 (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Roger Leigh <rleigh@whinlatter.ukfsn.org>:
Extra info received and forwarded to list. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #35 received at 395062@bugs.debian.org (full text, mbox, reply):

From: Roger Leigh <rleigh@whinlatter.ukfsn.org>
To: Raúl Sánchez Siles <rasasi78@gmail.com>
Cc: 427047@bugs.debian.org, 395062@bugs.debian.org
Subject: Re: [Buildd-tools-devel] Bug#427047: Not found on recent version or svn.
Date: Tue, 8 Jan 2008 00:36:35 +0000
[Message part 1 (text/plain, inline)]
On Mon, Jan 07, 2008 at 11:14:03PM +0000, Roger Leigh wrote:
> Raúl Sánchez Siles <rasasi78@gmail.com> writes:
> 
> >   Hello:
> 
> Hi!
> 
> >   You said that the patch is commited on svn as of 08 Jul 2007, but
> > there have been 2 releases since then 1.1.5-1 and 1.1.5-1.1, and
> > also checked the svn repository but the patch doesn't seem to be
> > applied.
> >
> >   I would expect it on bin/schroot/setup dir.
> 
> The patch I applied was to enable a general mechanism for allowing
> user customisation of the setup scripts.  This is in the current
> release.  The generic bit is the "script-config" option (default in
> /etc/schroot/script-defaults.  This file gets sourced by the setup
> scripts to modify their behaviour.  You could add an FSTAB option here
> for 10mount to use.
> 
> The next step now involves using this general mechanism for allowing
> custom mounts.  This has not yet been added--I'm still not sure of the
> best approach here, though reading a separate file with the list of
> mounts in it in the format of /etc/fstab is probably the best way to
> go.  However, there is of course the issue of parsing the file format.
> I think a C++ $libexecdir/schroot-mount wrapper calling setmntent()
> and getmntent(), then calling mount(1) with the appropriate options
> for each mount in turn is the most portable approach here.  Otherwise,
> we can't portably read things like embedded spaces and escapes without
> platform-specific knowledge.

Just FYI, I added a schroot-mount tool to bin/schroot-mount.  It's
adapted from schroot-listmounts, and does not work yet (it's a
direct copy+search&replace), but will once I've added the
setmntent/getmntent bits.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to debian-bugs-dist@lists.debian.org, Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>:
Bug#395062; Package schroot. (full text, mbox, link).


Acknowledgement sent to Roger Leigh <rleigh@whinlatter.ukfsn.org>:
Extra info received and forwarded to list. Copy sent to Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>. (full text, mbox, link).


Message #40 received at 395062@bugs.debian.org (full text, mbox, reply):

From: Roger Leigh <rleigh@whinlatter.ukfsn.org>
To: Raúl Sánchez Siles <rasasi78@gmail.com>
Cc: 427047@bugs.debian.org, 395062@bugs.debian.org
Subject: Re: [Buildd-tools-devel] Bug#427047: Not found on recent version or svn.
Date: Wed, 9 Jan 2008 23:42:31 +0000
[Message part 1 (text/plain, inline)]
On Tue, Jan 08, 2008 at 12:36:35AM +0000, Roger Leigh wrote:
> On Mon, Jan 07, 2008 at 11:14:03PM +0000, Roger Leigh wrote:
> > Raúl Sánchez Siles <rasasi78@gmail.com> writes:
> > 
> > >   Hello:
> > 
> > Hi!
> > 
> > >   You said that the patch is commited on svn as of 08 Jul 2007, but
> > > there have been 2 releases since then 1.1.5-1 and 1.1.5-1.1, and
> > > also checked the svn repository but the patch doesn't seem to be
> > > applied.
> > >
> > >   I would expect it on bin/schroot/setup dir.
> > 
> > The patch I applied was to enable a general mechanism for allowing
> > user customisation of the setup scripts.  This is in the current
> > release.  The generic bit is the "script-config" option (default in
> > /etc/schroot/script-defaults.  This file gets sourced by the setup
> > scripts to modify their behaviour.  You could add an FSTAB option here
> > for 10mount to use.
> > 
> > The next step now involves using this general mechanism for allowing
> > custom mounts.  This has not yet been added--I'm still not sure of the
> > best approach here, though reading a separate file with the list of
> > mounts in it in the format of /etc/fstab is probably the best way to
> > go.  However, there is of course the issue of parsing the file format.
> > I think a C++ $libexecdir/schroot-mount wrapper calling setmntent()
> > and getmntent(), then calling mount(1) with the appropriate options
> > for each mount in turn is the most portable approach here.  Otherwise,
> > we can't portably read things like embedded spaces and escapes without
> > platform-specific knowledge.
> 
> Just FYI, I added a schroot-mount tool to bin/schroot-mount.  It's
> adapted from schroot-listmounts, and does not work yet (it's a
> direct copy+search&replace), but will once I've added the
> setmntent/getmntent bits.

Now mostly complete.  It now just needs the necessary glue code in
/etc/schroot/script-defaults and /etc/schroot/setup.d/10mount to
make it automatic.  I should have this finished and tested by the
weekend.


Regards,
Roger


diff --git a/ChangeLog b/ChangeLog
index a3e0a36..a08327e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,67 @@
+2008-01-09  Roger Leigh  <rleigh@debian.org>
+
+	* bin/schroot/mount.defaults: New file.  Defaults for
+	schroot-mount.  To be used in 10mounts and script-defaults.
+
+2008-01-09  Roger Leigh  <rleigh@debian.org>
+
+	* TODO: Add new items.
+
+2008-01-09  Roger Leigh  <rleigh@debian.org>
+
+	* bin/schroot-mount/schroot-mount-main.cc: Remove FIND, OPEN and
+	CLOSE error code descriptions.  Replace with CHILD_FORK,
+	CHILD_WAIT and EXEC descriptions.
+	(main::main): Update program description.
+	(main::action_mount): Use mntstream to parse fstab.  For each
+	mount entry, prefix mountpoint to directory, and fork and exec
+	/bin/mount to mount the filesystem.  Pass -v to mount if --verbose
+	was specified.
+	(main::run_child): New function, copied from
+	sbuild/sbuild-run-parts.cc with minor modifications.
+	(main::wait_for_child): New function, copied verbatim from
+	sbuild/sbuild-run-parts.cc.
+
+	* bin/schroot-mount/schroot-mount-main.h: Remove FIND, OPEN and
+	CLOSE error code.  Replace with CHILD_FORK, CHILD_WAIT and EXEC.
+
+	* bin/schroot-mount/schroot-mount-options.cc
+	(options::options): Initialise dry_run and fstab.
+	(options::add_options): Add --dry-run and --fstab options.
+	(options::check_options): Set dry_run and normalise mountpoint
+	path.
+
+	* bin/schroot-mount/schroot-mount-options.h: Add dry_run and fstab
+	member variables.
+
+2008-01-09  Roger Leigh  <rleigh@debian.org>
+
+	* po/POTFILES.in: Add sbuild/sbuild-mntstream.(cc|h).
+
+	* sbuild/Makefile.am
+	(sbuild_public_h_sources): Add sbuild-mntstream.h
+	(sbuild_public_cc_sources): Add sbuild-mntstream.cc
+
+	* sbuild/sbuild-mntstream.(cc|h): "Mount stream" interface to SUS
+	mntent functions.
+
+2008-01-08  Roger Leigh  <rleigh@debian.org>
+
+	* doc/.gitignore: Ignore *.pdf and *.ps.
+
+2008-01-08  Roger Leigh  <rleigh@debian.org>
+
+	* po/POTFILES.in: Add bin/schroot-mount sources.
+
+	* configure.ac: Output bin/schroot-mount/Makefile
+
+	* bin/Makefile.am (SUBDIRS): Add schroot-mount.
+
+	* bin/schroot-mount: Copy schroot-listmounts and search and
+	replace listmounts with mount.  This is the starting mount for the
+	schroot-mount utility to parse fstab(5) format files for mounting
+	filessystems inside chroots.
+
 2008-01-08  Roger Leigh  <rleigh@debian.org>
 
 	* sbuild/sbuild-chroot-lvm-snapshot.cc
diff --git a/TODO b/TODO
index 567855a..6703247 100644
--- a/TODO
+++ b/TODO
@@ -57,3 +57,8 @@ fashion.  expect might be useful for testing the PAM wrappers.
   code has no knowledge of the file name, so can't report it.
   Outright errors throw, and the handler adds the needed context.
 
+
+* schroot-listmounts should use mntstream.
+
+* Unify fork/exec code into a spawn function.
+
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 8012675..3b01349 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -25,6 +25,7 @@ SUBDIRS =	 		\
 	schroot-base		\
 	schroot			\
 	schroot-listmounts	\
+	schroot-mount		\
 	schroot-releaselock	\
 	dchroot			\
 	dchroot-dsa		\
diff --git a/bin/schroot-mount/.gitignore b/bin/schroot-mount/.gitignore
new file mode 100644
index 0000000..20f272a
--- /dev/null
+++ b/bin/schroot-mount/.gitignore
@@ -0,0 +1 @@
+schroot-mount
diff --git a/bin/schroot-mount/Makefile.am b/bin/schroot-mount/Makefile.am
new file mode 100644
index 0000000..2ef8046
--- /dev/null
+++ b/bin/schroot-mount/Makefile.am
@@ -0,0 +1,38 @@
+# schroot Makefile template
+#
+#
+# Copyright © 2004-2007  Roger Leigh <rleigh@debian.org>
+#
+# schroot is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# schroot is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+#####################################################################
+
+include $(top_srcdir)/scripts/global.mk
+
+pkglibexecdir = $(SCHROOT_LIBEXEC_DIR)
+
+LOCAL_CXXFLAGS = $(SCHROOT_CFLAGS) -I$(top_srcdir)/bin
+
+DEFS = -DLOCALEDIR=\"$(localedir)\" -D_GNU_SOURCE
+
+pkglibexec_PROGRAMS = schroot-mount
+
+schroot_mount_SOURCES =			\
+	schroot-mount-main.h		\
+	schroot-mount-main.cc		\
+	schroot-mount-options.h		\
+	schroot-mount-options.cc	\
+	schroot-mount.cc
+schroot_mount_LDADD = $(top_builddir)/bin/schroot-base/libschroot-base.la
diff --git a/bin/schroot-mount/schroot-mount-main.cc b/bin/schroot-mount/schroot-mount-main.cc
new file mode 100644
index 0000000..61d0c3c
--- /dev/null
+++ b/bin/schroot-mount/schroot-mount-main.cc
@@ -0,0 +1,224 @@
+/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include <sbuild/sbuild-mntstream.h>
+
+#include "schroot-mount-main.h"
+
+#include <cerrno>
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <locale>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <boost/format.hpp>
+
+#include <mntent.h>
+
+#include <lockdev.h>
+
+using std::endl;
+using boost::format;
+using sbuild::_;
+using sbuild::N_;
+using namespace schroot_mount;
+
+namespace
+{
+
+  typedef std::pair<main::error_code,const char *> emap;
+
+  /**
+   * This is a list of the supported error codes.  It's used to
+   * construct the real error codes map.
+   */
+  emap init_errors[] =
+    {
+      emap(main::CHILD_FORK, N_("Failed to fork child")),
+      emap(main::CHILD_WAIT, N_("Wait for child failed")),
+      // TRANSLATORS: %1% = command name
+      emap(main::EXEC,       N_("Failed to execute '%1%'"))
+    };
+
+}
+
+template<>
+sbuild::error<main::error_code>::map_type
+sbuild::error<main::error_code>::error_strings
+(init_errors,
+ init_errors + (sizeof(init_errors) / sizeof(init_errors[0])));
+
+main::main (options::ptr& options):
+  schroot_base::main("schroot-mount",
+		     // TRANSLATORS: '...' is an ellipsis e.g. U+2026,
+		     // and '-' is an em-dash.
+		     _("[OPTION...] - mount filesystems"),
+		     options,
+		     false),
+  opts(options)
+{
+}
+
+main::~main ()
+{
+}
+
+void
+main::action_mount ()
+{
+  // Check mounts.
+  sbuild::mntstream mounts(opts->fstab);
+
+  sbuild::mntstream::mntentry entry;
+
+  while (mounts >> entry)
+    {
+      std::string directory(opts->mountpoint + entry.directory);
+
+      std::cout << boost::format("Mounting '%1%' on '%2%'")
+	% entry.filesystem_name
+	% directory
+		<< std::endl;
+
+      if (!opts->dry_run)
+	{
+	  sbuild::string_list command;
+	  command.push_back("/bin/mount");
+	  if (opts->verbose)
+	    command.push_back("-v");
+	  command.push_back("-t");
+	  command.push_back(entry.type);
+	  command.push_back("-o");
+	  command.push_back(entry.options);
+	  command.push_back(entry.filesystem_name);
+	  command.push_back(directory);
+
+	  int status = run_child(command[0], command, sbuild::environment());
+
+	  if (status)
+	    exit(status);
+	}
+    }
+}
+
+int
+main::run_child (std::string const& file,
+		 sbuild::string_list const& command,
+		 sbuild::environment const& env)
+{
+  int exit_status = 0;
+  pid_t pid;
+
+  if ((pid = fork()) == -1)
+    {
+      throw error(CHILD_FORK, strerror(errno));
+    }
+  else if (pid == 0)
+    {
+      try
+	{
+	  sbuild::log_debug(sbuild::DEBUG_INFO)
+	    << "mount_main: executing "
+	    << sbuild::string_list_to_string(command, ", ")
+	    << std::endl;
+	  if (opts->verbose)
+	    // TRANSLATORS: %1% = command
+	    sbuild::log_info() << format(_("Executing '%1%'"))
+	      % sbuild::string_list_to_string(command, " ")
+			       << std::endl;
+	  exec(file, command, env);
+	  error e(file, EXEC, strerror(errno));
+	  sbuild::log_exception_error(e);
+	}
+      catch (std::exception const& e)
+	{
+	  sbuild::log_exception_error(e);
+	}
+      catch (...)
+	{
+	  sbuild::log_error()
+	    << _("An unknown exception occurred") << std::endl;
+	}
+      _exit(EXIT_FAILURE);
+    }
+  else
+    {
+      wait_for_child(pid, exit_status);
+    }
+
+  if (exit_status)
+    sbuild::log_debug(sbuild::DEBUG_INFO)
+      << "mount_main: " << file
+      << " failed with status " << exit_status
+      << std::endl;
+  else
+    sbuild::log_debug(sbuild::DEBUG_INFO)
+      << "mount_main: " << file
+      << " succeeded"
+      << std::endl;
+
+  return exit_status;
+}
+
+void
+main::wait_for_child (pid_t pid,
+		      int&  child_status)
+{
+  child_status = EXIT_FAILURE; // Default exit status
+
+  int status;
+
+  while (1)
+    {
+      if (waitpid(pid, &status, 0) == -1)
+	{
+	  if (errno == EINTR)
+	    continue; // Wait again.
+	  else
+	    throw error(CHILD_WAIT, strerror(errno));
+	}
+      else
+	break;
+    }
+
+  if (WIFEXITED(status))
+    child_status = WEXITSTATUS(status);
+}
+
+int
+main::run_impl ()
+{
+  if (this->opts->action == options::ACTION_HELP)
+    action_help(std::cerr);
+  else if (this->opts->action == options::ACTION_VERSION)
+    action_version(std::cerr);
+  else if (this->opts->action == options::ACTION_MOUNT)
+    action_mount();
+  else
+    assert(0); // Invalid action.
+
+  return EXIT_SUCCESS;
+}
diff --git a/bin/schroot-mount/schroot-mount-main.h b/bin/schroot-mount/schroot-mount-main.h
new file mode 100644
index 0000000..6540c65
--- /dev/null
+++ b/bin/schroot-mount/schroot-mount-main.h
@@ -0,0 +1,114 @@
+/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#ifndef SCHROOT_MOUNT_MAIN_H
+#define SCHROOT_MOUNT_MAIN_H
+
+#include <schroot-base/schroot-base-main.h>
+
+#include <schroot-mount/schroot-mount-options.h>
+
+#include <sbuild/sbuild-custom-error.h>
+
+namespace schroot_mount
+{
+
+  /**
+   * Frontend for schroot-mount.  This class is used to "run" schroot-mount.
+   */
+  class main : public schroot_base::main
+  {
+  public:
+    /// Error codes.
+    enum error_code
+      {
+	CHILD_FORK, ///< Failed to fork child.
+	CHILD_WAIT, ///< Wait for child failed.
+	EXEC        ///< Failed to execute.
+      };
+
+    /// Exception type.
+    typedef sbuild::custom_error<error_code> error;
+
+    /**
+     * The constructor.
+     *
+     * @param options the command-line options to use.
+     */
+    main (options::ptr& options);
+
+    /// The destructor.
+    virtual ~main ();
+
+  private:
+    /**
+     * Mount filesystems.
+     */
+    virtual void
+    action_mount ();
+
+    /**
+     * Run the command specified by file (an absolute pathname), using
+     * command and env as the argv and environment, respectively.
+     *
+     * @param file the program to execute.
+     * @param command the arguments to pass to the executable.
+     * @param env the environment.
+     * @returns the return value of the execve system call on failure.
+     */
+    int
+    run_child(std::string const& file,
+	      sbuild::string_list const& command,
+	      sbuild::environment const& env);
+
+    /**
+     * Wait for a child process to complete, and check its exit status.
+     *
+     * An error will be thrown on failure.
+     *
+     * @param pid the pid to wait for.
+     * @param child_status the place to store the child exit status.
+     */
+    void
+    wait_for_child (pid_t pid,
+		    int&  child_status);
+
+  protected:
+    /**
+     * Run the program.
+     *
+     * @returns 0 on success, 1 on failure or the exit status of the
+     * chroot command.
+     */
+    virtual int
+    run_impl ();
+
+  private:
+    /// The program options.
+    options::ptr opts;
+  };
+
+}
+
+#endif /* SCHROOT_MOUNT_MAIN_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */
diff --git a/bin/schroot-mount/schroot-mount-options.cc b/bin/schroot-mount/schroot-mount-options.cc
new file mode 100644
index 0000000..a0719a9
--- /dev/null
+++ b/bin/schroot-mount/schroot-mount-options.cc
@@ -0,0 +1,103 @@
+/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include <sbuild/sbuild-i18n.h>
+#include <sbuild/sbuild-util.h>
+
+#include "schroot-mount-options.h"
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/format.hpp>
+#include <boost/program_options.hpp>
+
+using std::endl;
+using boost::format;
+using sbuild::_;
+namespace opt = boost::program_options;
+using namespace schroot_mount;
+
+const options::action_type options::ACTION_MOUNT ("mount");
+
+options::options ():
+  schroot_base::options(),
+  dry_run(false),
+  fstab(),
+  mountpoint(),
+  mount(_("Mount"))
+{
+}
+
+options::~options ()
+{
+}
+
+void
+options::add_options ()
+{
+  // Chain up to add basic options.
+  schroot_base::options::add_options();
+
+  action.add(ACTION_MOUNT);
+  action.set_default(ACTION_MOUNT);
+
+
+  mount.add_options()
+    ("dry-run,d",
+     _("Perform a simulation of actions which would be taken"))
+    ("fstab,f", opt::value<std::string>(&this->fstab),
+     _("fstab file to read (full path)"))
+    ("mountpoint,m", opt::value<std::string>(&this->mountpoint),
+     _("Mountpoint to check (full path)"));
+}
+
+void
+options::add_option_groups ()
+{
+  // Chain up to add basic option groups.
+  schroot_base::options::add_option_groups();
+
+#ifndef BOOST_PROGRAM_OPTIONS_DESCRIPTION_OLD
+  if (!mount.options().empty())
+#else
+  if (!mount.primary_keys().empty())
+#endif
+    {
+      visible.add(mount);
+      global.add(mount);
+    }
+}
+
+void
+options::check_options ()
+{
+  // Chain up to check basic options.
+  schroot_base::options::check_options();
+
+  if (vm.count("dry-run"))
+    this->dry_run = true;
+
+  this->mountpoint = sbuild::normalname(this->mountpoint);
+
+  if (this->action == ACTION_MOUNT &&
+      this->mountpoint.empty())
+    throw opt::validation_error(_("No mount point specified"));
+}
diff --git a/bin/schroot-mount/schroot-mount-options.h b/bin/schroot-mount/schroot-mount-options.h
new file mode 100644
index 0000000..c1581dc
--- /dev/null
+++ b/bin/schroot-mount/schroot-mount-options.h
@@ -0,0 +1,78 @@
+/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#ifndef SCHROOT_MOUNT_OPTIONS_H
+#define SCHROOT_MOUNT_OPTIONS_H
+
+#include <schroot-base/schroot-base-options.h>
+
+#include <string>
+
+namespace schroot_mount
+{
+
+  /**
+   * schroot-mount command-line options.
+   */
+  class options : public schroot_base::options
+  {
+  public:
+    /// A shared_ptr to an options object.
+    typedef std::tr1::shared_ptr<options> ptr;
+
+    /// Begin, run and end a session.
+    static const action_type ACTION_MOUNT;
+
+    /// The constructor.
+    options ();
+
+    /// The destructor.
+    virtual ~options ();
+
+    /// Dry run.
+    bool dry_run;
+
+    /// The fstab to read.
+    std::string fstab;
+
+    /// The mountpoint to check.
+    std::string mountpoint;
+
+  protected:
+    virtual void
+    add_options ();
+
+    virtual void
+    add_option_groups ();
+
+    virtual void
+    check_options ();
+
+    /// Mount options group.
+    boost::program_options::options_description mount;
+  };
+
+}
+
+#endif /* SCHROOT_MOUNT_OPTIONS_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */
diff --git a/bin/schroot-mount/schroot-mount.cc b/bin/schroot-mount/schroot-mount.cc
new file mode 100644
index 0000000..671d4ba
--- /dev/null
+++ b/bin/schroot-mount/schroot-mount.cc
@@ -0,0 +1,47 @@
+/* Copyright © 2005-2007  Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "schroot-mount-options.h"
+#include "schroot-mount-main.h"
+
+#include <schroot-base/schroot-base-run.h>
+
+using std::endl;
+using boost::format;
+namespace opt = boost::program_options;
+
+using namespace schroot_mount;
+
+/**
+ * Main routine.
+ *
+ * @param argc the number of arguments
+ * @param argv argument vector
+ *
+ * @returns 0 on success, 1 on failure or the exit status of the
+ * chroot command.
+ */
+int
+main (int   argc,
+      char *argv[])
+{
+  return schroot_base::run
+    <schroot_mount::options, schroot_mount::main>(argc, argv);
+}
diff --git a/bin/schroot/mount.defaults b/bin/schroot/mount.defaults
new file mode 100644
index 0000000..522e91e
--- /dev/null
+++ b/bin/schroot/mount.defaults
@@ -0,0 +1,10 @@
+# mount.defaults: static file system information for chroots.
+# Note that the mount point will be prefixed by the chroot path
+# (CHROOT_PATH)
+#
+# <file system>	<mount point>	<type>	<options>	<dump>	<pass>
+proc		/proc		proc	defaults	0	0
+/dev/pts	/dev/pts	none	rw,bind		0	0
+tmpfs		/dev/shm	tmpfs	defaults	0	0
+/home		/home		none	rw,bind		0	0
+/tmp		/tmp		none	rw,bind		0	0
diff --git a/bin/schroot/setup/20network b/bin/schroot/setup/20network
index 07212bc..3529bbd 100755
--- a/bin/schroot/setup/20network
+++ b/bin/schroot/setup/20network
@@ -26,6 +26,7 @@ if [ "$AUTH_VERBOSITY" = "verbose" ]; then
 fi
 
 if [ $1 = "setup-start" ] || [ $1 = "setup-recover" ]; then
+  cp $VERBOSE /etc/hosts "${CHROOT_PATH}/etc/hosts"
   cp $VERBOSE /etc/resolv.conf "${CHROOT_PATH}/etc/resolv.conf"
 fi
 
diff --git a/configure.ac b/configure.ac
index 43492b2..2b4cbb5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -455,6 +455,7 @@ AC_CONFIG_FILES([bin/schroot/schroot.1])
 AC_CONFIG_FILES([bin/schroot/schroot-setup.5])
 AC_CONFIG_FILES([bin/schroot/schroot.conf.5])
 AC_CONFIG_FILES([bin/schroot-listmounts/Makefile])
+AC_CONFIG_FILES([bin/schroot-mount/Makefile])
 AC_CONFIG_FILES([bin/schroot-releaselock/Makefile])
 AC_CONFIG_FILES([bin/dchroot/Makefile])
 AC_CONFIG_FILES([bin/dchroot/dchroot.1])
diff --git a/doc/.gitignore b/doc/.gitignore
index d1fe64d..f400853 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -6,3 +6,5 @@ schroot-stamp
 schroot.dox
 schroot.log
 schroot
+*.pdf
+*.ps
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8f544b8..dbb3d10 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,6 +21,7 @@ sbuild/sbuild-lock.cc
 sbuild/sbuild-chroot-lvm-snapshot.cc
 sbuild/sbuild-types.cc
 sbuild/sbuild-keyfile-base.cc
+sbuild/sbuild-mntstream.cc
 sbuild/sbuild-null.cc
 sbuild/sbuild-log.cc
 sbuild/sbuild-util.cc
@@ -55,3 +56,6 @@ bin/dchroot-dsa/dchroot-dsa-options.cc
 bin/schroot-releaselock/schroot-releaselock-main.cc
 bin/schroot-releaselock/schroot-releaselock-options.cc
 bin/schroot-releaselock/schroot-releaselock.cc
+bin/schroot-mount/schroot-mount.cc
+bin/schroot-mount/schroot-mount-main.cc
+bin/schroot-mount/schroot-mount-options.cc
diff --git a/sbuild/Makefile.am b/sbuild/Makefile.am
index 4c86a92..e8fa41e 100644
--- a/sbuild/Makefile.am
+++ b/sbuild/Makefile.am
@@ -54,6 +54,7 @@ sbuild_public_h_sources =		\
 	sbuild-keyfile.h		\
 	sbuild-lock.h			\
 	sbuild-log.h			\
+	sbuild-mntstream.h		\
 	sbuild-nostream.h		\
 	sbuild-null.h			\
 	sbuild-parse-error.h		\
@@ -86,6 +87,7 @@ sbuild_public_cc_sources =		\
 	sbuild-keyfile-base.cc		\
 	sbuild-lock.cc			\
 	sbuild-log.cc			\
+	sbuild-mntstream.cc		\
 	sbuild-nostream.cc		\
 	sbuild-null.cc			\
 	sbuild-parse-value.cc		\
diff --git a/sbuild/sbuild-mntstream.cc b/sbuild/sbuild-mntstream.cc
new file mode 100644
index 0000000..c605129
--- /dev/null
+++ b/sbuild/sbuild-mntstream.cc
@@ -0,0 +1,184 @@
+/* Copyright © 2003,2006-2008  Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "sbuild-mntstream.h"
+
+#include <cerrno>
+#include <cstring>
+
+using namespace sbuild;
+
+namespace
+{
+
+  typedef std::pair<mntstream::error_code,const char *> emap;
+
+  /**
+   * This is a list of the supported error codes.  It's used to
+   * construct the real error codes map.
+   */
+  emap init_errors[] =
+    {
+      // TRANSLATORS: %1% = mount file name
+      emap(mntstream::MNT_OPEN,    N_("Failed to open mount file '%1%'")),
+      // TRANSLATORS: %1% = mount file name
+      emap(mntstream::MNT_READ,    N_("Failed to read mount file '%1%'"))
+    };
+
+}
+
+template<>
+error<mntstream::error_code>::map_type
+error<mntstream::error_code>::error_strings
+(init_errors,
+ init_errors + (sizeof(init_errors) / sizeof(init_errors[0])));
+
+
+mntstream::mntentry::mntentry (struct mntent const&  entry):
+  filesystem_name(entry.mnt_fsname),
+  directory(entry.mnt_dir),
+  type(entry.mnt_type),
+  options(entry.mnt_opts),
+  dump_frequency(entry.mnt_freq),
+  fsck_pass(entry.mnt_passno)
+{
+}
+
+
+mntstream::mntstream(std::string const& file):
+  file(),
+  mntfile(0),
+  data(),
+  error_status(true),
+  eof_status(true)
+{
+  open(file);
+}
+
+
+mntstream::~mntstream()
+{
+  close();
+}
+
+void
+mntstream::open(std::string const& file)
+{
+  this->mntfile = setmntent(file.c_str(), "r");
+  if (this->mntfile == 0)
+    {
+      this->file.clear();
+      this->error_status = true;
+      this->eof_status = true;
+      throw error(file, MNT_OPEN, strerror(errno));
+    }
+  this->file = file;
+  this->error_status = false;
+  this->eof_status = false;
+  read();
+}
+
+void
+mntstream::read(int quantity)
+{
+  int i;
+
+  if (this->mntfile == 0)
+    return;
+
+  for (i = 0; i < quantity; ++i)
+    {
+      struct mntent* entry;
+      errno = 0;
+      entry = getmntent(mntfile);
+
+      if (entry == 0) // EOF or error
+	{
+	  //std::cerr << "Mount file read error: ";
+	  if (errno) // error
+	    {
+	      this->error_status = true;
+	      throw error(this->file, MNT_READ, strerror(errno));
+	    }
+	  return;
+	}
+
+      mntentry newentry(*entry); // make a mntentry
+      this->data.push_back(newentry); // push onto the end of the list
+    }
+}
+
+void
+mntstream::close()
+{
+  if (this->mntfile)
+    endmntent(this->mntfile); // don't throw an exception on failure
+			      // -- it could be called in the
+			      // destructor
+  this->mntfile = 0;
+  this->data.clear();    // clear all data
+  this->file.clear();
+  this->error_status = true;
+  this->eof_status = true;
+}
+
+
+bool
+mntstream::eof() const
+{
+  return this->eof_status;
+}
+
+bool
+mntstream::bad() const
+{
+  return this->error_status;
+}
+
+mntstream::operator bool ()
+{
+  return !(bad() || eof());
+}
+
+bool
+mntstream::operator ! ()
+{
+  return bad() || eof();
+}
+
+
+mntstream&
+sbuild::operator >> (mntstream&            stream,
+		     mntstream::mntentry&  entry)
+{
+  stream.read(); // read a new entry
+  if (stream && !stream.data.empty()) // not at end of file or bad.
+    {
+      entry = stream.data.front(); // assign next mntentry to entry
+      stream.data.pop_front(); // remove the entry
+    }
+  else // blank the mntentry and set EOF status
+    {
+      entry = mntstream::mntentry();
+      stream.eof_status = true;
+    }
+
+  return stream;
+}
diff --git a/sbuild/sbuild-mntstream.h b/sbuild/sbuild-mntstream.h
new file mode 100644
index 0000000..1acda19
--- /dev/null
+++ b/sbuild/sbuild-mntstream.h
@@ -0,0 +1,214 @@
+/* Copyright © 2003,2006-2008  Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#ifndef SBUILD_MNTSTREAM_H
+#define SBUILD_MNTSTREAM_H
+
+#include <sbuild/sbuild-custom-error.h>
+
+#include <iostream>
+#include <deque>
+#include <string>
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <mntent.h>
+
+namespace sbuild
+{
+
+  /**
+   * Access mounts.  This is a wrapper around the setmntent(3),
+   * getmntent(3) and endmntent(3) functions, which are used to read a
+   * stream of "mntents" through multiple getmntent() calls.
+   *
+   * mntstream calls setmntent() and endmntent() automatically, and
+   * represents each mntent as a mntstream::mntentry.  Like reading
+   * from and istream by pulling data out with the >> "extraction
+   * operator", mntentries are also extracted from the mntstream with
+   * the >> operator.
+   */
+  class mntstream
+    {
+    public:
+      /// Error codes.
+      enum error_code
+	{
+	  MNT_OPEN, ///< Failed to open mount file.
+	  MNT_READ  ///< Failed to read mount file.
+	};
+
+      /// Exception type.
+      typedef sbuild::custom_error<error_code> error;
+
+      /**
+       * An entry in a mntstream.  It is a wrapper around the mntent
+       * structure declared in mntent.h.  Unlike a mntent pointer returned
+       * by getmntent(3), a mntentry does not become invalid when the
+       * mntstream it was extracted from is destroyed.
+       */
+      struct mntentry
+      {
+	/// The constructor.
+	mntentry ()
+	{};
+
+	/**
+	 * The contructor.
+	 *
+	 * @param
+	 */
+	mntentry (struct mntent const&  entry);
+
+	/// Name of mounted filesystem.
+	std::string  filesystem_name;
+	/// File system path prefix.
+	std::string  directory;
+	/// Mount type.
+	std::string  type;
+	/// Mount options.
+	std::string  options;
+	/// Dump frequency (days).
+	int          dump_frequency;
+	/// Parallel fsck pass number.
+	int          fsck_pass;
+      };
+
+      /**
+       * The constructor.
+       *
+       * @param file the file to read.
+       */
+      mntstream(std::string const& file);
+
+      /// The destructor.
+      virtual ~mntstream();
+
+      /**
+       * Open a mount file for reading.  This uses the openmnt(3) call
+       * to open the underlying FILE stream.  Any previously open
+       * mount file is closed before opening the new one.  The
+       * mntstream error state is set if the open fails, and an
+       * exception will be thrown.
+       *
+       * @param file the file to read.
+       * @see close()
+       */
+      void open(std::string const& file);
+
+      /**
+       * Close the mount file.  This uses the closemnt(3) call to
+       * close the underlying FILE stream.  All cached data is deleted
+       * and the error state set until open() is called.
+       *
+       * @see open()
+       */
+      void close();
+
+      /**
+       * Check for End Of File.  Note that the end of file status is
+       * only set adter a read fails, so this should be checked after
+       * each read.
+       *
+       * @returns true if the mntstream is empty, otherwise false.
+       */
+      bool eof() const;
+
+      /**
+       * Check for errors.  If there is an error, the mntstream is
+       * unusable until the next open() call.
+       *
+       * @returns true if the mntstream is in an error state, otherwise
+       * false.
+       */
+      bool bad() const;
+
+      /**
+       * Check if the mntstream status is good.
+       *
+       * @returns true if the status is good (eof() and bad() both
+       * return false).
+       */
+      operator bool ();
+
+      /**
+       * Check if the mntstream status is bad.
+       *
+       * @returns true if the status is bad (eof() or bad() return
+       * true).
+       */
+      bool
+      operator ! ();
+
+      friend mntstream&
+      operator >> (mntstream& stream,
+		   mntentry&  entry);
+
+    private:
+      /**
+       * Read mntents from the underlying FILE stream into the data
+       * deque.  If the read fails, the error state will be set, and
+       * an exception will be thrown.
+       *
+       * @param quantity the number of mntents to read.
+       *
+       * @todo Add mntentry constructor to do automatic struct mntent
+       * to mntentry conversion.
+       */
+      void read (int quantity=1);
+
+      /// The file name.
+      std::string file;
+
+      /// The underlying FILE stream.
+      FILE *mntfile;
+
+      /**
+       * A list of mntentries represents the mount file stream as a
+       * LIFO stack.
+       */
+      std::deque<mntentry> data;
+
+      /// Error status.
+      bool error_status;
+
+      /// End of File status.
+      bool eof_status;
+  };
+
+  /**
+   * The overloaded extraction operator.  This is used to pull
+   * mntentries from a mntstream.
+   *
+   * @param stream the mntstream to get input from.
+   * @param entry the mntentry to set.
+   * @returns the mntstream.
+   */
+  mntstream&
+  operator >> (mntstream&            stream,
+	       mntstream::mntentry&  entry);
+
+}
+
+#endif /* SBUILD_MNTSTREAM_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
[signature.asc (application/pgp-signature, inline)]

Merged 395062 427047. Request was from Roger Leigh <rleigh@whinlatter.ukfsn.org> to control@bugs.debian.org. (Sat, 12 Jan 2008 15:54:03 GMT) (full text, mbox, link).


Tags added: pending Request was from Roger Leigh <rleigh@whinlatter.ukfsn.org> to control@bugs.debian.org. (Sat, 12 Jan 2008 15:54:04 GMT) (full text, mbox, link).


Reply sent to Roger Leigh <rleigh@debian.org>:
You have taken responsibility. (full text, mbox, link).


Notification sent to Kees Cook <kees@outflux.net>:
Bug acknowledged by developer. (full text, mbox, link).


Message #49 received at 395062-close@bugs.debian.org (full text, mbox, reply):

From: Roger Leigh <rleigh@debian.org>
To: 395062-close@bugs.debian.org
Subject: Bug#395062: fixed in schroot 1.1.6-1
Date: Mon, 21 Jan 2008 02:02:05 +0000
Source: schroot
Source-Version: 1.1.6-1

We believe that the bug you reported is fixed in the latest version of
schroot, which is due to be installed in the Debian FTP archive:

dchroot-dsa_1.1.6-1_powerpc.deb
  to pool/main/s/schroot/dchroot-dsa_1.1.6-1_powerpc.deb
dchroot_1.1.6-1_powerpc.deb
  to pool/main/s/schroot/dchroot_1.1.6-1_powerpc.deb
libsbuild-dev_1.1.6-1_powerpc.deb
  to pool/main/s/schroot/libsbuild-dev_1.1.6-1_powerpc.deb
libsbuild-doc_1.1.6-1_all.deb
  to pool/main/s/schroot/libsbuild-doc_1.1.6-1_all.deb
schroot-common_1.1.6-1_all.deb
  to pool/main/s/schroot/schroot-common_1.1.6-1_all.deb
schroot_1.1.6-1.diff.gz
  to pool/main/s/schroot/schroot_1.1.6-1.diff.gz
schroot_1.1.6-1.dsc
  to pool/main/s/schroot/schroot_1.1.6-1.dsc
schroot_1.1.6-1_powerpc.deb
  to pool/main/s/schroot/schroot_1.1.6-1_powerpc.deb
schroot_1.1.6.orig.tar.gz
  to pool/main/s/schroot/schroot_1.1.6.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 395062@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Roger Leigh <rleigh@debian.org> (supplier of updated schroot package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.7
Date: Sun, 20 Jan 2008 22:51:04 +0000
Source: schroot
Binary: schroot-common libsbuild-dev dchroot-dsa dchroot libsbuild-doc schroot
Architecture: source all powerpc
Version: 1.1.6-1
Distribution: unstable
Urgency: low
Maintainer: Debian buildd-tools Developers <buildd-tools-devel@lists.alioth.debian.org>
Changed-By: Roger Leigh <rleigh@debian.org>
Description: 
 dchroot    - Execute commands in a chroot environment
 dchroot-dsa - Execute commands in a chroot environment
 libsbuild-dev - development files for the Debian source builder
 libsbuild-doc - development documentation for the Debian source builder
 schroot    - Execute commands in a chroot environment
 schroot-common - common files for schroot
Closes: 395062 427047 428808 439215 452263 459658 461531
Changes: 
 schroot (1.1.6-1) unstable; urgency=low
 .
   * New upstream development release.
   * Acknowledge NMU.  Thanks to Lucas Nussbaum for fixing the Boost
     library names following another incompatible change in Boost
     (Closes: #439215).
   * debian/control: Suggest lvm2 instead of lvm-common (Closes: #452263).
   * debian/copyright:
     - Update with new GIT source code repository location.
     - Update licence to GPLv3.
   * debian/schroot.init: Update licence to GPLv3.
   * bin/schroot/setup/20network, bin/schroot/setup/30passwd: For files to
     copy, compare file device, inode and contents to avoid copying
     identical files (Closes: #428808).
   * If unknown keys are present in the configuration file, print a warning
     message to alert the user (Closes: #459658).
   * The filesystems to mount in the chroot may be customised by the system
     administrator through the use of an fstab file on a per-chroot basis,
     and a new helper utility, schroot-mount (Closes: #395062, #427047).
     Thanks for your patience while we took the time to implement this the
     right way.
   * Update Vietnamese translation (Closes: #461531).  Thanks to Clytie
     Siddall.
   * debian/schroot.preinst: Add rm_conffile function to remove
     /etc/schroot/setup.d/20network and /etc/schroot/setup.d/30passwd for
     versions prior to this.  These are replaced by
     /etc/schroot/setup.d/20copyfiles.
   * debian/schroot.NEWS: Document conffile changes.
Files: 
 1e3c5e97bd9c8f711619b4805a4d6db3 1060 admin optional schroot_1.1.6-1.dsc
 8cccdc70578551e4834a085fedd3f668 6751813 admin optional schroot_1.1.6.orig.tar.gz
 69ffffebd33a8c8e9178dc40cefad48b 20 admin optional schroot_1.1.6-1.diff.gz
 5a539adcdc35042f8b06e070286b06d3 97504 admin optional schroot-common_1.1.6-1_all.deb
 38226c3b10d518390cb81c94009dab7f 3076468 doc optional libsbuild-doc_1.1.6-1_all.deb
 aefdb98e3b9c5a2e0a64e6fcffe34ed3 1233614 devel optional libsbuild-dev_1.1.6-1_powerpc.deb
 e4ee84549e00899e9b8ecaa1d3c24b36 685048 admin optional schroot_1.1.6-1_powerpc.deb
 495394c0991c216408893f076279b92d 312046 admin optional dchroot_1.1.6-1_powerpc.deb
 f2caeefb210cbd6c5d0c21a86454f853 311402 admin optional dchroot-dsa_1.1.6-1_powerpc.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHk/pZVcFcaSW/uEgRAmn7AJ4gUQnhhAnh3jLRs6A1HDiIQEFnrgCfS2CV
yptvKC+tgtumI1htQ3AYo58=
=VlpL
-----END PGP SIGNATURE-----





Reply sent to Roger Leigh <rleigh@debian.org>:
You have taken responsibility. (full text, mbox, link).


Notification sent to Peter Rabbitson <rabbit@rabbit.us>:
Bug acknowledged by developer. (full text, mbox, link).


Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Wed, 05 Mar 2008 07:30:32 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Fri Jan 5 13:04:32 2018; Machine Name: beach

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.