mirror of
https://github.com/tmux/tmux.git
synced 2026-04-16 03:56:28 +00:00
Cache user from getpwuid because it can be very expensive on some
platforms. From Ben Maurer in GitHub issue 4973.
This commit is contained in:
15
format.c
15
format.c
@@ -1616,9 +1616,13 @@ format_cb_client_user(struct format_tree *ft)
|
||||
struct passwd *pw;
|
||||
|
||||
if (ft->c != NULL) {
|
||||
if (ft->c->user != NULL)
|
||||
return (xstrdup(ft->c->user));
|
||||
uid = proc_get_peer_uid(ft->c->peer);
|
||||
if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL)
|
||||
return (xstrdup(pw->pw_name));
|
||||
if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL) {
|
||||
ft->c->user = xstrdup(pw->pw_name);
|
||||
return (xstrdup(ft->c->user));
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
@@ -3076,10 +3080,13 @@ format_cb_uid(__unused struct format_tree *ft)
|
||||
static void *
|
||||
format_cb_user(__unused struct format_tree *ft)
|
||||
{
|
||||
static char *cached;
|
||||
struct passwd *pw;
|
||||
|
||||
if ((pw = getpwuid(getuid())) != NULL)
|
||||
return (xstrdup(pw->pw_name));
|
||||
if (cached == NULL && (pw = getpwuid(getuid())) != NULL)
|
||||
cached = xstrdup(pw->pw_name);
|
||||
if (cached != NULL)
|
||||
return (xstrdup(cached));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user