summaryrefslogtreecommitdiff
path: root/sysdeps/mach/hurd/bind.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2016-08-20 19:50:45 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2016-08-20 19:50:45 +0200
commit4dd9e35bfd35d3138bc44169baba098005bad51e (patch)
treea4939c43a9c3fe00eb27f023e14acc5e1fe8808c /sysdeps/mach/hurd/bind.c
parentbd42a4599d1b6f77bcfe1e4f67b7cbd9e1cb2dfd (diff)
parentf76453c31593957fec1a99b986bfa5506618b79c (diff)
Merge commit 'refs/top-bases/t/bigmem' into t/bigmem
Diffstat (limited to 'sysdeps/mach/hurd/bind.c')
-rw-r--r--sysdeps/mach/hurd/bind.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/sysdeps/mach/hurd/bind.c b/sysdeps/mach/hurd/bind.c
index 17ef22a7d0..4b09be3635 100644
--- a/sysdeps/mach/hurd/bind.c
+++ b/sysdeps/mach/hurd/bind.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2014 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,7 +25,7 @@
#include <stddef.h>
#include <hurd/ifsock.h>
#include <sys/un.h>
-#include <string.h>
+#include "hurd/hurdsocket.h"
/* Give the socket FD the local address ADDR (which is LEN bytes long). */
int
@@ -37,13 +37,11 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
if (addr->sun_family == AF_LOCAL)
{
+ char *name = _hurd_sun_path_dupa (addr, len);
/* For the local domain, we must create a node in the filesystem
using the ifsock translator and then fetch the address from it. */
- file_t dir, node;
- char name[len - offsetof (struct sockaddr_un, sun_path) + 1], *n;
-
- strncpy (name, addr->sun_path, sizeof name - 1);
- name[sizeof name - 1] = '\0'; /* Make sure */
+ file_t dir, node, ifsock;
+ char *n;
dir = __file_name_split (name, &n);
if (dir == MACH_PORT_NULL)
@@ -63,36 +61,32 @@ __bind (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
MACH_MSG_TYPE_COPY_SEND);
if (! err)
{
- /* Link the node, now a socket, into the target directory. */
- err = __dir_link (dir, node, n, 1);
- if (err == EEXIST)
+ enum retry_type doretry;
+ char retryname[1024];
+ /* 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;
}
- __mach_port_deallocate (__mach_task_self (), node);
if (! err)
{
- /* Get a port to the ifsock translator. */
- file_t ifsock = __file_name_lookup_under (dir, n, 0, 0);
- if (ifsock == MACH_PORT_NULL)
+ /* Get the address port. */
+ err = __ifsock_getsockaddr (ifsock, &aport);
+ if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+ err = EGRATUITOUS;
+ if (! err)
{
- err = errno;
- /* If we failed, get rid of the node we created. */
- __dir_unlink (dir, n);
- }
- 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. */
+ /* Link the node, now a socket with proper mode, into the
+ target directory. */
+ err = __dir_link (dir, node, n, 1);
+ if (err == EEXIST)
err = EADDRINUSE;
+ if (err)
+ __mach_port_deallocate (__mach_task_self (), aport);
}
__mach_port_deallocate (__mach_task_self (), ifsock);
}
+ __mach_port_deallocate (__mach_task_self (), node);
}
__mach_port_deallocate (__mach_task_self (), dir);