diff options
author | Roland McGrath <roland@gnu.org> | 1995-12-26 10:00:22 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1995-12-26 10:00:22 +0000 |
commit | be7e3b7e7ef0fb3d632002bda04d0ad0537ced8b (patch) | |
tree | ed3701064cddf156aed81b7799617ecc031f6e1c /sysdeps/mach/hurd/bind.c | |
parent | e0f09b6b2a5a06ee90f962d79aad21274152d052 (diff) | |
download | glibc-be7e3b7e7ef0fb3d632002bda04d0ad0537ced8b.tar.gz glibc-be7e3b7e7ef0fb3d632002bda04d0ad0537ced8b.tar.xz glibc-be7e3b7e7ef0fb3d632002bda04d0ad0537ced8b.zip |
Mon Dec 25 20:56:39 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> cvs/libc-951228 cvs/libc-951227 cvs/libc-951226
* sysdeps/mach/hurd/bind.c: Translate EEXIST from dir_link into EADDRINUSE. If translated node doesn't grok ifsock protocol, return EADDRINUSE. * sysdeps/mach/hurd/connect.c: Make address arg `const struct sockaddr_un *'. The redecl is kosher and avoids another variable for AF_LOCAL case. * sysdeps/mach/hurd/sendto.c: Likewise. * sysdeps/mach/hurd/bind.c: Likewise. * socket/sys/socket.h (__SOCKADDR_ARG): Enable transparent_union code for GCC >= 2.7; use __transparent_union__ for name safety; add several sockaddr flavors. (__SOCKADDR_ALLTYPES, __SOCKADDR_ONETYPE): New macros used in constructing the transparent union declarations. (__CONST_SOCKADDR_ARG): New type (or macro if not GCC 2.7). (bind, connect, sendto): Make the sockaddr argument use that.
Diffstat (limited to 'sysdeps/mach/hurd/bind.c')
-rw-r--r-- | sysdeps/mach/hurd/bind.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/sysdeps/mach/hurd/bind.c b/sysdeps/mach/hurd/bind.c index 399c23ed22..11f268be09 100644 --- a/sysdeps/mach/hurd/bind.c +++ b/sysdeps/mach/hurd/bind.c @@ -32,23 +32,22 @@ Cambridge, MA 02139, USA. */ /* Give the socket FD the local address ADDR (which is LEN bytes long). */ int DEFUN(bind, (fd, addr, len), - int fd AND struct sockaddr *addr AND size_t len) + int fd AND const struct sockaddr_un *addr AND size_t len) { addr_port_t aport; error_t err; - if (addr->sa_family == AF_LOCAL) + if (addr->sun_family == AF_LOCAL) { /* For the local domain, we must create a node in the filesystem using the ifsock translator and then fetch the address from it. */ - struct sockaddr_un *unaddr = (struct sockaddr_un *) addr; file_t dir, node; char name[len - offsetof (struct sockaddr_un, sun_path)], *n; - strncpy (name, unaddr->sun_path, sizeof name); + strncpy (name, addr->sun_path, sizeof name); dir = __file_name_split (name, &n); if (dir == MACH_PORT_NULL) return -1; - + /* Create a new, unlinked node in the target directory. */ err = __dir_mkfile (dir, O_CREAT, 0666 & ~_hurd_umask, &node); @@ -56,15 +55,19 @@ DEFUN(bind, (fd, addr, len), { file_t ifsock; /* Set the node's translator to make it a local-domain socket. */ - err = __file_set_translator (node, + err = __file_set_translator (node, FS_TRANS_EXCL | FS_TRANS_SET, FS_TRANS_EXCL | FS_TRANS_SET, 0, _HURD_IFSOCK, sizeof _HURD_IFSOCK, MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND); if (! err) - /* Link the node, now a socket, into the target directory. */ - err = __dir_link (dir, node, n); + { + /* Link the node, now a socket, into the target directory. */ + err = __dir_link (dir, node, n); + if (err == EEXIST) + err = EADDRINUSE; + } __mach_port_deallocate (__mach_task_self (), node); if (! err) { @@ -78,8 +81,16 @@ DEFUN(bind, (fd, addr, len), } } if (! err) - /* Get the address port. */ - err = __ifsock_getsockaddr (ifsock, &aport); + { + /* 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; + } __mach_port_deallocate (__mach_task_self (), ifsock); } __mach_port_deallocate (__mach_task_self (), dir); @@ -94,7 +105,7 @@ DEFUN(bind, (fd, addr, len), ({ if (err) err = __socket_create_address (port, - addr->sa_family, + addr->sun_family, (char *) addr, len, &aport); if (! err) |