wiki:SourceConventions

Conventions and Idioms used in confman

Locking

There are two kinds of locks that can be obtained: the working copy lock and the system lock. Note that the locking functions will cause confman to exit if the lock cannot be obtained.

local system_lock=$(conf_lock_system)
# do stuff that modifies the system
conf_unlock_system $system_lock

local wcopy_lock=$(conf_lock_wcopy)
# do stuff that modifies the working copy
conf_unlock_wcopy $wcopy_lock

The token returned from the lock functions contains information about whether the lock was obtained recursively. By saving the token for the call to unlock, the locking function is saved frequent bookkeeping regarding a lock's recursive status.