On Sat, Jan 23, 2010 at 06:39:51PM +0100, Aurelien Jarno wrote: > Please find below a patch to support GNU/kFreeBSD. I don't know how you > plan to deal with architecture specific changes in scripts, so I have > decided to just modify them in this patch. With it I have been able to > get schroot working in plain, directory, block device and loopback modes. > I haven't tested the other modes yet.
Thanks. I've updated schroot on the master branch using the following patch (it's several changes in git). Note this hasn't been tested yet; I'm really just looking for some review before I put it to use. I'll do some testing tomorrow when I have some more time to review it. It may need some further work, so I would appreciate your comments. I've updated the schroot build system (configure and makefiles) to allow different configuration files to be installed for different platforms. I've also introduced a PLATFORM variable into the setup scripts to allow conditional behaviour depending upon the platform. Using your patch, I've added in the appropriate conditional behaviour for a "freebsd" platform (both freebsd and kfreebsd-gnu). Note that the setup scripts are installed into /etc/schroot/default, not just into /etc/schroot. This is a change in addition to the portability changes, so if you manually set script-config in your chroot definitions, it might need adjusting (if not, it's automatic). 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.
diff --git a/configure.ac b/configure.ac index c54ad48..cc32de8 100644 --- a/configure.ac +++ b/configure.ac @@ -258,6 +258,7 @@ AC_SUBST([bashcompletiondir]) AC_PROG_CXX AC_LANG([C++]) ACX_PTHREAD([], [AC_MSG_ERROR([POSIX thread support is required for correct std::tr1::shared_ptr operation])]) +AC_CANONICAL_HOST AC_DISABLE_SHARED AC_ENABLE_STATIC AC_PROG_LIBTOOL @@ -277,6 +278,27 @@ if test "$enable_doxygen" = "yes" && test -z "$DOXYGEN"; then fi; AM_CONDITIONAL([BUILD_DOXYGEN], [test -n "$DOXYGEN" && test "$enable_doxygen" = "yes"]) + +# Check for host platform +AC_MSG_CHECKING([for supported host platform type]) +PLATFORM="generic" +case $host_os in + linux*): + PLATFORM="linux";; + freebsd* | k*bsd*-gnu) : + PLATFORM="freebsd";; +esac +AC_MSG_RESULT([$PLATFORM]) +AC_SUBST([PLATFORM], [$PLATFORM]) + +AM_CONDITIONAL([PLATFORM_GENERIC], [test "$PLATFORM" = "generic"]) +AM_CONDITIONAL([PLATFORM_LINUX], [test "$PLATFORM" = "linux"]) +AM_CONDITIONAL([PLATFORM_FREEBSD], [test "$PLATFORM" = "freebsd"]) + +AH_TEMPLATE(SBUILD_PLATFORM, [Platform type, used to modify run-time platform-specific behaviour]) +AC_DEFINE_UNQUOTED(SBUILD_PLATFORM, ["$PLATFORM"]) + + # Checks for libraries. PKG_CHECK_MODULES([UUID], [uuid], [AC_DEFINE(HAVE_UUID) @@ -755,6 +777,10 @@ AC_CONFIG_FILES([bin/dchroot/Makefile]) AC_CONFIG_FILES([bin/dchroot-dsa/Makefile]) AC_CONFIG_FILES([bin/csbuild/Makefile]) AC_CONFIG_FILES([etc/Makefile]) +AC_CONFIG_FILES([etc/default/Makefile]) +AC_CONFIG_FILES([etc/default/freebsd/Makefile]) +AC_CONFIG_FILES([etc/default/generic/Makefile]) +AC_CONFIG_FILES([etc/default/linux/Makefile]) AC_CONFIG_FILES([etc/pam/Makefile]) AC_CONFIG_FILES([etc/setup.d/Makefile]) AC_CONFIG_FILES([etc/bash_completion/Makefile]) diff --git a/etc/Makefile.am b/etc/Makefile.am index c09d370..b1effa4 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -21,15 +21,12 @@ include $(top_srcdir)/scripts/global.mk -SUBDIRS = pam setup.d bash_completion +SUBDIRS = pam default setup.d bash_completion pkgsysconfdir = $(PACKAGE_SYSCONF_DIR) + pkgsysconf_DATA = \ - schroot.conf \ - copyfiles-defaults \ - mount-defaults \ - nssdatabases-defaults \ - script-defaults + schroot.conf EXTRA_DIST = \ $(pkgsysconf_DATA) diff --git a/etc/copyfiles-defaults b/etc/copyfiles-defaults deleted file mode 100644 index 6bb4d96..0000000 --- a/etc/copyfiles-defaults +++ /dev/null @@ -1,2 +0,0 @@ -/etc/resolv.conf -/etc/gshadow diff --git a/etc/default/Makefile.am b/etc/default/Makefile.am new file mode 100644 index 0000000..7a81701 --- /dev/null +++ b/etc/default/Makefile.am @@ -0,0 +1,24 @@ +# schroot Makefile template +# +# +# Copyright © 2004-2009 Roger Leigh <rle...@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 + +SUBDIRS = generic freebsd linux diff --git a/etc/default/freebsd/Makefile.am b/etc/default/freebsd/Makefile.am new file mode 100644 index 0000000..0e11058 --- /dev/null +++ b/etc/default/freebsd/Makefile.am @@ -0,0 +1,36 @@ +# schroot Makefile template +# +# +# Copyright © 2004-2009 Roger Leigh <rle...@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 + +pkgsysconfdir = $(PACKAGE_SYSCONF_DIR)/default + +if PLATFORM_FREEBSD +SCRIPT_CONFIG = \ + copyfiles \ + fstab \ + nssdatabases +endif + +pkgsysconf_DATA = $(SCRIPT_CONFIG) + +EXTRA_DIST = \ + $(SCRIPT_CONFIG) diff --git a/etc/default/freebsd/copyfiles b/etc/default/freebsd/copyfiles new file mode 100644 index 0000000..6bb4d96 --- /dev/null +++ b/etc/default/freebsd/copyfiles @@ -0,0 +1,2 @@ +/etc/resolv.conf +/etc/gshadow diff --git a/etc/default/freebsd/fstab b/etc/default/freebsd/fstab new file mode 100644 index 0000000..de8b733 --- /dev/null +++ b/etc/default/freebsd/fstab @@ -0,0 +1,12 @@ +# 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 +#procbususb /proc/bus/usb usbfs defaults 0 0 +#/dev /dev none rw,bind 0 0 +/dev/pts /dev/pts none rw,bind 0 0 +/dev/shm /dev/shm none rw,bind 0 0 +/home /home none rw,bind 0 0 +/tmp /tmp none rw,bind 0 0 diff --git a/etc/default/freebsd/nssdatabases b/etc/default/freebsd/nssdatabases new file mode 100644 index 0000000..bfd5eea --- /dev/null +++ b/etc/default/freebsd/nssdatabases @@ -0,0 +1,7 @@ +passwd +shadow +group +services +protocols +networks +hosts diff --git a/etc/default/generic/Makefile.am b/etc/default/generic/Makefile.am new file mode 100644 index 0000000..b67c718 --- /dev/null +++ b/etc/default/generic/Makefile.am @@ -0,0 +1,40 @@ +# schroot Makefile template +# +# +# Copyright © 2004-2009 Roger Leigh <rle...@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 + +pkgsysconfdir = $(PACKAGE_SYSCONF_DIR)/default + +if PLATFORM_GENERIC +SCRIPT_CONFIG = \ + copyfiles \ + fstab \ + nssdatabases +endif + +SCRIPT_GLOBAL = \ + config + +pkgsysconf_DATA = $(SCRIPT_CONFIG) + +EXTRA_DIST = \ + $(SCRIPT_GLOBAL) \ + $(SCRIPT_CONFIG) diff --git a/etc/default/generic/config b/etc/default/generic/config new file mode 100644 index 0000000..afc9a38 --- /dev/null +++ b/etc/default/generic/config @@ -0,0 +1,11 @@ +# Default settings for chroot setup and exec scripts. +# See schroot-script-config(5) for further details. + +# Filesystems to mount inside the chroot. +FSTAB="/etc/schroot/default/fstab" + +# Files to copy from the host system into the chroot. +COPYFILES="/etc/schroot/default/copyfiles" + +# System NSS databases to copy into the chroot. +NSSDATABASES="/etc/schroot/default/nssdatabases" diff --git a/etc/default/generic/copyfiles b/etc/default/generic/copyfiles new file mode 100644 index 0000000..6bb4d96 --- /dev/null +++ b/etc/default/generic/copyfiles @@ -0,0 +1,2 @@ +/etc/resolv.conf +/etc/gshadow diff --git a/etc/default/generic/fstab b/etc/default/generic/fstab new file mode 100644 index 0000000..de8b733 --- /dev/null +++ b/etc/default/generic/fstab @@ -0,0 +1,12 @@ +# 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 +#procbususb /proc/bus/usb usbfs defaults 0 0 +#/dev /dev none rw,bind 0 0 +/dev/pts /dev/pts none rw,bind 0 0 +/dev/shm /dev/shm none rw,bind 0 0 +/home /home none rw,bind 0 0 +/tmp /tmp none rw,bind 0 0 diff --git a/etc/default/generic/nssdatabases b/etc/default/generic/nssdatabases new file mode 100644 index 0000000..bfd5eea --- /dev/null +++ b/etc/default/generic/nssdatabases @@ -0,0 +1,7 @@ +passwd +shadow +group +services +protocols +networks +hosts diff --git a/etc/default/linux/Makefile.am b/etc/default/linux/Makefile.am new file mode 100644 index 0000000..ac440cd --- /dev/null +++ b/etc/default/linux/Makefile.am @@ -0,0 +1,36 @@ +# schroot Makefile template +# +# +# Copyright © 2004-2009 Roger Leigh <rle...@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 + +pkgsysconfdir = $(PACKAGE_SYSCONF_DIR)/default + +if PLATFORM_LINUX +SCRIPT_CONFIG = \ + copyfiles \ + fstab \ + nssdatabases +endif + +pkgsysconf_DATA = $(SCRIPT_CONFIG) + +EXTRA_DIST = \ + $(SCRIPT_CONFIG) diff --git a/etc/default/linux/copyfiles b/etc/default/linux/copyfiles new file mode 100644 index 0000000..6bb4d96 --- /dev/null +++ b/etc/default/linux/copyfiles @@ -0,0 +1,2 @@ +/etc/resolv.conf +/etc/gshadow diff --git a/etc/default/linux/fstab b/etc/default/linux/fstab new file mode 100644 index 0000000..de8b733 --- /dev/null +++ b/etc/default/linux/fstab @@ -0,0 +1,12 @@ +# 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 +#procbususb /proc/bus/usb usbfs defaults 0 0 +#/dev /dev none rw,bind 0 0 +/dev/pts /dev/pts none rw,bind 0 0 +/dev/shm /dev/shm none rw,bind 0 0 +/home /home none rw,bind 0 0 +/tmp /tmp none rw,bind 0 0 diff --git a/etc/default/linux/nssdatabases b/etc/default/linux/nssdatabases new file mode 100644 index 0000000..bfd5eea --- /dev/null +++ b/etc/default/linux/nssdatabases @@ -0,0 +1,7 @@ +passwd +shadow +group +services +protocols +networks +hosts diff --git a/etc/mount-defaults b/etc/mount-defaults deleted file mode 100644 index de8b733..0000000 --- a/etc/mount-defaults +++ /dev/null @@ -1,12 +0,0 @@ -# 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 -#procbususb /proc/bus/usb usbfs defaults 0 0 -#/dev /dev none rw,bind 0 0 -/dev/pts /dev/pts none rw,bind 0 0 -/dev/shm /dev/shm none rw,bind 0 0 -/home /home none rw,bind 0 0 -/tmp /tmp none rw,bind 0 0 diff --git a/etc/nssdatabases-defaults b/etc/nssdatabases-defaults deleted file mode 100644 index bfd5eea..0000000 --- a/etc/nssdatabases-defaults +++ /dev/null @@ -1,7 +0,0 @@ -passwd -shadow -group -services -protocols -networks -hosts diff --git a/etc/script-defaults b/etc/script-defaults deleted file mode 100644 index 86450cd..0000000 --- a/etc/script-defaults +++ /dev/null @@ -1,11 +0,0 @@ -# Default settings for chroot setup and exec scripts. -# See schroot-script-config(5) for further details. - -# Filesystems to mount inside the chroot. -FSTAB="/etc/schroot/mount-defaults" - -# Files to copy from the host system into the chroot. -COPYFILES="/etc/schroot/copyfiles-defaults" - -# System NSS databases to copy into the chroot. -NSSDATABASES="/etc/schroot/nssdatabases-defaults" diff --git a/etc/setup.d/00check b/etc/setup.d/00check index f62f068..e3dcaf9 100755 --- a/etc/setup.d/00check +++ b/etc/setup.d/00check @@ -53,6 +53,7 @@ if [ "$AUTH_VERBOSITY" = "verbose" ]; then echo "MOUNT_DIR=$MOUNT_DIR" echo "LIBEXEC_DIR=$LIBEXEC_DIR" echo "PID=$PID" + echo "PLATFORM=$PLATFORM" echo "SESSION_ID=$SESSION_ID" echo "CHROOT_TYPE=$CHROOT_TYPE" echo "CHROOT_NAME=$CHROOT_NAME" @@ -116,7 +117,13 @@ case "$CHROOT_TYPE" in fi ;; block-device | lvm-snapshot) - if [ ! -b "$CHROOT_DEVICE" ]; then + if [ "$PLATFORM" = "freebsd" ]; then + DEVTYPE="-c" + else + DEVTYPE="-b" + fi + + if [ ! "$DEVTYPE" "$CHROOT_DEVICE" ]; then echo "Device '$CHROOT_DEVICE' does not exist" exit 1 fi diff --git a/etc/setup.d/10mount b/etc/setup.d/10mount index f0b5632..7c4501c 100755 --- a/etc/setup.d/10mount +++ b/etc/setup.d/10mount @@ -103,22 +103,34 @@ if [ "$CHROOT_TYPE" = "directory" ] || [ "$CHROOT_TYPE" = "file" ] || [ "$CHROOT CREATE_UNION="no" fi + if [ "$PLATFORM" = "freebsd" ]; then + BINDOPT="-t nullfs" + else + BINDOPT="--bind" + fi + if [ "$CHROOT_TYPE" = "directory" ]; then - CHROOT_MOUNT_OPTIONS="--bind" + CHROOT_MOUNT_OPTIONS="$BINDOPT" CHROOT_MOUNT_DEVICE="$CHROOT_DIRECTORY" elif [ "$CHROOT_TYPE" = "file" ]; then UNPACK_LOCATION="${UNPACK_DIR}/${SESSION_ID}" - CHROOT_MOUNT_OPTIONS="--bind" + CHROOT_MOUNT_OPTIONS="$BINDOPT" CHROOT_MOUNT_DEVICE="${CHROOT_FILE_UNPACK_DIR}/${SESSION_ID}" elif [ "$CHROOT_TYPE" = "loopback" ]; then - LOOP_DEVICE="$(/sbin/losetup -j "$CHROOT_FILE" | sed -e 's/:.*$//')" - if [ -z "$LOOP_DEVICE" ]; then - CHROOT_MOUNT_DEVICE="$CHROOT_FILE" - CHROOT_MOUNT_OPTIONS="${CHROOT_MOUNT_OPTIONS},loop" - else + if [ "$PLATFORM" = "freebsd" ]; then + LOOP_DEVICE="/dev/$(/sbin/mdconfig -a -t vnode -f "$CHROOT_FILE")" CHROOT_MOUNT_DEVICE="$LOOP_DEVICE" CHROOT_MOUNT_OPTIONS="" + else + LOOP_DEVICE="$(/sbin/losetup -j "$CHROOT_FILE" | sed -e 's/:.*$//')" + if [ -z "$LOOP_DEVICE" ]; then + CHROOT_MOUNT_DEVICE="$CHROOT_FILE" + CHROOT_MOUNT_OPTIONS="${CHROOT_MOUNT_OPTIONS},loop" + else + CHROOT_MOUNT_DEVICE="$LOOP_DEVICE" + CHROOT_MOUNT_OPTIONS="" + fi fi fi diff --git a/sbuild/sbuild-chroot-block-device.cc b/sbuild/sbuild-chroot-block-device.cc index 542d73e..90cec1a 100644 --- a/sbuild/sbuild-chroot-block-device.cc +++ b/sbuild/sbuild-chroot-block-device.cc @@ -123,7 +123,13 @@ chroot_block_device::setup_lock (chroot::setup_type type, try { - if (!stat(this->get_device()).is_block()) + if (!stat +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + (this->get_device()).is_character() +#else + (this->get_device()).is_block() +#endif + ) { throw error(get_device(), DEVICE_NOTBLOCK); } diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc index c516a84..ca52696 100644 --- a/sbuild/sbuild-chroot.cc +++ b/sbuild/sbuild-chroot.cc @@ -108,7 +108,7 @@ sbuild::chroot::chroot (): mount_location(), original(true), run_setup_scripts(true), - script_config("script-defaults"), + script_config("default/config"), command_prefix(), facets() { diff --git a/sbuild/sbuild-session.cc b/sbuild/sbuild-session.cc index 70076b7..de8f0ed 100644 --- a/sbuild/sbuild-session.cc +++ b/sbuild/sbuild-session.cc @@ -1036,6 +1036,7 @@ session::setup_chroot (sbuild::chroot::ptr& session_chroot, env.add("LIBEXEC_DIR", SCHROOT_LIBEXEC_DIR); env.add("PID", getpid()); env.add("SESSION_ID", session_chroot->get_session_id()); + env.add("PLATFORM", SBUILD_PLATFORM); run_parts rp(SCHROOT_CONF_SETUP_D, true, true, 022); diff --git a/test/test-sbuild-chroot.h b/test/test-sbuild-chroot.h index e8c3f13..6ab74f1 100644 --- a/test/test-sbuild-chroot.h +++ b/test/test-sbuild-chroot.h @@ -176,7 +176,7 @@ public: { env.add("CHROOT_NAME", "test-name"); env.add("CHROOT_DESCRIPTION", "test-description"); - env.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults")); + env.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/default/config")); } void setup_keyfile_chroot (sbuild::keyfile& keyfile, @@ -193,7 +193,7 @@ public: SBUILD_DEFAULT_ENVIRONMENT_FILTER); keyfile.set_value(group, "personality", "undefined"); keyfile.set_value(group, "command-prefix", ""); - keyfile.set_value(group, "script-config", "script-defaults"); + keyfile.set_value(group, "script-config", "default/config"); } void setup_keyfile_session (sbuild::keyfile& keyfile,
signature.asc
Description: Digital signature