Cache last uid, gid to make translation faster.
This commit is contained in:
parent
62c1415826
commit
6f6553dfb7
1 changed files with 21 additions and 4 deletions
|
|
@ -47,13 +47,20 @@ isdisk(struct stat *st)
|
||||||
#define _HAVESTGEN
|
#define _HAVESTGEN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Caching the last group and passwd looked up is
|
||||||
|
* a significant win (stupidly enough) on most systems.
|
||||||
|
* It's not safe for threaded programs, but neither is using
|
||||||
|
* getpwnam in the first place, so I'm not too worried.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
_p9dir(struct stat *st, char *name, Dir *d, char **str, char *estr)
|
_p9dir(struct stat *st, char *name, Dir *d, char **str, char *estr)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
char tmp[20];
|
char tmp[20];
|
||||||
struct group *g;
|
static struct group *g;
|
||||||
struct passwd *p;
|
static struct passwd *p;
|
||||||
|
static int gid, uid;
|
||||||
int sz;
|
int sz;
|
||||||
|
|
||||||
sz = 0;
|
sz = 0;
|
||||||
|
|
@ -82,7 +89,12 @@ _p9dir(struct stat *st, char *name, Dir *d, char **str, char *estr)
|
||||||
sz += strlen(s)+1;
|
sz += strlen(s)+1;
|
||||||
|
|
||||||
/* user */
|
/* user */
|
||||||
|
if(p && st->st_uid == uid && p->pw_uid == uid)
|
||||||
|
;
|
||||||
|
else{
|
||||||
p = getpwuid(st->st_uid);
|
p = getpwuid(st->st_uid);
|
||||||
|
uid = st->st_uid;
|
||||||
|
}
|
||||||
if(p == nil){
|
if(p == nil){
|
||||||
snprint(tmp, sizeof tmp, "%d", (int)st->st_uid);
|
snprint(tmp, sizeof tmp, "%d", (int)st->st_uid);
|
||||||
s = tmp;
|
s = tmp;
|
||||||
|
|
@ -100,7 +112,12 @@ _p9dir(struct stat *st, char *name, Dir *d, char **str, char *estr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* group */
|
/* group */
|
||||||
|
if(g && st->st_gid == gid && g->gr_gid == gid)
|
||||||
|
;
|
||||||
|
else{
|
||||||
g = getgrgid(st->st_gid);
|
g = getgrgid(st->st_gid);
|
||||||
|
gid = st->st_gid;
|
||||||
|
}
|
||||||
if(g == nil){
|
if(g == nil){
|
||||||
snprint(tmp, sizeof tmp, "%d", (int)st->st_gid);
|
snprint(tmp, sizeof tmp, "%d", (int)st->st_gid);
|
||||||
s = tmp;
|
s = tmp;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue