On long running systems, the ssh-agent dir might go stale. This should
not prevent entering the cros chroot though, so skip it if it's invalid.
BUG=None
TEST=`cros_sdk` enters with ssh-agent dir bind mounted
TEST=`rm -rf /tmp/ssh-*/; cros_sdk` enters with ssh-agent dir skipped
Change-Id: I923b031612c0d37a896437c7355cac6c448eef82
Reviewed-on: https://gerrit.chromium.org/gerrit/12758
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
The current instructions for golo access include additions to the
~/.ssh/config file that are specific to Google distros of ssh. The
filtering mechanism in enter_chroot needed an update to include
these new options to filter out.
BUG=chromium-os:23322
TEST=With a golo-configured .ssh/config, enter chroot and test ssh:
> cros_sdk
> git remote update
Fetching ...
...
Change-Id: Ida9fcdff37ff0eb24c811ad789f82136dca7252f
Reviewed-on: https://gerrit.chromium.org/gerrit/12037
Tested-by: Matt Tennant <mtennant@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Reviewed-by: Zdenek Behan <zbehan@chromium.org>
Commit-Ready: Matt Tennant <mtennant@chromium.org>
Every invocation of `sudo` delays things, so merge all of the mounts
into a single `sudo` command when possible. This saves over 1 second
on initial execution (out of ~4 seconds total).
BUG=None
TEST=`cros_sdk --enter true` still mounts & unmounts properly
Change-Id: Ibc66507dc21250a81207d2f940645eaebe93c79c
Reviewed-on: https://gerrit.chromium.org/gerrit/10901
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
The current code that syncs the user's ssh files from ~/.ssh/ to the
chroot assumes the user has these files in the first place. For the
fresh user and/or install, these might not exist. So ignore errors
from attempting to copy them. It's not like we attempt to "recover"
anyways, and this sync is more of a "let's make things smoother" than
a "we need this to run properly".
BUG=chromium-os:15005
TEST=`mv ~/.ssh ~/.ssh.bak; mkdir ~/.ssh; cros_sdk` and see no more warnings
Change-Id: I9cac2ecad7c64c088fbdfe55377c0429b3b7ab03
Reviewed-on: https://gerrit.chromium.org/gerrit/10922
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Ubuntu 11.10, for whatever reason, moved /dev/shm to /run/shm. Since
/run is not mounted in the chroot, /dev/shm is a dangling symlink and
various things that require shared memory start failing.
If /run and /run/shm exist, bind-mount them in the chroot.
Because /run doesn't yet exist in the SDK tarballs, try to create it
(and /run/shm if necessary) as root if it and can't be created as a
normal user.
BUG=chromium-os:19871
TEST=Run cros_sdk, verify that /dev/shm has the expected contents
Change-Id: I61583c1c0d409c1234fa8d8930a9b64544c9a8e7
Reviewed-on: https://gerrit.chromium.org/gerrit/10222
Tested-by: Aaron Plattner <aplattner@nvidia.com>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: David James <davidjames@chromium.org>
The sync pid file is created without using sudo which means we should be
able to delete it without using sudo. By default, run `rm` directly and
if it fails, fall back to sudo like we historically have.
BUG=None
TEST=`cros_sdk --enter true`; see pid file deleted
Change-Id: I26d898f6d594eb9ea4652335468345dd11303122
Reviewed-on: http://gerrit.chromium.org/gerrit/8644
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
We call `readlink -f` on the chroot mount point to resolve any symlinks
in the path (since that is what `mount` records). But the only paths
that can have symlinks are in the base chroot mount. Everything below
that we know are not going to be symlinks (since we've set up the paths
ourselves). So process the chroot mount point with readlink once and
reuse that value everywhere else.
BUG=None
TEST=`cros_sdk --enter true` still mounts & unmounts properly
Change-Id: Id1e734d20c0cb766f5490583b793930af77b3b14
Reviewed-on: http://gerrit.chromium.org/gerrit/8645
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
The chrome root code doesn't attempt to mount the tree if there is no
source root configured. So re-order the code from:
- is chrome source mounted ?
- does a chrome source exist ?
- mount chrome source
to the more logical:
- does a chrome source exist ?
- use ensure_mounted to check+mount
This lets us use the mount cache for the chrome mounting and unifies
duplicated mount/checking logic.
BUG=None
TEST=`cros_sdk --enter` still works with simultaneous runs
TEST=`cros_sdk --enter -- ls` still works
Change-Id: I7e6af9dd7f65cefa04438c2862c931f06237060a
Reviewed-on: http://gerrit.chromium.org/gerrit/8032
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
The depot_tools mount code is exactly like ensure_mounted except that it
prints a warning instead of dying when things can't be mounted. So take
the current api and extend it slightly to support warning or dying. This
also lets us re-use the existing mount cache and avoid the forks as well
as clean up duplicated code.
BUG=None
TEST=`cros_sdk --enter` still works with simultaneous runs
TEST=`cros_sdk --enter -- ls` still works
Change-Id: I89336778b6aa16191e79d900a51774929cadf06b
Reviewed-on: http://gerrit.chromium.org/gerrit/8031
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
The cros_sdk tool runs a lot of helper programs which can be replaced
with bash builtins, or condensed multiple calls into a single one. By
themselves they aren't that slow, but add them all up and run them a
whole lot, and it starts to make a difference.
External programs to bash internals:
- dirname $f -> ${f%/*}
- f=$(cat $f) -> f=$(<$f)
- which f -> type -P f
Simpler expressions:
- [[ ( ... ) ]] -> [[ ... ]]
- eval v=\$$f -> v=${!f}
Common/clearer expressions:
- ! var=$(cmd) -> var=$(cmd || :)
Condensed tools:
- sort | uniq -> uniq -u
BUG=None
TEST=`cros_sdk --enter` still works with simultaneous runs
TEST=`cros_sdk --enter -- ls` still works
Change-Id: Ice5e5e252237082a2249990644e051895d61d1fd
Reviewed-on: http://gerrit.chromium.org/gerrit/8029
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
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>
Since we grab a lock before mounting anything, we know that the relevant
list of mounts won't change (since we haven't changed it yet). So we can
cache the output of `mount` and re-use that in every subsequent check.
BUG=None
TEST=`cros_sdk --enter` still works with simultaneous runs
TEST=`cros_sdk --enter -- ls` still works
Change-Id: I27c98c923761fb777686632fe6e6604ca543cfb6
Reviewed-on: http://gerrit.chromium.org/gerrit/8030
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Checking the permission of files is faster than assuming they're broken
and then running `sudo chmod`, so do just that.
BUG=None
TEST=run `cros_sdk --enter` with bad perms and see them fixed
TEST=run `cros_sdk --enter` with correct perms and see sudo skipped
TEST=the buildbot failure was due to other changes, not this one
Change-Id: Ie69b4e766e2e3652944e4723d091ce589d07a4f6
Reviewed-on: http://gerrit.chromium.org/gerrit/8028
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
No need to call `git var | sed` multiple times when we can call it once
and then use bash string parsing routines to extract the relevant info.
BUG=None
TEST=delete .gitconfig in chroot; enter chroot; verify .gitconfig is up-to-date
Change-Id: I900e4241a5c53bc46c90eb0f2a01152f4bfba577
Reviewed-on: http://gerrit.chromium.org/gerrit/8027
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
First let's add a chroot upgrade hook that'll declare a small list of
locales to speed up glibc upgrades.
The other blocker was that `cros_sdk --enter` took an inordinate amount
of time to execute (`locale-gen -u` specifically) when the number of
existing locales is huge. This seems to be a bug in the bash/glibc
stack which is resolved in newer versions, but we can workaround the
issue by forcing locale-gen to run in a C locale. The tool itself does
not care about its locale and we silence its output.
BUG=chromium-os:20378
TEST=`cros_sdk --enter`; see no locales in /etc/locale.gen; run `./build_packages` and see upgrade hook work
TEST=generate all 400 locales; `cros_sdk --enter`; see that it was quick
Change-Id: I8fcc5e26bd8e1bcfd52b6a6c7ef3cacf0a252081
Reviewed-on: http://gerrit.chromium.org/gerrit/7806
Reviewed-by: David James <davidjames@chromium.org>
Reviewed-by: Zdenek Behan <zbehan@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Running `sudo` at all is a bit poky, so let's avoid modprobing fuse when
we know it already exists because it's listed in /proc/filesystems.
The relative speed:
time sudo modprobe fuse -> 0.164s
time grep -q fuse /proc/filesystems -> 0.002s
BUG=None
TEST=enable `set -x`; run `sudo modprobe fuse`; run `cros_sdk true`; see modprobe skipped
Change-Id: I07213e7b0607ca65df2a8a3ae22eb4a49c8bb888
Reviewed-on: http://gerrit.chromium.org/gerrit/7824
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
It doesn't make much sense to run gconftool when the default automount
value is what we already want: false. So in this common case, skip the
save/restore logic altogether since we aren't actually changing things.
Further, we can merge the `which` check in by checking the exit status
of the `gconftool` run. If it fails, the tool doesn't exist.
BUG=None
TEST=enable `set -x`; run `cros_sdk true`; see gconftool run once in common case
Change-Id: I1c6aee945218a8a9df533d9ef207c750f909c252
Reviewed-on: http://gerrit.chromium.org/gerrit/7823
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
The teardown_env is a little slow when unmounting things because it runs
`sudo umount` once per mount point. This is so that when things go wrong,
it can easily recover. However, this slows down the common case at the
expense of the uncommon.
Refactor the code so that in the common case, we run one `sudo umount`.
When things do fail, we're a bit slower as we reparse the entire mount,
list, but that's fine as it's an error case.
BUG=None
TEST=enable `set -x`; run `cros_sdk true`; see all mount points unmounted in one shot
Change-Id: Iec98a7b9f51a77e90c30e6f6acae26e528b8c50d
Reviewed-on: http://gerrit.chromium.org/gerrit/7822
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Works around:
http://code.google.com/p/chromium-os/issues/detail?id=20378
which is breaking the tree.
BUG=chromium-os:20378
TEST=cros_sdk --enter
Change-Id: I0d5dc2dd6466efe9baafcc404648d2c53309a3b7
Reviewed-on: http://gerrit.chromium.org/gerrit/7679
Reviewed-by: David James <davidjames@chromium.org>
Reviewed-by: Thieu Le <thieule@chromium.org>
Tested-by: David James <davidjames@chromium.org>
The process of updating the Portage package status spreadsheet on
buildbots requires a credentials file at ~/.gdata_cred.txt in the
chroot. All buildbot VMs have this file outside the chroot now,
so this change adds that file to the list of things created in
the user's homedir when entering the chroot.
BUG=None
TEST=Run cros_sdk in these scenarios:
~/.gdata_cred.txt exists -> Same file should be at $HOME in chroot
~/.gdata_cred.txt does not exist -> No file created in chroot
Change-Id: I5c0f333a9308f5efa5324ce2e202a7c9e9fdb48b
Reviewed-on: http://gerrit.chromium.org/gerrit/6911
Reviewed-by: Zdenek Behan <zbehan@chromium.org>
Tested-by: Matt Tennant <mtennant@chromium.org>
BUG=None
TEST=run cros_sdk
Change-Id: I39fafd58c7cc9fd536fe9b75f314f9970766a483
Reviewed-on: http://gerrit.chromium.org/gerrit/6414
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
The buildbot code forces the en_US.UTF8 locale itself, and does so inside
of the chroot, so our auto-detection code doesn't catch it. Always create
these locales that the buildbot uses.
BUG=None
TEST=cleared out locales, emptied out active locale env vars, ran enter_chroot, saw that en_US{,UTF8} were created
Change-Id: I9ad65007a340333e19743985c9cbeea9403823fa
Reviewed-on: http://gerrit.chromium.org/gerrit/6168
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
Since we no longer force LC_ALL=C on everyone, the few times that perl
does get run by people, it spews the expected "Setting locale failed"
warnings. This isn't as big a deal as with Debian systems as perl usage
is uncommon in Gentoo.
This is also highlights the long-existing small issue of only specific
locales being available in the chroot. So for non US english speaking
users, they've been having non-optimal experiences.
So parse the user's active locale and automatically generate the missing
ones in the chroot so that when they do enter, things "just work".
BUG=chromium-os:19139
TEST=set locale to non-existent ones, enter_chroot, & verify locales are created
Change-Id: I43f809a1ee1472e4797edab0f32cecf582ea8b48
Reviewed-on: http://gerrit.chromium.org/gerrit/5986
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
* Removed boilerplate, simplified search code.
* Fixed one too long line
This will unfortunately kill all outstanding CLs into enter_chroot.
BUG=chromium-os:18750
TEST=run it
Change-Id: I39c45fa8163d92487b512e7e8d298ce9231f4bd2
Reviewed-on: http://gerrit.chromium.org/gerrit/5830
Tested-by: Zdenek Behan <zbehan@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Anush Elangovan <anush@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>