Commit 1a5883c5 1a5883c5ff44b27d6e4762f0e6a2003285fc4d68 by Sam Roberts

(locker_set_default_flags) new function to set the default locking flags

Fixed bug wherein lock count wasn't incremented for external locking.
Fixed bug wherein the right flags wasn't checked during union init.
1 parent 7efcb301
......@@ -68,6 +68,13 @@ extern "C" {
#define MU_LOCKER_DEFAULT (MU_LOCKER_RETRY)
/* Use these flags for as the default locker flags (the default defaults
* 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));
/* A flags of 0 means that the default will be used. */
extern int locker_create __P ((locker_t *, const char *filename, int flags));
extern void locker_destroy __P ((locker_t *));
......
......@@ -87,6 +87,18 @@ 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;
int locker_set_default_flags(int flags)
{
if(flags == 0)
flags = MU_LOCKER_DEFAULT;
locker_default_flags = flags;
return 0;
}
int
locker_create (locker_t *plocker, const char *filename, int flags)
{
......@@ -102,8 +114,9 @@ locker_create (locker_t *plocker, const char *filename, int flags)
if (l == NULL)
return ENOMEM;
/* Should make l->file be the resulting of following the symlinks. */
l->file = strdup (filename);
/* Should make l->file be the result of following the symlinks. */
l->file = strdup(filename);
if (l->file == NULL)
{
free (l);
......@@ -115,14 +128,14 @@ locker_create (locker_t *plocker, const char *filename, int flags)
else if (flags)
l->flags = flags;
else
l->flags = MU_LOCKER_DEFAULT;
l->flags = locker_default_flags;
l->expire_time = MU_LOCKER_EXPIRE_TIME;
l->retries = MU_LOCKER_RETRIES;
l->retry_sleep = MU_LOCKER_RETRY_SLEEP;
/* Initialize locker-type-specific data */
if (flags & MU_LOCKER_EXTERNAL)
if (l->flags & MU_LOCKER_EXTERNAL)
{
if (!(l->data.external.name = strdup (MU_LOCKER_EXTERNAL_PROGRAM)))
{
......@@ -130,7 +143,7 @@ locker_create (locker_t *plocker, const char *filename, int flags)
return ENOMEM;
}
}
else if (!(flags & MU_LOCKER_KERNEL))
else if (!(l->flags & MU_LOCKER_KERNEL))
{
l->data.dot.dotlock = malloc (strlen (l->file)
+ 5 /*strlen(".lock")*/ + 1);
......@@ -799,6 +812,7 @@ lock_external (locker_t l, int lock)
break;
case MU_DL_EX_OK:
err = 0;
l->refcnt = lock;
break;
case MU_DL_EX_NEXIST:
err = MU_ERR_LOCK_NOT_HELD;
......