Revert gvfs hacks to known-good state.

Originally, I patched enter_chroot.sh to stop the gvfs daemons to work
around an issue where these daemons would prevent loop devices from being
unmounted. See https://bugzilla.gnome.org/show_bug.cgi?id=677648

Unfortunately, temporarily stopping gvfs daemons has a bad side effects:
other GUI applications that rely on these daemons responding start hanging.
This can be reproduced, for example, by starting 'gedit'.

To fix these hangs, I'm just reverting my patches to enter_chroot.sh and
restoring the scripts to where they were before.

This reverts the following patches:
  1. Stop gvfs daemons earlier during enter_chroot.
     This reverts commit 0079158f737167d2a97b7899e6f58133f7602c17.
  2. Revert "Stop the gvfsd-trash daemon during enter_chroot."
     This reverts commit 654a00bd6154476bc7d9d1138576c5452b2da978.
  3. Revert "Stop the automounting daemon whenever we're inside the chroot."
     This reverts commit fae0a59e8b0e60b91b3b9bfee915edc57514ee1b.
  4. Revert "Clean up update_bootloaders.sh to avoid sleeping."
     This reverts commit 0103b5913816544c4ed9b75369a1fc2fe5e1d6ac.

BUG=chromium-os:23443
TEST=Trybot run.

Change-Id: Ie9ff222fe5fc7232fd1fc39af129cc18531118c6
Reviewed-on: https://gerrit.chromium.org/gerrit/26922
Reviewed-by: Chris Wolfe <cwolfe@chromium.org>
Reviewed-by: Jon Kliegman <kliegs@chromium.org>
Reviewed-by: Brian Harring <ferringb@chromium.org>
Commit-Ready: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh
index 6683004..86c7f61 100755
--- a/sdk_lib/enter_chroot.sh
+++ b/sdk_lib/enter_chroot.sh
@@ -261,13 +261,6 @@
       disown $!
     fi
 
-    # Turn off automounting of external media when we enter the chroot by
-    # stopping the gvfs-gdu-volume-monitor and gvfsd-trash daemons. This is
-    # currently the most reliable way to disable automounting.
-    # See https://bugzilla.gnome.org/show_bug.cgi?id=677648
-    sudo killall -STOP -r '^gvfs-gdu-volume.*$|^gvfsd-trash$' 2>/dev/null \
-      || true
-
     debug "Mounting chroot environment."
     MOUNT_CACHE=$(echo $(awk '{print $2}' /proc/mounts))
     mount_queue_init
@@ -394,6 +387,22 @@
         warn "-- Note: modprobe fuse failed.  gmergefs will not work"
     fi
 
+    # Turn off automounting of external media when we enter the
+    # chroot; thus we don't have to worry about being able to unmount
+    # from inside.
+    if SAVED_PREF=$(gconftool-2 -g ${AUTOMOUNT_PREF} 2>/dev/null); then
+      if [ "${SAVED_PREF}" != "false" ]; then
+        if [ $(gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} false) ]; then
+          warn "-- Note: USB sticks may be automounted by your host OS."
+          warn "-- Note: If you plan to burn bootable media, you may need to"
+          warn "-- Note: unmount these devices manually, or run image_to_usb.sh"
+          warn "-- Note: outside the chroot."
+        fi
+      fi
+    fi
+    # Always write the temp file so we can read it when exiting
+    echo "${SAVED_PREF:-false}" > "${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}"
+
     # Fix permissions on ccache tree.  If this is a fresh chroot, then they
     # might not be set up yet.  Or if the user manually `rm -rf`-ed things,
     # we need to reset it.  Otherwise, gcc itself takes care of fixing things
@@ -505,6 +514,12 @@
     # Remove any dups from lock file while installing new one
     sort -u -n "$TMP_LOCKFILE" > "$LOCKFILE"
 
+    SAVED_PREF=$(<"${FLAGS_chroot}${SAVED_AUTOMOUNT_PREF_FILE}")
+    if [ "${SAVED_PREF}" != "false" ]; then
+      gconftool-2 -s --type=boolean ${AUTOMOUNT_PREF} ${SAVED_PREF} || \
+        warn "could not re-set your automount preference."
+    fi
+
     if [ -s "$LOCKFILE" ]; then
       debug "At least one other pid is running in the chroot, so not"
       debug "tearing down env."
@@ -531,10 +546,6 @@
 
       debug "Unmounting chroot environment."
       safe_umount_tree "${MOUNTED_PATH}/"
-
-      # Now that we've exited the chroot, allow automounting again.
-      sudo killall -CONT -r '^gvfs-gdu-volume.*$|^gvfsd-trash$' 2>/dev/null \
-        || true
     fi
   ) 200>>"$LOCKFILE" || die "teardown_env failed"
 }