Commit b93d4032 b93d40325f26366da3e2e3b0a7e6ec31abb71bac by Sergey Poznyakoff

(enum mu_locker_set_mode): New data type

(locker_set_default_flags): Changed declaration
(locker_set_default_retry_timeout)
(locker_set_default_retry_count)
(locker_set_default_expire_timeout)
(locker_set_default_external_program): New functions
1 parent 25d17848
......@@ -37,6 +37,13 @@ extern "C" {
#define MU_DL_EX_ERROR 1 /* failed due to some other error */
#define MU_DL_EX_OK 0 /* success */
enum mu_locker_set_mode
{
mu_locker_set_flags,
mu_locker_set_bit,
mu_locker_clear_bit
};
/* locker_create() flags */
#define MU_LOCKER_SIMPLE 0x00
......@@ -72,7 +79,11 @@ extern "C" {
* to MU_LOCKER_DEFAULT). A flags of 0 resets the flags back to the
* the default.
*/
extern int locker_set_default_flags __P((int flags));
extern int locker_set_default_flags __P((int flags, enum mu_locker_set_mode mode));
extern void locker_set_default_retry_timeout __P((time_t to));
extern void locker_set_default_retry_count __P((size_t n));
extern void locker_set_default_expire_timeout __P((time_t t));
extern void locker_set_default_external_program __P((char *path));
/* A flags of 0 means that the default will be used. */
extern int locker_create __P ((locker_t *, const char *filename, int flags));
......
......@@ -87,18 +87,60 @@ static int _locker_unlock_dotlock __P((locker_t lock));
static int _locker_lock_kernel __P((locker_t lock));
static int _locker_unlock_kernel __P((locker_t lock));
static int locker_default_flags = MU_LOCKER_DEFAULT;
static int mu_locker_default_flags = MU_LOCKER_DEFAULT;
static time_t mu_locker_retry_timeout = MU_LOCKER_RETRY_SLEEP;
static size_t mu_locker_retry_count = MU_LOCKER_RETRIES;
static time_t mu_locker_expire_timeout = MU_LOCKER_EXPIRE_TIME;
static char *mu_locker_external_program = NULL;
int locker_set_default_flags(int flags)
int
locker_set_default_flags (int flags, enum mu_locker_set_mode mode)
{
if(flags == 0)
flags = MU_LOCKER_DEFAULT;
switch (mode)
{
case mu_locker_set_flags:
mu_locker_default_flags = flags;
break;
case mu_locker_set_bit:
mu_locker_default_flags |= flags;
break;
locker_default_flags = flags;
case mu_locker_clear_bit:
mu_locker_default_flags &= ~flags;
break;
default:
return EINVAL;
}
return 0;
}
void
locker_set_default_retry_timeout (time_t to)
{
mu_locker_retry_timeout = to;
}
void
locker_set_default_retry_count (size_t n)
{
mu_locker_retry_count = n;
}
void
locker_set_default_expire_timeout (time_t t)
{
mu_locker_expire_timeout = t;
}
void
locker_set_default_external_program (char *path)
{
free (mu_locker_external_program);
mu_locker_external_program = strdup (path);
}
int
locker_create (locker_t *plocker, const char *filename_, int flags)
{
......@@ -133,16 +175,18 @@ locker_create (locker_t *plocker, const char *filename_, int flags)
else if (flags)
l->flags = flags;
else
l->flags = locker_default_flags;
l->flags = mu_locker_default_flags;
l->expire_time = MU_LOCKER_EXPIRE_TIME;
l->retries = MU_LOCKER_RETRIES;
l->retry_sleep = MU_LOCKER_RETRY_SLEEP;
l->expire_time = mu_locker_expire_timeout;
l->retries = mu_locker_retry_count;
l->retry_sleep = mu_locker_retry_timeout;
/* Initialize locker-type-specific data */
if (l->flags & MU_LOCKER_EXTERNAL)
{
if (!(l->data.external.name = strdup (MU_LOCKER_EXTERNAL_PROGRAM)))
if (!(l->data.external.name = strdup (mu_locker_external_program ?
mu_locker_external_program :
MU_LOCKER_EXTERNAL_PROGRAM)))
{
locker_destroy (&l);
return ENOMEM;
......