mirror of
https://github.com/tmux/tmux.git
synced 2026-04-16 12:06:32 +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;
|
struct passwd *pw;
|
||||||
|
|
||||||
if (ft->c != NULL) {
|
if (ft->c != NULL) {
|
||||||
|
if (ft->c->user != NULL)
|
||||||
|
return (xstrdup(ft->c->user));
|
||||||
uid = proc_get_peer_uid(ft->c->peer);
|
uid = proc_get_peer_uid(ft->c->peer);
|
||||||
if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL)
|
if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL) {
|
||||||
return (xstrdup(pw->pw_name));
|
ft->c->user = xstrdup(pw->pw_name);
|
||||||
|
return (xstrdup(ft->c->user));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -3076,10 +3080,13 @@ format_cb_uid(__unused struct format_tree *ft)
|
|||||||
static void *
|
static void *
|
||||||
format_cb_user(__unused struct format_tree *ft)
|
format_cb_user(__unused struct format_tree *ft)
|
||||||
{
|
{
|
||||||
|
static char *cached;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
if ((pw = getpwuid(getuid())) != NULL)
|
if (cached == NULL && (pw = getpwuid(getuid())) != NULL)
|
||||||
return (xstrdup(pw->pw_name));
|
cached = xstrdup(pw->pw_name);
|
||||||
|
if (cached != NULL)
|
||||||
|
return (xstrdup(cached));
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -537,6 +537,7 @@ server_client_free(__unused int fd, __unused short events, void *arg)
|
|||||||
|
|
||||||
if (c->references == 0) {
|
if (c->references == 0) {
|
||||||
free((void *)c->name);
|
free((void *)c->name);
|
||||||
|
free((void *)c->user);
|
||||||
free(c);
|
free(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
tmux.h
1
tmux.h
@@ -1958,6 +1958,7 @@ typedef void (*overlay_resize_cb)(struct client *, void *);
|
|||||||
struct client {
|
struct client {
|
||||||
const char *name;
|
const char *name;
|
||||||
struct tmuxpeer *peer;
|
struct tmuxpeer *peer;
|
||||||
|
const char *user;
|
||||||
struct cmdq_list *queue;
|
struct cmdq_list *queue;
|
||||||
|
|
||||||
struct client_windows windows;
|
struct client_windows windows;
|
||||||
|
|||||||
Reference in New Issue
Block a user