chiark / gitweb /
test: udp-preload: Fix binding, unlink
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Oct 2019 11:31:14 +0000 (12:31 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 12 Oct 2019 22:29:26 +0000 (23:29 +0100)
Avoids EADDRINUSE from the real bind(2).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
test/udp-preload.c

index 6667a67eb2b11ed12bcf065ee1b7fe32202305fa..55e4314e2ef19817c2cae2b202e9df4713574388 100644 (file)
@@ -161,6 +161,7 @@ WRAP(bind) {
     *p++='/';
     if (addrport2str(p,addr,addrlen)) return -1;
 //fprintf(stderr,"binding %s\n",sun.sun_path);
+    if (unlink(sun.sun_path) && errno!=ENOENT) return -1;
     return old_bind(fd,(const void*)&sun,sizeof(sun));
 }