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