Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/mkarchroot
diff options
context:
space:
mode:
authorJan Steffens <jan.steffens@gmail.com>2011-03-13 19:06:27 +0100
committerJan Steffens <jan.steffens@gmail.com>2011-03-22 19:47:32 +0100
commit174ff59dba8c24f544e354cd43f3b68aea91d265 (patch)
tree08eec872ad89cdb98850082347566a975067f377 /mkarchroot
parent5434d3991cd51873f987bde49d55948341c09f3e (diff)
Add flock-based locking to chroots
This prevents accidents when chroots are shared between multiple users.
Diffstat (limited to 'mkarchroot')
-rwxr-xr-xmkarchroot16
1 files changed, 16 insertions, 0 deletions
diff --git a/mkarchroot b/mkarchroot
index 254841e..5c6548e 100755
--- a/mkarchroot
+++ b/mkarchroot
@@ -141,6 +141,20 @@ chroot_umount () {
umount "${working_dir}/${cache_dir}"
[ -n "${host_mirror_path}" ] && umount "${working_dir}/${host_mirror_path}"
}
+
+chroot_lock () {
+ # Only reopen the FD if it wasn't handed to us
+ if [ "$(readlink -f /dev/fd/9)" != "${working_dir}.lock" ]; then
+ exec 9>"${working_dir}.lock"
+ fi
+
+ # Lock the chroot. Take note of the FD number.
+ if ! flock -n 9; then
+ echo -n "locking chroot..."
+ flock 9
+ echo "done"
+ fi
+}
# }}}
umask 0022
@@ -153,6 +167,7 @@ if [ "$RUN" != "" ]; then
exit 1
fi
+ chroot_lock
chroot_mount
copy_hostconf
@@ -169,6 +184,7 @@ else
mkdir -p "${working_dir}/var/lib/pacman/sync"
mkdir -p "${working_dir}/etc/"
+ chroot_lock
chroot_mount
pacargs="--noconfirm --root=${working_dir} --cachedir=${cache_dir}"