From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2339 invoked by alias); 20 Mar 2018 08:00:51 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 123388 invoked by uid 89); 20 Mar 2018 08:00:34 -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,SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:n9-v6mr, HContent-Transfer-Encoding:8bit X-HELO: mail-it0-f45.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZsSiD6Xn5em6Q3rE3pVLF+QYBmJUwY6434x9FO3EE4Q=; b=DXbtFsajgXWMH9jDbXxHt+yrFG8Et4nkYOInw2yAP086md0MJyKQwjgLmNNCnTqjHI c3MyY4OfAC4PJm3OqY8JQgKcXow8tGtPgJuCq/nSKKhQrUXoGv8FkDcwLU8OcKFk7G75 9I8I6gEENZ3fJBxiX1yGOowbriRu/gIa5HFNJGV506cBEUzB4D6keY4rq+gBxABo/+5V L9Nd4zplEO4FLPpujThdfVVf4sVPU1xivpu9gs7iE9wl/oLXLAn6qEdXJdOqf5kxiZhd 7YXXovJUesJNRqGQXe5dCNz6aJuapCx/5WEYWvzUgVW6NdFgg2apJ1XR6wChMSmNAYb9 SDDw== X-Gm-Message-State: AElRT7HWaVpv2eu93bNKcxby0VJPK5Pk3oGzGROrauWSAFKaR1WjAgQT NvxrhXZiYh7E9aC64Vb/fUTwZph4DMk= X-Google-Smtp-Source: AIpwx4+DfhEz6hNWWDzYT0QMlzG+dj3KRvSbgMo1pOayNKl0RJY+OoUh2DZOJ15cTd47jtkx0AIW3Q== X-Received: by 2002:a24:d309:: with SMTP id n9-v6mr1870569itg.0.1521532830575; Tue, 20 Mar 2018 01:00:30 -0700 (PDT) Subject: Re: [PATCH] getlogin_r: return early when linux sentinel value is set To: libc-alpha@sourceware.org References: From: Adhemerval Zanella Message-ID: <73b04097-ef36-b597-4f7c-2e73c6eb9fa3@linaro.org> Date: Tue, 20 Mar 2018 08:00:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2018-03/txt/msg00485.txt.bz2 On 17/03/2018 00:18, Jesse Hathaway wrote: > When there is no login uid Linux sets /proc/self/loginid to the sentinel > value of 4294967295. If this is set we can return early and avoid > needlessly looking up the sentinel value in any configured nss > databases. The change is short enough so I think it won't require a copyright assignment. However it does require a ChangeLog entry, could you please resend the patch with a proper one? > > diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c > b/sysdeps/unix/sysv/linux/getlogin_r.c > index 73ea14c8f9..43f55a2188 100644 > --- a/sysdeps/unix/sysv/linux/getlogin_r.c > +++ b/sysdeps/unix/sysv/linux/getlogin_r.c > @@ -55,6 +55,12 @@ __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 4294967295, so check if the value is set and return early to > + avoid making unneeded nss lookups. */ > + if (uid == 4294967295) > + return ENXIO; I prefer to just use either (int)-1 or just 0xffffffff. Also, __getlogin_r_loginuid should set errno itself as for ERANGE instead of just return its value (errno won't be set in this case and I think it got it wrong for ENOMEM in this case). > + > struct passwd pwd; > struct passwd *tpwd; > int result = 0; >