Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkgtools/pbulk: delete xcrun cache file before unprivileged su #277

Open
wants to merge 1 commit into
base: joyent/feature/miscfix/2015Q2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion pkgtools/pbulk/files/pbulk/scripts/pkg-build
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,33 @@ cleanup() {
exit 1
}

delete_xcrun_cache() {
local xcrun_bin xcrun_db_tmp
if [ -z ${xcrun_db+x} ]; then
xcrun_db=''
xcrun_bin=`which xcrun`
[ $? -eq 0 ] || return
[ -n "$xcrun_bin" ] || return
xcrun_db_tmp=`{ "$xcrun_bin" -v true 2>&1; } | \
grep ' xcrun_db = .*' | head -n 1`
xcrun_db_tmp=${xcrun_db_tmp#*"'"}
xcrun_db_tmp=${xcrun_db_tmp%"'"}
[ "X${xcrun_db_tmp##*/}" = Xxcrun_db ] || return
xcrun_db="$xcrun_db_tmp"
fi
[ -n "$xcrun_db" ] && rm -f "$xcrun_db"
}

pre_run_su() {
# On OS X, if the privileged user's xcrun cache file exists, delete
# it because the xcrun invoked as the unprivileged user via su may
# try to replace it and fail because it does not have appropriate
# permissions.
delete_xcrun_cache
}

run_direct() { "$@"; }
run_su() { su ${unprivileged_user} -c '"$@"' make "$@"; }
run_su() { pre_run_su; su ${unprivileged_user} -c '"$@"' make "$@"; }

run_make() {
local run_cmd
Expand Down