[bin] implement read, shared lock in emerge()

This commit is contained in:
Fabio Erculiani 2012-09-06 14:29:11 +02:00
parent b14075158c
commit de5b95bdd2

View File

@ -1,21 +1,32 @@
# Emerge wrapper, uses matter lock file support to avoid # Emerge wrapper, uses matter lock file support to avoid
# concurrent execution # concurrent execution
emerge() { emerge() {
snapshot_lock_file=/var/tmp/.emerge.snapshot.lock"
matter_lock_file="/var/tmp/.matter_resource.lock" matter_lock_file="/var/tmp/.matter_resource.lock"
flock -x -n "${matter_lock_file}" true flock -x -n "${matter_lock_file}" true
rc=${?} rc=${?}
if [ "${rc}" != "0" ]; then if [ "${rc}" != "0" ]; then
echo echo >&2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
echo "matter is running on this chroot, in order to prevent explosions" echo "matter is running on this chroot, in order to prevent explosions" >&2
echo "this emerge instance will terminate NOW" echo "this emerge instance will terminate NOW" >&2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >&2
echo echo >&2
return 1 return 1
else else
# acquire snapshot read lock in non-blocking, shared mode
(
flock -s -n 9 || {
echo "Hello there," >&2;
echo "a chroot snapshot is in progress..." >%2;
echo "Try again later." >&2;
exit 1;
}
# eval $(portageq envvar -v FETCHCOMMAND RESUMECOMMAND PORTAGE_RSYNC_OPTS) # eval $(portageq envvar -v FETCHCOMMAND RESUMECOMMAND PORTAGE_RSYNC_OPTS)
# add bandwidth limit here # add bandwidth limit here
/usr/bin/emerge --quiet-build=n "$@" /usr/bin/emerge --quiet-build=n "$@"
return ${?} exit ${?}
) 9> "${snapshot_lock_file}"
return "${?}"
fi fi
} }