mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-24 23:21:17 +02:00
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 <davidjames@chromium.org> Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
9ca3e4c0fe
commit
7f7a763ed1
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user