The current locking uses lockf, and is completely broken.
When you hold a lockf lock, any close of any fd on that file will
release the lock. So map_read() call which is made as soon as we get
the lock, will immediately drop the lock.
So change to flock locking which isn't so badly designed.
Signed-off-by: NeilBrown <neilb@suse.de>
* one that we can.
*/
#include "mdadm.h"
+#include <sys/file.h>
#include <ctype.h>
#define mapnames(base) { #base, #base ".new", #base ".lock"}
lf = open_map(2, &lwhich);
if (lf == NULL)
return -1;
- if (lockf(fileno(lf), F_LOCK, 0) != 0) {
+ if (flock(fileno(lf), LOCK_EX) != 0) {
fclose(lf);
lf = NULL;
return -1;
void map_unlock(struct map_ent **melp)
{
- if (lf)
+ if (lf) {
+ flock(fileno(lf), LOCK_UN);
fclose(lf);
+ }
unlink(mapname[lwhich][2]);
lf = NULL;
}