if [ $x11 = 1 -a -n "$DISPLAY" -a "${DISPLAY##localhost:}" = "$DISPLAY" ]; then
COOKIE="$(xauth list $DISPLAY)"
fi
-BECOME="$HOME/.become"
-profile="$BECOME/$user"
-[ -f "$profile" ] || profile="$BECOME/all"
+ignore_profile_user=0
+for candidate in "$HOME" "$PROFILE_HOME"; do
+ [ -n "$candidate" ] || continue
+ BECOME="$candidate/.become"
+ [ -d "$BECOME" ] || continue
+
+ # Script to run when becoming any user.
+ [ -z "$allusersprofile" ] && allusersprofile="$BECOME/all"
+ [ -f "$allusersprofile" ] || allusersprofile=
+
+ # Set $HOME/all sticky to ignore $PROFILE_HOME/$user.
+ if [ "$candidate" = "$HOME" ]; then
+ [ -k "$BECOME/all" ] && ignore_profile_user=1
+ else
+ [ $ignore_profile_user = 1 ] && continue
+ fi
+
+ # Script to run (after the one mentioned above) when becoming this user.
+ [ -z "$userprofile" ] && userprofile="$BECOME/$user"
+ [ -f "$userprofile" ] || userprofile=
+done
file="${TMPDIR:-/tmp}/$USER.become.$user.$RANDOM.$$"
umask=$(builtin umask -p)
fi
echo >&3 ". ${PROFILE_HOME:-$HOME}/.bash_profile"
-[ -f "$BECOME/all" ] && cat >&3 2>/dev/null "$BECOME/all"
-[ -f "$BECOME/$user" ] && cat >&3 2>/dev/null "$BECOME/$user"
+[ -f "$allusersprofile" ] && cat >&3 2>/dev/null "$allusersprofile"
+[ -f "$userprofile" ] && cat >&3 2>/dev/null "$userprofile"
[ $chdir = 1 ] && echo >&3 2>/dev/null "cd - &>/dev/null"
exec 3>&-