FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-21-2010, 05:07 PM
Denis A. Altoé Falqueto
 
Default pacman-optimize: fix database locking race conditions

On Mon, Jun 21, 2010 at 1:55 PM, Andres P <aepd87@gmail.com> 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
else
# The lock already exists and we can't proceed.
fi

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
-------------------------------------------
 

Thread Tools




All times are GMT. The time now is 12:24 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org