(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.
Showing
2 changed files
with
26 additions
and
5 deletions
... | @@ -68,6 +68,13 @@ extern "C" { | ... | @@ -68,6 +68,13 @@ extern "C" { |
68 | 68 | ||
69 | #define MU_LOCKER_DEFAULT (MU_LOCKER_RETRY) | 69 | #define MU_LOCKER_DEFAULT (MU_LOCKER_RETRY) |
70 | 70 | ||
71 | /* Use these flags for as the default locker flags (the default defaults | ||
72 | * to MU_LOCKER_DEFAULT). A flags of 0 resets the flags back to the | ||
73 | * the default. | ||
74 | */ | ||
75 | extern int locker_set_default_flags __P((int flags)); | ||
76 | |||
77 | /* A flags of 0 means that the default will be used. */ | ||
71 | extern int locker_create __P ((locker_t *, const char *filename, int flags)); | 78 | extern int locker_create __P ((locker_t *, const char *filename, int flags)); |
72 | extern void locker_destroy __P ((locker_t *)); | 79 | extern void locker_destroy __P ((locker_t *)); |
73 | 80 | ... | ... |
... | @@ -87,6 +87,18 @@ static int _locker_unlock_dotlock __P((locker_t lock)); | ... | @@ -87,6 +87,18 @@ static int _locker_unlock_dotlock __P((locker_t lock)); |
87 | static int _locker_lock_kernel __P((locker_t lock)); | 87 | static int _locker_lock_kernel __P((locker_t lock)); |
88 | static int _locker_unlock_kernel __P((locker_t lock)); | 88 | static int _locker_unlock_kernel __P((locker_t lock)); |
89 | 89 | ||
90 | static int locker_default_flags = MU_LOCKER_DEFAULT; | ||
91 | |||
92 | int locker_set_default_flags(int flags) | ||
93 | { | ||
94 | if(flags == 0) | ||
95 | flags = MU_LOCKER_DEFAULT; | ||
96 | |||
97 | locker_default_flags = flags; | ||
98 | |||
99 | return 0; | ||
100 | } | ||
101 | |||
90 | int | 102 | int |
91 | locker_create (locker_t *plocker, const char *filename, int flags) | 103 | locker_create (locker_t *plocker, const char *filename, int flags) |
92 | { | 104 | { |
... | @@ -102,8 +114,9 @@ locker_create (locker_t *plocker, const char *filename, int flags) | ... | @@ -102,8 +114,9 @@ locker_create (locker_t *plocker, const char *filename, int flags) |
102 | if (l == NULL) | 114 | if (l == NULL) |
103 | return ENOMEM; | 115 | return ENOMEM; |
104 | 116 | ||
105 | /* Should make l->file be the resulting of following the symlinks. */ | 117 | /* Should make l->file be the result of following the symlinks. */ |
106 | l->file = strdup (filename); | 118 | l->file = strdup(filename); |
119 | |||
107 | if (l->file == NULL) | 120 | if (l->file == NULL) |
108 | { | 121 | { |
109 | free (l); | 122 | free (l); |
... | @@ -115,14 +128,14 @@ locker_create (locker_t *plocker, const char *filename, int flags) | ... | @@ -115,14 +128,14 @@ locker_create (locker_t *plocker, const char *filename, int flags) |
115 | else if (flags) | 128 | else if (flags) |
116 | l->flags = flags; | 129 | l->flags = flags; |
117 | else | 130 | else |
118 | l->flags = MU_LOCKER_DEFAULT; | 131 | l->flags = locker_default_flags; |
119 | 132 | ||
120 | l->expire_time = MU_LOCKER_EXPIRE_TIME; | 133 | l->expire_time = MU_LOCKER_EXPIRE_TIME; |
121 | l->retries = MU_LOCKER_RETRIES; | 134 | l->retries = MU_LOCKER_RETRIES; |
122 | l->retry_sleep = MU_LOCKER_RETRY_SLEEP; | 135 | l->retry_sleep = MU_LOCKER_RETRY_SLEEP; |
123 | 136 | ||
124 | /* Initialize locker-type-specific data */ | 137 | /* Initialize locker-type-specific data */ |
125 | if (flags & MU_LOCKER_EXTERNAL) | 138 | if (l->flags & MU_LOCKER_EXTERNAL) |
126 | { | 139 | { |
127 | if (!(l->data.external.name = strdup (MU_LOCKER_EXTERNAL_PROGRAM))) | 140 | if (!(l->data.external.name = strdup (MU_LOCKER_EXTERNAL_PROGRAM))) |
128 | { | 141 | { |
... | @@ -130,7 +143,7 @@ locker_create (locker_t *plocker, const char *filename, int flags) | ... | @@ -130,7 +143,7 @@ locker_create (locker_t *plocker, const char *filename, int flags) |
130 | return ENOMEM; | 143 | return ENOMEM; |
131 | } | 144 | } |
132 | } | 145 | } |
133 | else if (!(flags & MU_LOCKER_KERNEL)) | 146 | else if (!(l->flags & MU_LOCKER_KERNEL)) |
134 | { | 147 | { |
135 | l->data.dot.dotlock = malloc (strlen (l->file) | 148 | l->data.dot.dotlock = malloc (strlen (l->file) |
136 | + 5 /*strlen(".lock")*/ + 1); | 149 | + 5 /*strlen(".lock")*/ + 1); |
... | @@ -799,6 +812,7 @@ lock_external (locker_t l, int lock) | ... | @@ -799,6 +812,7 @@ lock_external (locker_t l, int lock) |
799 | break; | 812 | break; |
800 | case MU_DL_EX_OK: | 813 | case MU_DL_EX_OK: |
801 | err = 0; | 814 | err = 0; |
815 | l->refcnt = lock; | ||
802 | break; | 816 | break; |
803 | case MU_DL_EX_NEXIST: | 817 | case MU_DL_EX_NEXIST: |
804 | err = MU_ERR_LOCK_NOT_HELD; | 818 | err = MU_ERR_LOCK_NOT_HELD; | ... | ... |
-
Please register or sign in to post a comment