This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH,Hurd] bind() fails when umask is 0777
- From: Samuel Thibault <samuel dot thibault at gnu dot org>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: libc-alpha at sourceware dot org, bug-hurd at gnu dot org
- Date: Thu, 28 Aug 2014 00:11:54 +0200
- Subject: Re: [PATCH,Hurd] bind() fails when umask is 0777
- Authentication-results: sourceware.org; auth=none
- References: <53B83BBB dot 7060303 at googlemail dot com> <20140824192957 dot GY3053 at type dot youpi dot perso dot aquilenet dot fr> <20140824200642 dot GD3053 at type dot youpi dot perso dot aquilenet dot fr> <20140824211149 dot GG3053 at type dot youpi dot perso dot aquilenet dot fr> <20140825120934 dot GB3213 at type dot bordeaux dot inria dot fr> <20140825122157 dot GC3213 at type dot bordeaux dot inria dot fr> <20140826212615 dot 6E7F62C39C1 at topped-with-meat dot com> <20140827212220 dot GM3343 at type dot youpi dot perso dot aquilenet dot fr> <20140827220148 dot 3D1E92C3A2C at topped-with-meat dot com>
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.
--- a/sysdeps/mach/hurd/bind.c
+++ b/sysdeps/mach/hurd/bind.c
@@ -40,7 +40,7 @@ __bind (int fd, __CONST_SOCKADDR_ARG ad
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;
+ file_t dir, node, ifsock;
char *n;
dir = __file_name_split (name, &n);
@@ -61,36 +61,32 @@ __bind (int fd, __CONST_SOCKADDR_ARG ad
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);