From patchwork Wed Aug 27 22:11:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 383591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8F1921400A0 for ; Thu, 28 Aug 2014 08:12:07 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=gggZ Av/ymsiGgL3wI+926hbWB3916roRH7R4jxWQgSv3q9gJ8YRXBEliOINivOGAKfLX 1tZ8pNxTKla+ERiynBr1qY5pi1Z67QWDVIaUomuU67ONt1cHyrI5/rsoUBbYjbCB 6QyvCk+j0j30NkzmZ7wS4dZWa05hL+nQGa9ZRVY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=7Eo6yrUQVT /+bOeq9oBqFkSmxPc=; b=i/jiTqR/Rj2yzhVQME36xxn8eDJU0I1Yqpc+gQyjqy 9C8i38Sj59C+u0ZQaOxACFOQyIIWF1cDVDsjuSEIqebiR4GWjtZyBRBU8ez3pM2Y z74k5vn+htg6HnmnbPp90guIZndiBtURZ1YkuqNQ3vzlJ1Jf88/DcT0CccrbyoiT M= Received: (qmail 24498 invoked by alias); 27 Aug 2014 22:12:01 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 24484 invoked by uid 89); 27 Aug 2014 22:12:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: toccata.ens-lyon.org Date: Thu, 28 Aug 2014 00:11:54 +0200 From: Samuel Thibault To: Roland McGrath Cc: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: Re: [PATCH,Hurd] bind() fails when umask is 0777 Message-ID: <20140827221154.GT3343@type.youpi.perso.aquilenet.fr> Mail-Followup-To: Roland McGrath , libc-alpha@sourceware.org, bug-hurd@gnu.org References: <53B83BBB.7060303@googlemail.com> <20140824192957.GY3053@type.youpi.perso.aquilenet.fr> <20140824200642.GD3053@type.youpi.perso.aquilenet.fr> <20140824211149.GG3053@type.youpi.perso.aquilenet.fr> <20140825120934.GB3213@type.bordeaux.inria.fr> <20140825122157.GC3213@type.bordeaux.inria.fr> <20140826212615.6E7F62C39C1@topped-with-meat.com> <20140827212220.GM3343@type.youpi.perso.aquilenet.fr> <20140827220148.3D1E92C3A2C@topped-with-meat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140827220148.3D1E92C3A2C@topped-with-meat.com> User-Agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30) 2014-08-27 Samuel Thibault 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);