Răsfoiți Sursa

* Write cache out to socksfile and finish replaying

Caching should not take place while the replay is occuring.
replaying_cache should be checked before calling dprintf(DP_CACHE)
Bryan Drewery 17 ani în urmă
părinte
comite
7c0ee31cb3
4 a modificat fișierele cu 22 adăugiri și 10 ștergeri
  1. 2 1
      src/misc.c
  2. 17 7
      src/mod/server.mod/server.c
  3. 1 1
      src/mod/server.mod/server.h
  4. 2 1
      src/mod/server.mod/servmsg.c

+ 2 - 1
src/misc.c

@@ -681,7 +681,7 @@ readsocks(const char *fname)
       add_server(nserv);
       curserv = 0;
       rehash_server(dcc[servidx].host, nick);
-      replay_cache(servidx);
+      replay_cache(servidx, NULL);
       reset_chans = 1;
     }
   }
@@ -746,6 +746,7 @@ restart(int idx)
   lfprintf(socks->f, STR("+buildts %li\n"), buildts);
   lfprintf(socks->f, STR("+ip4 %s\n"), myipstr(AF_INET));
   lfprintf(socks->f, STR("+ip6 %s\n"), myipstr(AF_INET6));
+  replay_cache(-1, socks->f);
 
   fflush(socks->f);
   socks->my_close();

+ 17 - 7
src/mod/server.mod/server.c

@@ -105,6 +105,7 @@ static bool fast_deq(int);
 static char *splitnicks(char **);
 static void msgq_clear(struct msgq_head *qh);
 static int stack_limit = 4;
+static bool replaying_cache = 0;
 
 /* New bind tables. */
 static bind_table_t *BT_raw = NULL, *BT_msg = NULL;
@@ -371,15 +372,24 @@ char *splitnicks(char **rest)
   return r;
 }
 
-void replay_cache(int idx) {
-  struct msgq *r = NULL, *q = NULL;
+void replay_cache(int idx, FILE *f) {
+  struct msgq *r = NULL;
+  char *p_ptr = NULL, *p = NULL;
 
-  for (r = cacheq.head; r; r = q) {
-    q = r->next;
-    server_activity(idx, r->msg, r->len);
-    free(r->msg);
-    free(r);
+  replaying_cache = 1;
+
+  for (r = cacheq.head; r; r = r->next) {
+    if (f)
+      lfprintf(f, STR("+serv_cache %s\n"), r->msg);
+    else {
+      //Create temporary buffer since server_activity may squash the buffer
+      p_ptr = p = strdup(r->msg);
+      server_activity(idx, p, r->len);
+      free(p_ptr);
+    }
   }
+
+  replaying_cache = 0;
 }
 
 static bool fast_deq(int which)

+ 1 - 1
src/mod/server.mod/server.h

@@ -72,7 +72,7 @@ void clearq(struct server_list *);
 void nuke_server(const char *);
 bool match_my_nick(char *);
 void rehash_server(const char *, const char *);
-void replay_cache(int);
+void replay_cache(int, FILE *);
 void join_chans();
 void check_hostmask();
 void next_server(int *, char *, port_t *, char *);

+ 2 - 1
src/mod/server.mod/servmsg.c

@@ -245,7 +245,8 @@ got005(char *from, char *msg)
   //Cache the results for later parsing if needed (after a restart)
   //Sending 'VERSION' does not work on all servers, plus this speeds
   //up a restart by removing the need to wait for the information
-  dprintf(DP_CACHE, ":%s 005 . %s", from, msg);
+  if (!replaying_cache)
+    dprintf(DP_CACHE, ":%s 005 . %s", from, msg);
 
   while ((tmp = newsplit(&msg))[0]) {
     p = NULL;