]> Zhao Yanbai Git Server - minix.git/commitdiff
1-sized passwd cache
authorBen Gras <ben@minix3.org>
Wed, 29 Mar 2006 12:44:06 +0000 (12:44 +0000)
committerBen Gras <ben@minix3.org>
Wed, 29 Mar 2006 12:44:06 +0000 (12:44 +0000)
commands/simple/top.c

index d2d1eeab96b4ce26f02abd448e26d250f43b7b8d..826dcfe0062fbb8505da47958faef07a818bc9f3 100644 (file)
@@ -158,10 +158,11 @@ void print_procs(int maxlines,
        maxlines--;
        for(p = 0; p < nprocs; p++) {
                int euid = 0;
-               struct passwd *who = NULL;
                struct proc *pr;
                int pnr, ticks;
                char *name = "";
+               static struct passwd *who = NULL;
+               static int last_who = -1;
 
                if(maxlines-- <= 0) break;
 
@@ -176,7 +177,10 @@ void print_procs(int maxlines,
                        printf("[%3d] ", pnr);
                        name = pr->p_name;
                }
-               who = getpwuid(euid);
+               if(last_who != euid || !who) {
+                       who = getpwuid(euid);
+                       last_who = euid;
+               }
 
                if(who && who->pw_name) printf("%-8s ", who->pw_name);
                else if(pnr >= 0) printf("%8d ", mproc[pnr].mp_effuid);