From patchwork Wed Mar 21 21:27:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Hathaway X-Patchwork-Id: 26411 Received: (qmail 108461 invoked by alias); 21 Mar 2018 21:28:00 -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 108438 invoked by uid 89); 21 Mar 2018 21:28:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=H*r:sk:x4-v6so X-HELO: mail-pl0-f41.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0oxEgAIkVy0mBU5i/seD8/Z+CiSd8ls3VCGJdvMuJ5I=; b=KM4jkftOZ9qWUc5b19EP+MrNkYR3jTTMdxKhdTPg4shHNmvQD7UDST+eGEeeXumq4x 6MyNHHi2+w7K3vnyhcmCiD9XhqtaCKWl77iMJC/wwhh+J31nlodwL9iBsTXcJfViJwJS D41Vtg7YwK9E3dPdR0Pnlie4P7mQIknsH7hpmHJiR6GiQQv/iIl6jvBBG8NP+QbHF+B4 p5jK9IltdAKOHQXBkKHk8+5r1Jwq2cUHvWG9Jf60k8FoWGmF3vroLesUrN3dW7C6HQtX 8vJHTDXR4vmARU+7EHhD2hGwwfhu5vP7K8wtcTVHytd+79YUjlPHzSHkP2KH9JUu1Bty 4p5Q== X-Gm-Message-State: AElRT7Ef10x5lVafmF4BfF6uXjrStTOzDXZ36HWtF/l/7CykMa8uegjE Vbz4T55MzdV/BDs6T4O3hFhfsmhfN0yHdXIQpjoBNw== X-Google-Smtp-Source: AG47ELunuvgP3tVXM3J+dFtfuetexkqAv6MjzyrvoFlHGe6x3NmB+jeVK+Yl63fFKV08SrDe7lcreU+ZIf2Aqftnuv0= X-Received: by 2002:a17:902:5496:: with SMTP id e22-v6mr14577261pli.81.1521667676893; Wed, 21 Mar 2018 14:27:56 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <877eq6ppkw.fsf@linux-m68k.org> References: <73b04097-ef36-b597-4f7c-2e73c6eb9fa3@linaro.org> <877eq6ppkw.fsf@linux-m68k.org> From: Jesse Hathaway Date: Wed, 21 Mar 2018 16:27:56 -0500 Message-ID: Subject: Re: [PATCH] getlogin_r: return early when linux sentinel value is set To: Andreas Schwab Cc: Adhemerval Zanella , libc-alpha@sourceware.org On Tue, Mar 20, 2018 at 1:30 PM, Andreas Schwab wrote: > Depends on whether you want the linux __getlogin_r to fall back to the > generic __getlogin_r. Thanks, updated patch below: From 04a50b5ee857aa33e1527d70f0676b6daf5a036c Mon Sep 17 00:00:00 2001 From: Jesse Hathaway Date: Fri, 16 Mar 2018 10:46:50 -0500 Subject: [PATCH] getlogin_r: return early when linux sentinel value is set When there is no login uid Linux sets /proc/self/loginid to the sentinel value of, (uid_t) - 1. If this is set we can return early and avoid needlessly looking up the sentinel value in any configured nss databases. Reviewed-by: Adhemerval Zanella diff --git a/ChangeLog b/ChangeLog index 3399e567b8..1ceff1c094 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2018-03-20 Jesse Hathaway (tiny change) + + * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): return early + when linux sentinel value is set. + 2018-03-20 Samuel Thibault * manual/errno.texi (EOWNERDEAD, ENOTRECOVERABLE): Remove errno diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c index 73ea14c8f9..1f90c1ca2d 100644 --- a/sysdeps/unix/sysv/linux/getlogin_r.c +++ b/sysdeps/unix/sysv/linux/getlogin_r.c @@ -55,6 +55,15 @@ __getlogin_r_loginuid (char *name, size_t namesize) endp == uidbuf || *endp != '\0')) return -1; + /* If there is no login uid, linux sets /proc/self/loginid to the sentinel + value of, (uid_t) - 1, so check if that value is set and return early to + avoid making unneeded nss lookups. */ + if (uid == (uid_t) - 1) + { + __set_errno (ENXIO); + return ENXIO; + } + struct passwd pwd; struct passwd *tpwd; int result = 0;