From 7f7a763ed17d49e17e228e7ffedac1fcb023f4e2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 28 Sep 2011 11:48:20 -0400 Subject: [PATCH] enter_chroot: optimize env_sync_proc ownership changing Most of the time the files in the chroot /etc/ are already changed to the proper owner. Only on the first run do they need to be changed. So check the owner before doing the sudo as that is a bit faster. If we do end up needing to run sudo, bundle the commands up to avoid having to execute sudo multiple times. BUG=None TEST=`sudo chown root chroot/etc/resolv.conf && cros_sdk --enter`; see /etc/resolv.conf owned by me Change-Id: Ifd974ace168ab309fdc2e7583d135ee23576a5bb Reviewed-on: http://gerrit.chromium.org/gerrit/8418 Reviewed-by: David James Commit-Ready: Mike Frysinger Tested-by: Mike Frysinger --- sdk_lib/enter_chroot.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 69f62e5436..8da0ab5fa9 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -118,13 +118,14 @@ function env_sync_proc { # necessary. local poll_interval=10 - local sync_files="etc/resolv.conf etc/hosts" + local sync_files=( etc/resolv.conf etc/hosts ) # Make sure the synced files are writable by normal user, so that we # don't have to sudo inside the loop. - for file in ${sync_files}; do - sudo chown ${USER} ${FLAGS_chroot}/${file} 1>&2 - done + local chmods=$(find ${sync_files[@]/#/${FLAGS_chroot}/} '!' -user ${USER}) + if [ -n "${chmods}" ]; then + sudo -- chown ${USER} ${chmods} 1>&2 + fi # Drop stdin, stderr, stdout, and chroot lock. # This is needed for properly daemonizing the process.