Package: netcat-openbsd Version: 1.89-4 Tags: patch In order to successfully bind() in AF_UNIX, the specified pathname must not already exist. If it was previously bound, ie was a socket, but no-one is listening any more, bind() will fail with EADDRINUSE. This isn't helpful. In particular, it means that if you do this: nc -v -l -U spong ^C nc -v -l -U spong the 2nd invocation is bound to fail.
This patch changes the behaviour so that we always call unlink(). That might cause unintended reuse of the socket pathname, but there is no reliable way with an AF_UNIX socket to atomically tell whether the socket is in use. It is better to be optimistic (and succeed in multiple runs) and risk unlinking a live socket. People who want some kind of locking can arrange that themselves. This patch doesn't have any error handling but then the error handling in most of netcat is pretty shoddy and it's not clear that reporting errors from unlink would be in keeping with the error handling approach elsewhere. Observed behaviour: $ rm -f spong $ nc.openbsd -U -l -v spong [sits waiting for connection] ^C $ nc.openbsd -U -l -v spong nc.openbsd: Address already in use $ Desired behaviour: $ nc.openbsd -U -l -v spong [sits waiting for connection] ^C $ nc.openbsd -U -l -v spong [sits waiting for connection] Ian. commit 28364d030822d3b5380383178d2e7cb31e395676 Author: Ian Jackson <i...@liberator.relativity.greenend.org.uk> Date: Tue Apr 27 23:08:13 2010 +0100 remove paths supplied to unix_listen diff --git a/netcat.c b/netcat.c index eac43f8..8f2ac8e 100644 --- a/netcat.c +++ b/netcat.c @@ -504,6 +504,8 @@ unix_listen(char *path) return (-1); } + unlink(path); + if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) { close(s); return (-1); -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org