tags 428808 + patch thanks On Fri, Jun 15, 2007 at 08:10:35AM +0200, Raphael Hertzog wrote: > On Thu, 14 Jun 2007, Roger Leigh wrote: > > Raphael Hertzog <[EMAIL PROTECTED]> writes: > > > > > Following my previous bug report I switched my chroot to "plain" type and > > > got this: > > > [EMAIL PROTECTED]:~$ schroot -c sarge > > > cp: `/etc/resolv.conf' and > > > `/var/lib/schroot/mount/sarge-dc129170-7fe7-44ad-9a5e-a7f4e67a716a/etc/resolv.conf' > > > are the same file > > > E: sarge-dc129170-7fe7-44ad-9a5e-a7f4e67a716a: Chroot setup failed: > > > stage=setup-start > > > > > > This is because I have <chroot>/etc/resolv.conf as a symlink pointing > > > to .host/resolv.conf and <chroot>/etc/.host/ is bind mounted to the real > > > /etc/. > > > > > It looks like /etc/schroot/setup.d/20network could be enhanced to check > > > for this specific case at least. Or it could simply do nothing if the > > > chroot's resolv.conf is a symlink. > > > > We can certainly stat(1) both and check if the device and inode > > numbers are the same. I'm not so sure about the symlink; I don't know > > how the script can be certain of correctly assuming the intent of the > > system administrator in this case. > > You need to resolve (readlink -f or -e) the symlink before doing the stat > in any case. Because the symlink has its own inode number. > > Another simpler solution is to copy the file only if it's needed (i.e. > when the content differs). You calculate the md5sum of each file and you > copy only when they differ. This is even better I think.
The attached patch implements your md5sum suggestion, which I think is nice and clean. The only case I can think of where this might fail is a race if either copy is modified during the comparison, leading to failure as it tries to copy over itself. We can probably add a stat check too if this is needed. Is this OK with you? Thanks, 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/bin/schroot/exec/00check b/bin/schroot/exec/00check index 24387fc..e45a862 100755 --- a/bin/schroot/exec/00check +++ b/bin/schroot/exec/00check @@ -17,6 +17,8 @@ # ##################################################################### +set -e + if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then . "$CHROOT_SCRIPT_CONFIG" fi diff --git a/bin/schroot/setup/00check b/bin/schroot/setup/00check index 11bf7e0..6590659 100755 --- a/bin/schroot/setup/00check +++ b/bin/schroot/setup/00check @@ -17,6 +17,8 @@ # ##################################################################### +set -e + if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then . "$CHROOT_SCRIPT_CONFIG" fi diff --git a/bin/schroot/setup/20network b/bin/schroot/setup/20network index 3529bbd..59cdda1 100755 --- a/bin/schroot/setup/20network +++ b/bin/schroot/setup/20network @@ -17,6 +17,8 @@ # ##################################################################### +set -e + if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then . "$CHROOT_SCRIPT_CONFIG" fi @@ -25,8 +27,22 @@ if [ "$AUTH_VERBOSITY" = "verbose" ]; then VERBOSE="--verbose" fi +# Copy a file if the source and destination differ +# $1: source file +# $2: destination file +copy_file() +{ + a=$(/usr/bin/md5sum "$1" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') + b=$(/usr/bin/md5sum "$2" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') + + if [ "$a" != "$b" ]; then + cp $VERBOSE "$1" "$2" + 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" + copy_file /etc/hosts "${CHROOT_PATH}/etc/hosts" + copy_file /etc/resolv.conf "${CHROOT_PATH}/etc/resolv.conf" fi diff --git a/bin/schroot/setup/30passwd b/bin/schroot/setup/30passwd index c3c348a..8f674d7 100755 --- a/bin/schroot/setup/30passwd +++ b/bin/schroot/setup/30passwd @@ -17,6 +17,8 @@ # ##################################################################### +set -e + if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then . "$CHROOT_SCRIPT_CONFIG" fi @@ -25,9 +27,23 @@ if [ "$AUTH_VERBOSITY" = "verbose" ]; then VERBOSE="--verbose" fi +# Copy a file if the source and destination differ +# $1: source file +# $2: destination file +copy_file() +{ + a=$(/usr/bin/md5sum "$1" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') + b=$(/usr/bin/md5sum "$2" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') + + if [ "$a" != "$b" ]; then + cp $VERBOSE "$1" "$2" + fi + +} + if [ $1 = "setup-start" ] || [ $1 = "setup-recover" ]; then - cp $VERBOSE /etc/passwd "${CHROOT_PATH}/etc/passwd" - cp $VERBOSE /etc/shadow "${CHROOT_PATH}/etc/shadow" - cp $VERBOSE /etc/group "${CHROOT_PATH}/etc/group" + copy_file /etc/passwd "${CHROOT_PATH}/etc/passwd" + copy_file /etc/shadow "${CHROOT_PATH}/etc/shadow" + copy_file /etc/group "${CHROOT_PATH}/etc/group" fi diff --git a/bin/schroot/setup/50chrootname b/bin/schroot/setup/50chrootname index 86413c9..121e23e 100755 --- a/bin/schroot/setup/50chrootname +++ b/bin/schroot/setup/50chrootname @@ -17,6 +17,8 @@ # ##################################################################### +set -e + if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then . "$CHROOT_SCRIPT_CONFIG" fi diff --git a/bin/schroot/setup/50sbuild b/bin/schroot/setup/50sbuild index 541020f..e01955f 100755 --- a/bin/schroot/setup/50sbuild +++ b/bin/schroot/setup/50sbuild @@ -17,6 +17,8 @@ # ##################################################################### +set -e + if [ -f "$CHROOT_SCRIPT_CONFIG" ]; then . "$CHROOT_SCRIPT_CONFIG" fi
signature.asc
Description: Digital signature