Themis patch to avoid getpwuid and getgrgid

Ragnar Sundblad ragge at nada.kth.se
Thu Jan 17 20:28:37 CET 2002



Hello, drinkers!

Themis do plenty of getpwuids and getgrgids when generating
package style output files. Here is a highly advanced caching
system to avoid that. Enjoy!

/ragge

------

Index: themis.c
===================================================================
RCS file: 
/afs/stacken.kth.se/src/SourceRepository/arla/appl/themis/themis.c,v
retrieving revision 1.86
diff -u -d -b -w -r1.86 themis.c
--- themis.c    2001/12/06 10:41:06     1.86
+++ themis.c    2002/01/16 03:23:36
@@ -1142,6 +1142,42 @@
 }

 /*
+ * caching versions
+ */
+static
+struct passwd*
+my_getpwuid(uid_t uid)
+{
+  static struct passwd *c_p = NULL;
+  static uid_t c_uid = 0;
+
+  if(c_p != NULL && (c_uid == uid))
+    return c_p;
+
+  c_p = getpwuid(uid);
+  c_uid = uid;
+
+  return c_p;
+}
+
+static
+struct group*
+my_getgrgid(gid_t gid)
+{
+  static struct group *c_g = NULL;
+  static gid_t c_gid = 0;
+
+  if(c_g != NULL && (c_gid == gid))
+    return c_g;
+
+  c_g = getgrgid(gid);
+  c_gid = gid;
+
+  return c_g;
+}
+
+
+/*
  * Print the node, with package syntax.
  */

@@ -1252,11 +1288,11 @@
        node->data.fs->type == TYPE_L) {
        struct passwd *p;
        struct group *g;
-       p = getpwuid(node->data.fs->uid);
+       p = my_getpwuid(node->data.fs->uid);
        if (p == NULL) {
            err(1, "getpwgid %d", node->data.fs->uid);
        }
-       g = getgrgid(node->data.fs->gid);
+       g = my_getgrgid(node->data.fs->gid);
        if (g == NULL) {
            err(1, "getgrgid %d", node->data.fs->gid);
        }






More information about the Arla-drinkers mailing list