[Buildd-tools-devel] Bug#354513: schroot: Allow all commands run in a chroot to be prefixed with another command

Roger Leigh rleigh at debian.org
Mon Feb 27 00:00:23 UTC 2006


Package: schroot
Version: 0.2.5-1
Severity: wishlist
Tags: patch

For linux32 support on 64-bit arches, it would be nice if all commands
run inside the chroot could be prefixed with "linux32".  This could be
implemented more generally by adding the ability to prefix a command
with a custom command on a per-chroot basis, by adding a
"command-prefix" to the configuration file.

A patch is attached to implement this option.


<vorlon> rleigh: hiya. next wishlist bug: a "wrapper" command that's
prepended to whatever command is being executed in the chroot, so that
e.g., I can get a linux32 execution domain on amd64, or a sparc32
execution domain on sparc, associated with a particular chroot/chroot
config. :)
<rleigh> vorlon: Patches welcome! :)
<rleigh> vorlon: Not having a suitable arch to test, how does this work
currently, when doing it "by hand"?
<vorlon> rleigh: you can do either "linux32 schroot foo", or "schroot
linux32 foo"; the first obviously depends on the linux32 command being
present in the main root, the second on it being present in the chroot
<rleigh> vorlon: Which situation is the most common?
<vorlon> <shrug>? :)
<fs> the first
<fs> I would go with the first option, you likely have linux32 on your
main system or in main chroot 
<fs> but not in cleanroom chroots to build packages
<fs> additionally you could have dchroot depend on linux32
<fs> if you had to have linux32 installed in the chroot you want to
switch into, how could you express that in a dependecy?
<rleigh> This could be supported very generally, by adding a command in
the config file to prepend to each command run inside the chroot.  The
syntax would require each argv parameter delimited by a comma: e.g.
"command-prefix=linux32,option1,option2"; we can then simply concatenate
it with the real argv.  This would require it to be inside the chroot,
though.  For the external linux32, I'm not sure you can make it even
simpler than "linux32 schro
<rleigh> ot"; what would you want in this case?
<Zomb> well, maybe stupid question, but shouldn't we setup multiarch
first?
<vorlon> fs: eh, if the wrapper command is outside the chroot, you're
stuck doing silly things like having schroot re-exec itself
<vorlon> rleigh: yeah, I figure putting linux32 in my chroots is the
easiest way to make that work
<fs> vorlon: good point
<fs> rleigh: a command prefox options like that one could fix the
problems a shell wrapper using "$@" bears
<fs> prefix, even
<rleigh> I can add such an option quite easily (and it would be
generally useful for other things as well).  For anything more involved
than that, I can't really do much, since I have no knowledge of how any
of the linux32 stuff works; someone more knowledgeable than me would
need to look at that.



-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (990, 'unstable')
Architecture: powerpc (ppc)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.15.4
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)

Versions of packages schroot depends on:
ii  libboost-prog 1.33.1-2                   program options library for C++
ii  libc6         2.3.6-2                    GNU C Library: Shared libraries an
ii  libgcc1       1:4.0.2-9                  GCC support library
ii  liblockdev1   1.0.2-1                    Run-time shared library for lockin
ii  libpam0g      0.79-3.1                   Pluggable Authentication Modules l
ii  libstdc++6    4.0.2-9                    The GNU Standard C++ Library v3
ii  libuuid1      1.38+1.39-WIP-2005.12.31-1 universally unique id library

schroot recommends no packages.

-- no debconf information
-------------- next part --------------
? schroot/sbuild-sourcedeps.cc
? schroot/sbuild-sourcedeps.h
Index: ChangeLog
===================================================================
RCS file: /cvsroot/buildd-tools/schroot/ChangeLog,v
retrieving revision 1.252
diff -u -r1.252 ChangeLog
--- ChangeLog	26 Feb 2006 21:48:49 -0000	1.252
+++ ChangeLog	26 Feb 2006 23:58:46 -0000
@@ -1,5 +1,22 @@
 2006-02-26  Roger Leigh  <rleigh at debian.org>
 
+	* schroot/schroot.conf.5.in: Document "command-prefix" option.
+
+	* schroot/sbuild-session.cc
+	(run_child): Concatenate command_prefix and command to get the
+	command to run in the chroot.
+
+	* schroot/sbuild-chroot.cc
+	(get_command_prefix): New method to get command prefix.
+	(set_command_prefix): New method to set command prefix.
+	(print_details): Display command_prefix if set.
+	(get_keyfile): Set command-prefix in keyfile.
+	(set_keyfile): Get command-prefix from keyfile.
+
+	* schroot/sbuild-chroot.h: New member command_prefix.
+
+2006-02-26  Roger Leigh  <rleigh at debian.org>
+
 	* Version 0.2.5.
 
 	* configure.ac: Update for 0.2.5.
Index: schroot/sbuild-chroot.cc
===================================================================
RCS file: /cvsroot/buildd-tools/schroot/schroot/sbuild-chroot.cc,v
retrieving revision 1.31
diff -u -r1.31 sbuild-chroot.cc
--- schroot/sbuild-chroot.cc	26 Feb 2006 21:48:49 -0000	1.31
+++ schroot/sbuild-chroot.cc	26 Feb 2006 23:58:46 -0000
@@ -41,7 +41,8 @@
   mount_device(),
   active(false),
   run_setup_scripts(false),
-  run_session_scripts(false)
+  run_session_scripts(false),
+  command_prefix()
 {
 }
 
