Browse Source

* Last commit reverted as it was insignificant
* Disabled all memory allocations after a segfault (Fixes CPU spinning)


svn: 2174

Bryan Drewery 21 years ago
parent
commit
ff05f19f62
5 changed files with 16 additions and 11 deletions
  1. 1 1
      doc/UPDATES
  2. 6 0
      src/compat/memutil.c
  3. 2 0
      src/debug.c
  4. 1 1
      src/debug.h
  5. 6 9
      src/mod/server.mod/servmsg.c

+ 1 - 1
doc/UPDATES

@@ -154,7 +154,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fixed cosmetic bug with removing ignores.
 * cmd_dump now has a substitution. '$n' is replaced with the bot's current IRC nick.
 * Added rate var 'flood-g' which will set +g for 60 seconds after this many msgs:sec has been detected. (#74)
-* Fixed a possible cause for cpu spinning on segfault.
+* Disabled all memory allocations after a segfault (Fixes CPU spinning)
 
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 6 - 0
src/compat/memutil.c

@@ -30,6 +30,9 @@ strdup(const char *entry)
 
 void *my_calloc(size_t nmemb, size_t size)
 {
+  if (segfaulted)
+    return NULL;
+
   void *ptr = calloc(nmemb, size);
 
   if (ptr == NULL)
@@ -40,6 +43,9 @@ void *my_calloc(size_t nmemb, size_t size)
 
 void *my_realloc(void *ptr, size_t size)
 {
+  if (segfaulted)
+    return NULL;
+
   void *x = realloc(ptr, size);
 
   if (x == NULL && size > 0)

+ 2 - 0
src/debug.c

@@ -30,6 +30,7 @@
 #include <sys/mman.h>
 
 bool		sdebug = 0;             /* enable debug output? */
+bool		segfaulted = 0;
 
 
 #ifdef DEBUG_CONTEXT
@@ -202,6 +203,7 @@ static void got_segv(int) __attribute__ ((noreturn));
 
 static void got_segv(int z)
 {
+  segfaulted = 1;
   alarm(0);		/* dont let anything jump out of this signal! */
   signal(SIGSEGV, SIG_DFL);
   /* stackdump(0); */

+ 1 - 1
src/debug.h

@@ -30,7 +30,7 @@
 #define debug4(x,a1,a2,a3,a4)   putlog(LOG_DEBUG,"*",x,a1,a2,a3,a4)
 
 
-extern bool		sdebug;
+extern bool		sdebug, segfaulted;
 
 void stackdump(int);
 void setlimits();

+ 6 - 9
src/mod/server.mod/servmsg.c

@@ -303,13 +303,8 @@ static int got442(char *from, char *msg)
 void nuke_server(const char *reason)
 {
   if (serv >= 0 && servidx >= 0) {
-    if (reason) {
-      char buf[101] = "";
-      size_t len = 0;
-
-      len = simple_snprintf(buf, sizeof(buf), "QUIT :%s\r\n", reason);
-      write_to_server(buf, len);
-    }
+    if (reason)
+      dprintf(DP_DUMP, "QUIT :%s\n", reason);
 
     sleep(1);
     disconnect_server(servidx, DO_LOST);
@@ -1006,8 +1001,10 @@ static void connect_server(void);
 static void kill_server(int idx, void *x)
 {
   disconnect_server(idx, NO_LOST);	/* eof_server will lostdcc() it. */
-  for (struct chanset_t *chan = chanset; chan; chan = chan->next)
-     clear_channel(chan, 1);
+
+  if (!segfaulted)		// don't bother if we've segfaulted, too many memory calls in this loop
+    for (struct chanset_t *chan = chanset; chan; chan = chan->next)
+       clear_channel(chan, 1);
   /* A new server connection will be automatically initiated in
      about 2 seconds. */
 }