summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Incremental.c8
-rw-r--r--mapfile.c16
2 files changed, 11 insertions, 13 deletions
diff --git a/Incremental.c b/Incremental.c
index 35490e7..a8a072d 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -294,7 +294,9 @@ int Incremental(char *devname, int verbose, int runstop,
/* 4/ Check if array exists.
*/
- map_lock(&map);
+ if (map_lock(&map))
+ fprintf(stderr, Name ": failed to get exclusive lock on "
+ "mapfile\n");
mp = map_by_uuid(&map, info.uuid);
if (mp)
mdfd = open_dev(mp->devnum);
@@ -793,7 +795,9 @@ int Incremental_container(struct supertype *st, char *devname, int verbose,
struct mdinfo *ra;
struct map_ent *map = NULL;
- map_lock(&map);
+ if (map_lock(&map))
+ fprintf(stderr, Name ": failed to get exclusive lock on "
+ "mapfile\n");
for (ra = list ; ra ; ra = ra->next) {
int mdfd;
diff --git a/mapfile.c b/mapfile.c
index 79a6bd8..69f78b1 100644
--- a/mapfile.c
+++ b/mapfile.c
@@ -58,7 +58,7 @@ char *mapname[2][3] = {
};
char *mapdir[2] = { MAP_DIR, NULL };
-int mapmode[3] = { O_RDONLY, O_RDWR|O_CREAT, O_RDWR|O_CREAT|O_TRUNC };
+int mapmode[3] = { O_RDONLY, O_RDWR|O_CREAT, O_RDWR|O_CREAT|O_EXCL };
char *mapsmode[3] = { "r", "w", "w"};
FILE *open_map(int modenum, int *choice)
@@ -120,14 +120,11 @@ static int lwhich = 0;
int map_lock(struct map_ent **melp)
{
if (lf == NULL) {
- lf = open_map(2, &lwhich);
+ do {
+ lf = open_map(2, &lwhich);
+ } while (lf == NULL && errno == EEXIST);
if (lf == NULL)
return -1;
- if (flock(fileno(lf), LOCK_EX) != 0) {
- fclose(lf);
- lf = NULL;
- return -1;
- }
}
if (*melp)
map_free(*melp);
@@ -137,10 +134,7 @@ int map_lock(struct map_ent **melp)
void map_unlock(struct map_ent **melp)
{
- if (lf) {
- flock(fileno(lf), LOCK_UN);
- fclose(lf);
- }
+ fclose(lf);
unlink(mapname[lwhich][2]);
lf = NULL;
}