Linux Archive

Linux Archive (
-   ArchLinux Pacman Development (
-   -   pacman-optimize: fix database locking race conditions (

Denis A. Altoé Falqueto 06-21-2010 05:07 PM

pacman-optimize: fix database locking race conditions
On Mon, Jun 21, 2010 at 1:55 PM, Andres P <> wrote:
> Instead of making the lock file with touch, use mkdir since it's the only
> portable atomic transaction available to shell scripts.

In fact, there is another way to do an atomic operation. Look at
repo-add script, in function check_repo_db (I've seen this advice in
some article some time ago too..). The first command tries to create a
file with set -o noclobber. So, if the file already exists, it will
fail and will not alter the lock file. If it doesn't exist, the lock
file will be created and the process will proceed.

if (set -o noclobber; echo "$$" > "$LOCKFILE") 2>/dev/null; then
# We acquired the lock
# The lock already exists and we can't proceed.

This would avoid changing the db.lock to a directory. Maybe this could
break some kind of script or utility out there...

A: Because it obfuscates the reading.
Q: Why is top posting so bad?

Denis A. Altoe Falqueto

All times are GMT. The time now is 11:39 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.