On Mon, Nov 30, 2020 at 05:30:00PM -0800, Jakub Kicinski wrote: > On Mon, 30 Nov 2020 16:27:47 +0300 Denis Kirjanov wrote: > > in the case of the socket which is bound to an adress ^ address > > there is no sense to create a path in the next attempts > > > > here is a program that shows the issue: > > > > int main() > > { > > int s; > > struct sockaddr_un a; > > > > s = socket(AF_UNIX, SOCK_STREAM, 0); > > if (s<0) > > perror("socket() failed\n"); > > > > printf("First bind()\n"); > > > > memset(&a, 0, sizeof(a)); > > a.sun_family = AF_UNIX; > > strncpy(a.sun_path, "/tmp/.first_bind", sizeof(a.sun_path)); > > > > if ((bind(s, (const struct sockaddr*) &a, sizeof(a))) == -1) > > perror("bind() failed\n"); > > > > printf("Second bind()\n"); > > > > memset(&a, 0, sizeof(a)); > > a.sun_family = AF_UNIX; > > strncpy(a.sun_path, "/tmp/.first_bind_failed", sizeof(a.sun_path)); > > > > if ((bind(s, (const struct sockaddr*) &a, sizeof(a))) == -1) > > perror("bind() failed\n"); > > } > > > > kda@SLES15-SP2:~> ./test > > First bind() > > Second bind() > > bind() failed > > : Invalid argument > > > > kda@SLES15-SP2:~> ls -la /tmp/.first_bind > > .first_bind .first_bind_failed > > > > Signed-off-by: Denis Kirjanov <k...@linux-powerpc.org> > > > > v2: move a new patch creation after the address assignment check. ^ path
> > It is a behavior change, but IDK if anyone can reasonably depend on > current behavior for anything useful. Otherwise LGTM. For the record, we already changed the error code in this case once by commit 0fb44559ffd6 ("af_unix: move unix_mknod() out of bindlock"), this should revert it to the original value. As far as I'm aware, only LTP guys noticed back then. I tried to raise the question in this list but nobody seemed to care so I didn't pursue. Technically, both errors are correct as both "address already in use" and "socket already bound" conditions are met and the manual page (neither linux nor posix) doesn't seem to specify which should take precedence. Michal