]> git.tuebingen.mpg.de Git - dss.git/commit - dss.c
Use semaphore locking to avoid starting dss multiple times.
authorAndre Noll <maan@systemlinux.org>
Sat, 13 Nov 2010 19:31:10 +0000 (20:31 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 1 Jun 2012 15:31:36 +0000 (17:31 +0200)
commitdd42f745333f7273a1ef1e81b090705473de8079
treed4adc6d5e6f5541d2032895281ce2e2c196bae2e
parent17eea857c175123d68e7dffc28134befa4c0aa5f
Use semaphore locking to avoid starting dss multiple times.

It's trickier than one might expect but it is hopefully also much
better than any pidfile-based approach.

This patch adds ipc.c and ipc.h containing the public lock_dss()
function which acquires a semaphore-based lock whose key is based
on the hash of the resolved path name of the dss config file. This
allows different instances of dss to coexist.

All semaphore operations are called with both the SEM_UNDO and the
IPC_NOWAIT flag. SEM_UNDO guarantees that no stale lock remains after
dss was killed by SIGKIlL while IPC_NOWAIT makes the call to lock_dss()
fail if another process is already holding the lock.

The prune/create/run commands simply take the lock at startup and
exit if it could not be acquired.

The underlying semaphore set contains two semaphores. This is necessary
to implement the --kill subcommand which is done in a subsequent patch.
Makefile
dss.c
ipc.c [new file with mode: 0644]
ipc.h [new file with mode: 0644]