Message ID | CANSNSoWLXfsYq6kP0niyP8r25S=S1uTKN=+46xnC_SPLBmKXhQ@mail.gmail.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 20017 invoked by alias); 16 Mar 2018 16:18:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 20002 invoked by uid 89); 16 Mar 2018 16:18:42 -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=loginid X-HELO: mail-pf0-f172.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:from:date:message-id:subject:to; bh=3o4pQQxExuzfg0qpeKuLhxWhwk1IssMJ3EgEbN4RC7w=; b=b4qcu+qbMXdIUYa9XtuTaoOcwMSSEPSntUj7rXtDpSXadGYRnUF/J5IjAyxQ/D7Y5R 0qf5ArC/Ceva63hOAtV6+YHgmWGmSRW5ToeCpwwaMy1xG1Qnq1MXx1LUZeWAv149iL5x UtUyWuflIUcTgzjJ88jjpEy+9a2aK/a+l+W6RKGZbKXEDJh9Kr09WxS8s4sBz4cgVswP L02e+HAUZZKmgakr0QzI2iBnPGLHs67+6z3xgHw7MP85jsEyGv0aczffjw6U5SyVHVLh iiAlT9YP8QX1IJmrSySXpQk6sx52tFkzGq+HOOqA1RbxAgkwAfAfjCvcJqwl4F6OanIM c/Ug== X-Gm-Message-State: AElRT7HVwDtUpunihGtPXxa31NBQ07SCCc09gCUleWzu35mpPx5b9H3u qkY94QWIbIBoFIDkHk1Y0/sHpbQP7sJ6fO2G0y9sgylz X-Google-Smtp-Source: AG47ELvuXFQOmUkQki20wHZvfrFAwJ9ENcMJ/M76ZVvUSstom24/HbDznd0XsHpGwNgmO4taLAnOGmmLsLdH+Gxe8Rs= X-Received: by 10.98.27.10 with SMTP id b10mr2043617pfb.121.1521217118724; Fri, 16 Mar 2018 09:18:38 -0700 (PDT) MIME-Version: 1.0 From: Jesse Hathaway <jesse@mbuki-mvuki.org> Date: Fri, 16 Mar 2018 11:18:38 -0500 Message-ID: <CANSNSoWLXfsYq6kP0niyP8r25S=S1uTKN=+46xnC_SPLBmKXhQ@mail.gmail.com> Subject: [PATCH] getlogin_r: return early when linux sentinel value is set To: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" |
Commit Message
Jesse Hathaway
March 16, 2018, 4:18 p.m. UTC
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.
Comments
This is my first time submitting a patch, so any feedback would be very much appreciated. On Fri, Mar 16, 2018 at 11:18 AM, Jesse Hathaway <jesse@mbuki-mvuki.org> 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. > > 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; > + > struct passwd pwd; > struct passwd *tpwd; > int result = 0;
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; >
On Mär 20 2018, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote: > 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. That should be (uid_t) -1. Andreas.
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; + struct passwd pwd; struct passwd *tpwd; int result = 0;