umount wrapper: fix PATH cleansing

Even though we look up our wrapper script via $0, we don't use it.
Instead, the script has /usr/local/sbin hardcoded.  This causes the
code to constantly find itself and forkbomb.

BUG=chromium-os:23443
TEST=`cros_sdk -- true` no longer hangs

Change-Id: I64dc41880e3b7c0abf5da0f6a708c02510ddc8c0
Reviewed-on: https://gerrit.chromium.org/gerrit/33119
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Mike Frysinger 2012-09-12 16:01:08 -04:00 committed by Gerrit
parent 0f2cfe6b9d
commit 4bf9456c7a

View File

@ -1,12 +1,16 @@
#!/bin/bash
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Work around a bug on precise where gvfs trash goes looking in mounts
# it shouldn't, resulting in the umount failing when it shouldn't.
# See crosbug.com/23443 for the sordid details.
suppressed_dir=$(dirname "$(readlink -f "$0")")
cleaned_path="$(echo "$PATH" | sed -e 's+\(^\|:\)/usr/local/sbin\(:\|$\)++g')"
binary="$(PATH="${cleaned_path}" type -P umount)"
suppressed_dir=$(dirname "$0")
cleaned_path=$(echo "${PATH}" | sed -r -e "s,(^|:)${suppressed_dir}(:|$),,g")
binary=$(PATH="${cleaned_path}" type -P umount)
if [ $? -ne 0 ]; then
echo "umount: command not found" >&2
exit 127