1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

Simplify atomicity of socket creation in bind.

This commit is contained in:
Samuel Thibault
2014-08-28 00:11:54 +02:00
committed by Samuel Thibault
parent 45ef66289a
commit b0f955c9ac
2 changed files with 25 additions and 22 deletions

View File

@ -1,3 +1,10 @@
2014-08-27 Samuel Thibault <samuel.thibault@ens-lyon.org>
Simplify atomicity of socket creation in bind.
* sysdeps/mach/hurd/bind.c (__bind): Use dir_lookup(node, "") instead of
looking up the name after linking the file.
2014-08-27 Allan McRae <allan@archlinux.org> 2014-08-27 Allan McRae <allan@archlinux.org>
* sysdeps/i386/fpu/libm-test-ulps: Update ULPs. * sysdeps/i386/fpu/libm-test-ulps: Update ULPs.

View File

@ -39,7 +39,7 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
{ {
/* For the local domain, we must create a node in the filesystem /* For the local domain, we must create a node in the filesystem
using the ifsock translator and then fetch the address from it. */ using the ifsock translator and then fetch the address from it. */
file_t dir, node; file_t dir, node, ifsock;
char name[len - offsetof (struct sockaddr_un, sun_path) + 1], *n; char name[len - offsetof (struct sockaddr_un, sun_path) + 1], *n;
strncpy (name, addr->sun_path, sizeof name - 1); strncpy (name, addr->sun_path, sizeof name - 1);
@ -63,36 +63,32 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
MACH_MSG_TYPE_COPY_SEND); MACH_MSG_TYPE_COPY_SEND);
if (! err) if (! err)
{ {
/* Link the node, now a socket, into the target directory. */ enum retry_type doretry;
err = __dir_link (dir, node, n, 1); char retryname[1024];
if (err == EEXIST) /* Get a port to the ifsock translator. */
err = __dir_lookup (node, "", 0, 0, &doretry, retryname, &ifsock);
if (! err && (doretry != FS_RETRY_NORMAL || retryname[0] != '\0'))
err = EADDRINUSE; err = EADDRINUSE;
} }
__mach_port_deallocate (__mach_task_self (), node);
if (! err) if (! err)
{ {
/* Get a port to the ifsock translator. */ /* Get the address port. */
file_t ifsock = __file_name_lookup_under (dir, n, 0, 0); err = __ifsock_getsockaddr (ifsock, &aport);
if (ifsock == MACH_PORT_NULL) if (err == MIG_BAD_ID || err == EOPNOTSUPP)
err = EGRATUITOUS;
if (! err)
{ {
err = errno; /* Link the node, now a socket with proper mode, into the
/* If we failed, get rid of the node we created. */ target directory. */
__dir_unlink (dir, n); err = __dir_link (dir, node, n, 1);
} if (err == EEXIST)
else
{
/* Get the address port. */
err = __ifsock_getsockaddr (ifsock, &aport);
if (err == MIG_BAD_ID || err == EOPNOTSUPP)
/* We are not talking to /hurd/ifsock. Probably
someone came in after we linked our node, unlinked
it, and replaced it with a different node, before we
did our lookup. Treat it as if our link had failed
with EEXIST. */
err = EADDRINUSE; err = EADDRINUSE;
if (err)
__mach_port_deallocate (__mach_task_self (), aport);
} }
__mach_port_deallocate (__mach_task_self (), ifsock); __mach_port_deallocate (__mach_task_self (), ifsock);
} }
__mach_port_deallocate (__mach_task_self (), node);
} }
__mach_port_deallocate (__mach_task_self (), dir); __mach_port_deallocate (__mach_task_self (), dir);