From patchwork Fri Dec 28 21:32:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1019252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98850-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="OVyQQB2e"; dkim-atps=neutral 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 43RKgb2C05z9s3q for ; Sat, 29 Dec 2018 08:32:59 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=Gxe uzWNTeRlrFEg90g2cx9ytNIBZH4Ab7qdR8608rtFuXh+x97LUDD3bjYahODb4KbA LGOVPKLnTMhNvm2a0LCnfQMwzOOh5kkMrN3gE7G0iyVhwySoObxmZ2Vr80/k/sAy y4IMrmvCf41KUKyzYR8W5GRs0THqTWfu0+m1JjsQ= 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:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=NsJrfFNKo OBe+/tGJY+y7+HpIiQ=; b=OVyQQB2e/7fblTF6jt5+zmboXw6Ela3A5G63CHZ4T Z0HWS6hhHUqIfdR4KGdNgZbP4ChWGJbROhBG/l+eZ67ScD+jk8GUF4O3v7a7XXqe lpGmSjFWr46cy4m8QArM/hj62ZdwhqQMhTT/nFBl7O/I/Iv2wEztGwKqnND9kZV6 Fw= Received: (qmail 24251 invoked by alias); 28 Dec 2018 21:32:54 -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 24240 invoked by uid 89); 28 Dec 2018 21:32:53 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=winter, Winter, retry, sees X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Justus Winter <4winter@informatik.uni-hamburg.de>, commit-hurd@gnu.org Subject: [hurd,commited] hurd: Handle "pid" magical lookup retry Date: Fri, 28 Dec 2018 22:32:44 +0100 Message-Id: <20181228213244.24918-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 From: Justus Winter <4winter@informatik.uni-hamburg.de> * hurd/lookup-retry: Include . (__hurd_file_name_lookup_retry): Keep a ref on last result in `lastdir'. Release it on return. Handle "pid" magical lookup retry. --- ChangeLog | 6 ++++ hurd/lookup-retry.c | 78 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63ceb48de6..a2170167c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-12-28 Justus Winter <4winter@informatik.uni-hamburg.de> + + * hurd/lookup-retry: Include . + (__hurd_file_name_lookup_retry): Keep a ref on last result in `lastdir'. + Release it on return. Handle "pid" magical lookup retry. + 2018-12-28 Rafal Luzynski [BZ #10496] diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c index b596848624..53cacdab15 100644 --- a/hurd/lookup-retry.c +++ b/hurd/lookup-retry.c @@ -25,6 +25,7 @@ #include #include <_itoa.h> #include +#include /* Translate the error from dir_lookup into the error the user sees. */ static inline error_t @@ -59,6 +60,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) error_t err; char *file_name; int nloops; + file_t lastdir = MACH_PORT_NULL; error_t lookup_op (file_t startdir) { @@ -107,14 +109,15 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) { case FS_RETRY_REAUTH: if (err = reauthenticate (*result)) - return err; + goto out; /* Fall through. */ case FS_RETRY_NORMAL: if (nloops++ >= __eloop_threshold ()) { __mach_port_deallocate (__mach_task_self (), *result); - return ELOOP; + err = ELOOP; + goto out; } /* An empty RETRYNAME indicates we have the final port. */ @@ -180,7 +183,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) if (err) __mach_port_deallocate (__mach_task_self (), *result); - return err; + goto out; } startdir = *result; @@ -195,7 +198,10 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) if (*result != MACH_PORT_NULL) __mach_port_deallocate (__mach_task_self (), *result); if (nloops++ >= __eloop_threshold ()) - return ELOOP; + { + err = ELOOP; + goto out; + } file_name = &retryname[1]; break; @@ -214,7 +220,8 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) (*end != '/' && *end != '\0')) { errno = save; - return ENOENT; + err = ENOENT; + goto out; } if (! get_dtable_port) err = EGRATUITOUS; @@ -232,9 +239,12 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) } errno = save; if (err) - return err; + goto out; if (*end == '\0') - return 0; + { + err = 0; + goto out; + } else { /* Do a normal retry on the remaining components. */ @@ -261,9 +271,12 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) if (err = __host_info (__mach_host_self (), HOST_BASIC_INFO, (integer_t *) &hostinfo, &hostinfocnt)) - return err; + goto out; if (hostinfocnt != HOST_BASIC_INFO_COUNT) - return EGRATUITOUS; + { + err = EGRATUITOUS; + goto out; + } p = _itoa (hostinfo.cpu_subtype, &retryname[8], 10, 0); *--p = '/'; p = _itoa (hostinfo.cpu_type, &retryname[8], 10, 0); @@ -299,10 +312,11 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) } case '\0': - return opentty (result); + err = opentty (result); + goto out; case '/': if (err = opentty (&startdir)) - return err; + goto out; strcpy (retryname, &retryname[4]); break; default: @@ -312,14 +326,48 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) goto bad_magic; break; + case 'p': + if (retryname[1] == 'i' && retryname[2] == 'd' && + (retryname[3] == '/' || retryname[3] == 0)) + { + char *p, buf[1024]; /* XXX */ + size_t len; + p = _itoa (__getpid (), &buf[sizeof buf], 10, 0); + len = &buf[sizeof buf] - p; + memcpy (buf, p, len); + strcpy (buf + len, &retryname[3]); + strcpy (retryname, buf); + + /* Do a normal retry on the remaining components. */ + __mach_port_mod_refs (__mach_task_self (), lastdir, + MACH_PORT_RIGHT_SEND, 1); + startdir = lastdir; + file_name = retryname; + } + else + goto bad_magic; + break; + default: bad_magic: - return EGRATUITOUS; + err = EGRATUITOUS; + goto out; } break; default: - return EGRATUITOUS; + err = EGRATUITOUS; + goto out; + } + + if (MACH_PORT_VALID (*result) && *result != lastdir) + { + if (MACH_PORT_VALID (lastdir)) + __mach_port_deallocate (__mach_task_self (), lastdir); + + lastdir = *result; + __mach_port_mod_refs (__mach_task_self (), lastdir, + MACH_PORT_RIGHT_SEND, 1); } if (startdir != MACH_PORT_NULL) @@ -332,6 +380,10 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) err = (*use_init_port) (dirport, &lookup_op); } while (! err); +out: + if (MACH_PORT_VALID (lastdir)) + __mach_port_deallocate (__mach_task_self (), lastdir); + return err; } weak_alias (__hurd_file_name_lookup_retry, hurd_file_name_lookup_retry)