[pacman-dev] [PATCH] makepkg: implement locking for pacman commands
When pacman is run as root to do -S, -U, or -R, it would immediately abort if pacman is not ready for use. Instead, poll the lockfile and wait until it becomes available. Implements FS#28840 Original-patch-by: Georges Dubus <georges.dubus@compiletoi.net> Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- scripts/makepkg.sh.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index cf30c302..25700b09 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -228,6 +228,14 @@ run_pacman() { else cmd=(su root -c "$(printf '%q ' "${cmd[@]}")") fi + + local lockfile="$(pacman-conf DBPath)/db.lck" + if [[ -f $lockfile ]]; then + msg "$(gettext "Pacman is currently in use, please wait...")" + while [[ -f $lockfile ]]; do + sleep 3 + done + fi fi "${cmd[@]}" } -- 2.20.1
When pacman is run as root to do -S, -U, or -R, it would immediately abort if pacman is not ready for use. Instead, poll the lockfile and wait until it becomes available. Implements FS#28840 Original-patch-by: Georges Dubus <georges.dubus@compiletoi.net> Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- v2: repeat the wait message every 30 seconds. This lets the user know we are actually "doing something". Implemented as a result of discussion on #archlinux-pacman, seems like a bit of a placebo effect to me. I am okay with either version being accepted. scripts/makepkg.sh.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 7d10c7b1..32933e61 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -226,6 +226,15 @@ run_pacman() { else cmd=(su root -c "$(printf '%q ' "${cmd[@]}")") fi + local lockfile="$(pacman-conf DBPath)/db.lck" + while [[ -f $lockfile ]]; do + local timer=0 + msg "$(gettext "Pacman is currently in use, please wait...")" + while [[ -f $lockfile ]] && (( timer < 10 )); do + (( ++timer )) + sleep 3 + done + done fi "${cmd[@]}" } -- 2.20.1
On 21/2/19 12:35 pm, Eli Schwartz wrote:
Looks good. Given I suggested it, I don't think it is placebo, but shows the lack of hanging. Allan
participants (2)
-
Allan McRae
-
Eli Schwartz