diff options
author | Jan Steffens <jan.steffens@gmail.com> | 2011-03-13 19:06:27 +0100 |
---|---|---|
committer | Jan Steffens <jan.steffens@gmail.com> | 2011-03-22 19:47:32 +0100 |
commit | 174ff59dba8c24f544e354cd43f3b68aea91d265 (patch) | |
tree | 08eec872ad89cdb98850082347566a975067f377 /makechrootpkg | |
parent | 5434d3991cd51873f987bde49d55948341c09f3e (diff) | |
download | devtools32-174ff59dba8c24f544e354cd43f3b68aea91d265.tar.xz |
Add flock-based locking to chroots
This prevents accidents when chroots are shared between multiple users.
Diffstat (limited to 'makechrootpkg')
-rwxr-xr-x | makechrootpkg | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/makechrootpkg b/makechrootpkg index a38a740..1f6f20a 100755 --- a/makechrootpkg +++ b/makechrootpkg @@ -105,11 +105,34 @@ if [ ! -d "$chrootdir/root" ]; then fi umask 0022 + +# Lock the chroot we want to use. We'll keep this lock until we exit. +# Note this is the same FD number as in mkarchroot +exec 9>"$copydir.lock" +if ! flock -n 9; then + echo -n "locking chroot copy '$copy'..." + flock 9 + echo "done" +fi + if [ ! -d "$copydir" -o "$clean_first" -eq "1" ]; then + # Get a read lock on the root chroot to make + # sure we don't clone a half-updated chroot + exec 8>"$chrootdir/root.lock" + + if ! flock -sn 8; then + echo -n "locking clean chroot..." + flock -s 8 + echo "done" + fi + echo -n 'creating clean working copy...' mkdir -p "$copydir" rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" echo 'done' + + # Drop the read lock again + exec 8>&- fi if [ -n "$install_pkg" ]; then |