Date: Fri, 6 Apr 2018 17:17:34 +0000 (UTC) From: Brooks Davis <brooks@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332119 - in head/lib/libc: amd64/sys gen i386/sys powerpc/sys powerpc64/sys sparc64/sys Message-ID: <201804061717.w36HHYO3062040@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: brooks Date: Fri Apr 6 17:17:34 2018 New Revision: 332119 URL: https://svnweb.freebsd.org/changeset/base/332119 Log: Remove caching from getlogin(2). This caching has existed since the CSRG import, but serves no obvious purpose. Sure, setlogin() is called rarely, but calls to getlogin() should also be infrequent. The required invalidation was not implemented on aarch64, arm, mips, amd riscv so updates would never occur if getlogin() was called before setlogin(). Reported by: Ali Mashtizadeh <ali@mashtizadeh.com> Reviewed by: kib Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14965 Deleted: head/lib/libc/amd64/sys/setlogin.S head/lib/libc/i386/sys/setlogin.S head/lib/libc/powerpc/sys/setlogin.S head/lib/libc/powerpc64/sys/setlogin.S head/lib/libc/sparc64/sys/setlogin.S Modified: head/lib/libc/amd64/sys/Makefile.inc head/lib/libc/gen/getlogin.c head/lib/libc/i386/sys/Makefile.inc head/lib/libc/powerpc/sys/Makefile.inc head/lib/libc/powerpc64/sys/Makefile.inc head/lib/libc/sparc64/sys/Makefile.inc Modified: head/lib/libc/amd64/sys/Makefile.inc ============================================================================== --- head/lib/libc/amd64/sys/Makefile.inc Fri Apr 6 17:16:50 2018 (r332118) +++ head/lib/libc/amd64/sys/Makefile.inc Fri Apr 6 17:17:34 2018 (r332119) @@ -9,7 +9,7 @@ SRCS+= \ amd64_set_gsbase.c MDASM= vfork.S brk.S cerror.S exect.S getcontext.S \ - sbrk.S setlogin.S + sbrk.S # Don't generate default code for these syscalls: NOASM+= vfork.o Modified: head/lib/libc/gen/getlogin.c ============================================================================== --- head/lib/libc/gen/getlogin.c Fri Apr 6 17:16:50 2018 (r332118) +++ head/lib/libc/gen/getlogin.c Fri Apr 6 17:17:34 2018 (r332119) @@ -47,62 +47,33 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" -#define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&logname_mutex) -#define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&logname_mutex) - extern int _getlogin(char *, int); -int _logname_valid __hidden; /* known to setlogin() */ -static pthread_mutex_t logname_mutex = PTHREAD_MUTEX_INITIALIZER; - -static char * -getlogin_basic(int *status) -{ - static char logname[MAXLOGNAME]; - - if (_logname_valid == 0) { - if (_getlogin(logname, sizeof(logname)) < 0) { - *status = errno; - return (NULL); - } - _logname_valid = 1; - } - *status = 0; - return (*logname ? logname : NULL); -} - char * getlogin(void) { - char *result; - int status; + static char logname[MAXLOGNAME]; - THREAD_LOCK(); - result = getlogin_basic(&status); - THREAD_UNLOCK(); - return (result); + if (_getlogin(logname, sizeof(logname)) < 0) + return (NULL); + return (logname[0] != '\0' ? logname : NULL); } int getlogin_r(char *logname, int namelen) { - char *result; + char tmpname[MAXLOGNAME]; int len; - int status; if (namelen < 1) return (ERANGE); logname[0] = '\0'; - THREAD_LOCK(); - result = getlogin_basic(&status); - if (status == 0 && result != NULL) { - len = strlen(result) + 1; - if (len > namelen) - status = ERANGE; - else - strncpy(logname, result, len); - } - THREAD_UNLOCK(); - return (status); + if (_getlogin(tmpname, sizeof(tmpname)) < 0) + return (errno); + len = strlen(tmpname) + 1; + if (len > namelen) + return (ERANGE); + strlcpy(logname, tmpname, len); + return (0); } Modified: head/lib/libc/i386/sys/Makefile.inc ============================================================================== --- head/lib/libc/i386/sys/Makefile.inc Fri Apr 6 17:16:50 2018 (r332118) +++ head/lib/libc/i386/sys/Makefile.inc Fri Apr 6 17:17:34 2018 (r332119) @@ -8,7 +8,7 @@ SRCS+= i386_get_fsbase.c i386_get_gsbase.c i386_get_io i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S \ - sbrk.S setlogin.S syscall.S + sbrk.S syscall.S NOASM+= vfork.o Modified: head/lib/libc/powerpc/sys/Makefile.inc ============================================================================== --- head/lib/libc/powerpc/sys/Makefile.inc Fri Apr 6 17:16:50 2018 (r332118) +++ head/lib/libc/powerpc/sys/Makefile.inc Fri Apr 6 17:17:34 2018 (r332119) @@ -1,3 +1,3 @@ # $FreeBSD$ -MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S +MDASM+= brk.S cerror.S exect.S sbrk.S Modified: head/lib/libc/powerpc64/sys/Makefile.inc ============================================================================== --- head/lib/libc/powerpc64/sys/Makefile.inc Fri Apr 6 17:16:50 2018 (r332118) +++ head/lib/libc/powerpc64/sys/Makefile.inc Fri Apr 6 17:17:34 2018 (r332119) @@ -1,3 +1,3 @@ # $FreeBSD$ -MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S +MDASM+= brk.S cerror.S exect.S sbrk.S Modified: head/lib/libc/sparc64/sys/Makefile.inc ============================================================================== --- head/lib/libc/sparc64/sys/Makefile.inc Fri Apr 6 17:16:50 2018 (r332118) +++ head/lib/libc/sparc64/sys/Makefile.inc Fri Apr 6 17:17:34 2018 (r332119) @@ -12,4 +12,4 @@ SRCS+= __sparc_sigtramp_setup.c \ CFLAGS+= -I${LIBC_SRCTOP}/sparc64/fpu -MDASM+= brk.S cerror.S exect.S sbrk.S setlogin.S sigaction1.S +MDASM+= brk.S cerror.S exect.S sbrk.S sigaction1.S
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804061717.w36HHYO3062040>