From patchwork Thu Mar 22 19:30:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jesse Hathaway X-Patchwork-Id: 26433 Received: (qmail 42489 invoked by alias); 22 Mar 2018 19:30:36 -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 42288 invoked by uid 89); 22 Mar 2018 19:30:21 -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=HX-Received:10.99.174.6 X-HELO: mail-pf0-f170.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=F2R3qtPbmPsHDbcDp1XeVUdy8vtlWZ707hphka+JB+o=; b=cPnmi3OLF6nyCYxaWXbWDySqGvJCsfdlVbFIcNO6r9K6taJ4fUEEv8iPtwvEGbSZ5L ihwV+sSD9ntE1215u8QOK0FbG+78HMNJ2w6BUrD/EFoGa4FcJr0vjLIp8wZvt/CdFWQQ Z6CqnhoDFiUHQV7sJzRX79Mq1aDUUgppONQ7noWe7GiadosI9Vp6DSfjiWCG3UOUnpR2 jEmKRkSLM/KQFU+ZBYUhzVfHaI2QNf8AmowMTGwzNm6zRD3SSpQhwo4t0afE0ZXSYYf0 4/SWlmbEg57jZ5qxcF1gBUF+g9AWS259mjQ5WmfR02EOuSQyALg/Df0s0bixJcAVQbeG fAQQ== X-Gm-Message-State: AElRT7GUd5LojG3MXcRDu1JJt7f+7QfCXZu1VYAnpvAoB6lK2VhJmak3 6ALn9y+jTYpWKmUaMhinRxBSx4xOFL7b8K33x9peoQ== X-Google-Smtp-Source: AG47ELui38vs56ZPQbyd4Ay/LPHDT+0d+HH9s+QXLc4MnuDY9cKyPfdpfFVsIMH2/O7r9a9Dw5Y+AJ7b8k2nrYtRRbw= X-Received: by 10.99.174.6 with SMTP id q6mr3093165pgf.179.1521747005710; Thu, 22 Mar 2018 12:30:05 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <87370s9fns.fsf@linux-m68k.org> References: <73b04097-ef36-b597-4f7c-2e73c6eb9fa3@linaro.org> <877eq6ppkw.fsf@linux-m68k.org> <87370s9fns.fsf@linux-m68k.org> From: Jesse Hathaway Date: Thu, 22 Mar 2018 14:30:04 -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 Thu, Mar 22, 2018 at 12:35 PM, Andreas Schwab wrote: > On Mär 21 2018, Jesse Hathaway wrote: >> + if (uid == (uid_t) - 1) fixed, attached commit 7d60c6ab90d23bab16adc2809de95f99e84862d5 Author: Jesse Hathaway Date: Fri Mar 16 10:46:50 2018 -0500 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. diff --git a/ChangeLog b/ChangeLog index 3399e567b8..5d776d995f 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..14587712a7 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;