[master] 3dc584a Tolerate racing unlinks in vsm cleanup
Nils Goroll
nils.goroll at uplex.de
Wed Nov 15 14:13:04 UTC 2017
commit 3dc584a4ef00aeb2f69478d68a96194538c31b35
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Wed Nov 15 15:04:58 2017 +0100
Tolerate racing unlinks in vsm cleanup
for example, mgt_shm_atexit could race in two processes, one in
VSMW_Destroy and the other in system("rm -rf")
Closes #2484
diff --git a/lib/libvarnish/vsmw.c b/lib/libvarnish/vsmw.c
index ee2a443..a778599 100644
--- a/lib/libvarnish/vsmw.c
+++ b/lib/libvarnish/vsmw.c
@@ -221,7 +221,8 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx)
AZ(munmap(seg->ptr, len));
VTAILQ_REMOVE(&vsmw->segs, seg, list);
- AZ(unlinkat(vsmw->vdirfd, seg->fn, 0));
+ if (unlinkat(vsmw->vdirfd, seg->fn, 0))
+ assert (errno == ENOENT);
REPLACE(seg->fn, NULL);
REPLACE(seg->class, NULL);
REPLACE(seg->id, NULL);
@@ -286,7 +287,8 @@ VSMW_New(int vdirfd, int mode, const char *idxname)
vsmw->pid = getpid();
vsmw->birth = time(NULL);
- (void)unlinkat(vdirfd, vsmw->idx, 0);
+ if (unlinkat(vdirfd, vsmw->idx, 0))
+ assert (errno == ENOENT);
fd = openat(vdirfd,
vsmw->idx, O_APPEND | O_WRONLY | O_CREAT, vsmw->mode);
assert(fd >= 0);
@@ -303,7 +305,8 @@ VSMW_Destroy(struct vsmw **pp)
struct vsmwseg *seg, *s2;
TAKE_OBJ_NOTNULL(vsmw, pp, VSMW_MAGIC);
- AZ(unlinkat(vsmw->vdirfd, vsmw->idx, 0));
+ if (unlinkat(vsmw->vdirfd, vsmw->idx, 0))
+ assert (errno == ENOENT);
REPLACE(vsmw->idx, NULL);
VTAILQ_FOREACH_SAFE(seg, &vsmw->segs, list, s2)
vsmw_delseg(vsmw, seg, 0);
More information about the varnish-commit
mailing list