c6d234
commit cc8a1620eb97ccddd337d157263c13c57b39ab71
c6d234
Author: Jesse Hathaway <jesse@mbuki-mvuki.org>
c6d234
Date:   Tue Mar 27 21:17:59 2018 +0000
c6d234
c6d234
    getlogin_r: return early when linux sentinel value is set
c6d234
    
c6d234
    When there is no login uid Linux sets /proc/self/loginid to the sentinel
c6d234
    value of, (uid_t) -1. If this is set we can return early and avoid
c6d234
    needlessly looking up the sentinel value in any configured nss
c6d234
    databases.
c6d234
    
c6d234
    Checked on aarch64-linux-gnu.
c6d234
    
c6d234
            * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Return
c6d234
            early when linux sentinel value is set.
c6d234
    
c6d234
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
c6d234
c6d234
Index: b/sysdeps/unix/sysv/linux/getlogin_r.c
c6d234
===================================================================
c6d234
--- a/sysdeps/unix/sysv/linux/getlogin_r.c
c6d234
+++ b/sysdeps/unix/sysv/linux/getlogin_r.c
c6d234
@@ -54,6 +54,15 @@ __getlogin_r_loginuid (char *name, size_
c6d234
 	  endp == uidbuf || *endp != '\0'))
c6d234
     return -1;
c6d234
 
c6d234
+  /* If there is no login uid, linux sets /proc/self/loginid to the sentinel
c6d234
+     value of, (uid_t) -1, so check if that value is set and return early to
c6d234
+     avoid making unneeded nss lookups. */
c6d234
+  if (uid == (uid_t) -1)
c6d234
+    {
c6d234
+      __set_errno (ENXIO);
c6d234
+      return ENXIO;
c6d234
+    }
c6d234
+
c6d234
   size_t buflen = 1024;
c6d234
   char *buf = alloca (buflen);
c6d234
   bool use_malloc = false;