[sane-devel] [RFC] Locking devices via sanei_access lib...

Gerhard Jaeger gerhard@gjaeger.de
Mon, 7 Feb 2005 12:11:49 +0100


Hi list,

while trying to add button-support to the Plustek Backend and playing
around with Rene Rebes' scanbuttond, I noticed, that it'll be a good
idea to have exclusive access to the scanner, while i.e. checking
the buttons or scanning. As this could not be done by simply opening
the device, I decided to create a small library called sanei_access.
The idea is to provide a simple locking mechanism for the backends,
to have exclusive access to one scanner during an operation:

The lib consists of three functions currently:
sanei_access_init()   - of course ;)
sanei_access_lock()   - set the lock
sanei_access_unlock() - unlock it

sanei_access_lock(devname,timeout)
the function tries to create a lock file. Upon creation, the PID
of the process that created the file will be written to the file.
In the current implementation the file is named:
/var/lock/LCK..<devname>
If it's already existent, the PID (which is inside the file) will
be checked, and if the corresponding process is dead, the lockfile
will be captured. That's all.

sanei_access_unlock(devname)
simply removes the lockfile and closes its descriptor.

I think this rather small lib doesn't hurt, so that it can be
included to one of the next releases. I've checked it in to our 
experimental part of the repository for further discussions.

What do you guys think of this lib - is it useful? 

TIA
Gerhard