@@ -225,6 +226,18 @@
   this->run_session_scripts = run_session_scripts;
 }
 
+string_list const&
+sbuild::chroot::get_command_prefix () const
+{
+  return this->command_prefix;
+}
+
+void
+sbuild::chroot::set_command_prefix (string_list const& command_prefix)
+{
+  this->command_prefix = command_prefix;
+}
+
 void
 sbuild::chroot::setup_env (environment& env)
 {
@@ -318,6 +331,9 @@
 			   static_cast<bool>(get_session_flags() &
 					     chroot::SESSION_CREATE));
 
+  if (!get_command_prefix().empty())
+    stream << format_details(_("Command Prefix"), get_command_prefix());
+
   /* Non user-settable properties are listed last. */
   if (!get_location().empty())
     stream << format_details(_("Location"),
@@ -371,6 +387,9 @@
   if (get_active())
     keyfile.set_value(this->name, "mount-device",
 		      get_mount_device());
+
+  keyfile.set_list_value(this->name, "command-prefix",
+			 get_command_prefix());
 }
 
 void
@@ -431,6 +450,11 @@
 			keyfile::PRIORITY_OPTIONAL : keyfile::PRIORITY_DISALLOWED,
 			mount_device))
     set_mount_device(mount_device);
+
+  string_list command_prefix;
+  if (keyfile.get_list_value(this->name, "command-prefix",
+			     keyfile::PRIORITY_OPTIONAL, command_prefix))
+    set_command_prefix(command_prefix);
 }
 
 /*
Index: schroot/sbuild-chroot.h
===================================================================
RCS file: /cvsroot/buildd-tools/schroot/schroot/sbuild-chroot.h,v
retrieving revision 1.50
diff -u -r1.50 sbuild-chroot.h
--- schroot/sbuild-chroot.h	24 Feb 2006 20:26:07 -0000	1.50
+++ schroot/sbuild-chroot.h	26 Feb 2006 23:58:47 -0000
@@ -314,6 +314,24 @@
     set_run_session_scripts (bool run_session_scripts);
 
     /**
+     * Get the command_prefix for the chroot.  This is a command to
+     * prefix to any command run in the chroot.
+     *
+     * @returns the command prefix.
+     */
+    string_list const&
+    get_command_prefix () const;
+
+    /**
+     * Set the command_prefix for the chroot.  This is a command to
+     * prefix to any command run in the chroot.
+     *
+     * @param command_prefix the command prefix.
+     */
+    void
+    set_command_prefix (string_list const& command_prefix);
+
+    /**
      * Get the type of the chroot.
      *
      * @returns the chroot type.
@@ -559,6 +577,8 @@
     bool          run_setup_scripts;
     /// Run session setup scripts?
     bool          run_session_scripts;
+    /// Command prefix.
+    string_list   command_prefix;
   };
 
 }
Index: schroot/sbuild-session.cc
===================================================================
RCS file: /cvsroot/buildd-tools/schroot/schroot/sbuild-session.cc,v
retrieving revision 1.38
diff -u -r1.38 sbuild-session.cc
--- schroot/sbuild-session.cc	25 Feb 2006 12:06:20 -0000	1.38
+++ schroot/sbuild-session.cc	26 Feb 2006 23:58:47 -0000
@@ -667,7 +667,13 @@
   /* Run login shell */
   std::string file;
 
-  string_list command = get_command();
+  string_list command(session_chroot->get_command_prefix());
+  string_list const& command_suffix = get_command();
+  for (string_list::const_iterator pos = command_suffix.begin();
+       pos != command_suffix.end();
+       ++pos)
+    command.push_back(*pos);
+
   if (command.empty() ||
       command[0].empty()) // No command
     {
Index: schroot/schroot.conf.5.in
===================================================================
RCS file: /cvsroot/buildd-tools/schroot/schroot/schroot.conf.5.in,v
retrieving revision 1.29
diff -u -r1.29 schroot.conf.5.in
--- schroot/schroot.conf.5.in	25 Feb 2006 12:06:20 -0000	1.29
+++ schroot/schroot.conf.5.in	26 Feb 2006 23:58:48 -0000
@@ -74,7 +74,7 @@
 example, a chroot named \[lq]sid\[rq] might have an \[lq]unstable\[rq] alias
 for convenience.
 .TP
-.B run-setup-scripts=\fItrue\fP|\fIfalse\fP
+.B run\-setup\-scripts=\fItrue\fP|\fIfalse\fP
 Set whether chroot setup scripts will be run.  The default is not to run setup
 scripts (\[lq]false\[rq]), for safety reasons (so it won't clobber your passwd
 and other critical files).  The default for session-managed chroots
@@ -85,9 +85,15 @@
 true session management, because it does not make a copy of the chroot).  If
 your chroots are exclusively controlled by schroot, set to \[lq]true\[rq].
 .TP
-.B run-session-scripts=\fItrue\fP|\fIfalse\fP
+.B run\-session\-scripts=\fItrue\fP|\fIfalse\fP
 Set whether chroot session scripts will be run.  The default is are the same as
 for the \fIrun-setup-scripts\fP key.
+.TP
+.B command\-prefix=\fIcommand,option1,option2,...\fP
+A comma-separated list of a command and the options for the command.  This
+command and its options will be prefixed to all commands run inside the chroot.
+For example, if set to \[lq]linux32\[rq], this will cause all commands run in
+the chroot to have a \fBlinux32\fP prefix added.
 .SS
 Plain chroots
 .PP


More information about the Buildd-tools-devel mailing list