[1892] in Moira

home help back first fref pref prev next nref lref last post

_list_queries

daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Sat Nov 24 16:07:31 2001

Message-Id: <200111242107.QAA03783@brad-majors.mit.edu>
To: moiradev@MIT.EDU
Date: Sat, 24 Nov 2001 16:07:28 -0500
From: Garry Zacheiss <zacheiss@MIT.EDU>

	Two bugs in list_queries(); if we're returning a list specific
to the version of the client, we can't be caching our data, so punt
those static declarations and reinitialize every time through.
Secondly, if we hit the case where a client is too old to know about a
query (q->version > cl->version), we still need to increment q.

Garry

Index: qsubs.c
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/qsubs.c,v
retrieving revision 1.18
diff -u -r1.18 qsubs.c
--- qsubs.c	2000/01/11 05:57:31	1.18
+++ qsubs.c	2001/11/24 21:00:33
@@ -49,28 +49,29 @@
 void list_queries(client *cl, int (*action)(int, char *[], void *),
 		  void *actarg)
 {
-  static struct query **squeries = NULL;
-  static int qcount;
+  struct query **squeries = NULL;
+  int qcount;
   struct query *q, **sq;
   char qnames[80];
   char *qnp;
   int i;
 
-  if (!squeries)
+  squeries = sq = xmalloc(QueryCount * sizeof(struct query *));
+  q = Queries;
+  for (i = 0; i < QueryCount; i++)
     {
-      squeries = sq = xmalloc(QueryCount * sizeof(struct query *));
-      q = Queries;
-      for (i = 0; i < QueryCount; i++)
+      if (q->version > cl->version)
 	{
-	  if (q->version > cl->version)
-	    continue;
-	  if (i > 0 && strcmp((*sq)->name, q->name))
-	    sq++;
-	  *sq = q++;
+	  q++;
+	  continue;
 	}
-      qcount = (sq - squeries) + 1;
-      qsort(squeries, qcount, sizeof(struct query *), qcmp);
+      if (i > 0 && strcmp((*sq)->name, q->name))
+	sq++;
+      *sq = q++;
     }
+  qcount = (sq - squeries) + 1;
+  qsort(squeries, qcount, sizeof(struct query *), qcmp);
+
   sq = squeries;
 
   qnp = qnames;
@@ -85,6 +86,9 @@
   (*action)(1, &qnp, actarg);
   strcpy(qnames, "_list_users");
   (*action)(1, &qnp, actarg);
+
+  free(sq);
+  free(squeries);
 }
 
 void help_query(struct query *q, int (*action)(int, char *[], void *),

home help back first fref pref prev next nref lref last post