[Buildd-tools-devel] Bug#427047: Bug#427047: Not found on recent version or svn.

Roger Leigh rleigh at whinlatter.ukfsn.org
Wed Jan 9 23:42:31 UTC 2008


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 at 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 at 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 at debian.org>
+
+	* TODO: Add new items.
+
+2008-01-09  Roger Leigh  <rleigh at 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 at 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 at debian.org>
+
+	* doc/.gitignore: Ignore *.pdf and *.ps.
+
+2008-01-08  Roger Leigh  <rleigh at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/buildd-tools-devel/attachments/20080109/ebab4ebb/attachment-0003.pgp 


More information about the Buildd-tools-devel mailing list