Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / s_debug.c
index f1c7afd69e3bbc3c8a362f3e42663b1a6332947f..da1992964b3e5f18424b82108cfa64468ae236d7 100644 (file)
  * $Id$
  *
  */
+#include "config.h"
+
 #include "s_debug.h"
 #include "channel.h"
 #include "class.h"
 #include "client.h"
+#include "gline.h"
 #include "hash.h"
 #include "ircd_alloc.h"
+#include "ircd_features.h"
 #include "ircd_log.h"
 #include "ircd_osdep.h"
 #include "ircd_reply.h"
 #include "ircd.h"
+#include "jupe.h"
 #include "list.h"
+#include "motd.h"
 #include "msgq.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "res.h"
 #include "s_bsd.h"
 #include "s_conf.h"
+#include "s_stats.h"
 #include "send.h"
 #include "struct.h"
 #include "sys.h"
 #include <string.h>
 #include <unistd.h>
 
-/* *INDENT-OFF* */
-
 /*
  * Option string.  Must be before #ifdef DEBUGMODE.
  */
-char serveropts[] = {
-#if BUFFERPOOL < 1000000
-    'b',
-#if BUFFERPOOL > 99999
-    (char)('0' + (BUFFERPOOL/100000)),
-#endif
-#if BUFFERPOOL > 9999
-    (char)('0' + (BUFFERPOOL/10000) % 10),
-#endif
-    (char)('0' + (BUFFERPOOL/1000) % 10),
-#else
-    'B',
-#if BUFFERPOOL > 99999999
-    (char)('0' + (BUFFERPOOL/100000000)),
-#endif
-#if BUFFERPOOL > 9999999
-    (char)('0' + (BUFFERPOOL/10000000) % 10),
-#endif
-    (char)('0' + (BUFFERPOOL/1000000) % 10),
-#endif
-#ifdef  CHROOTDIR
-    'c',
-#endif
-#ifdef  CMDLINE_CONFIG
-    'C',
-#endif
-#ifdef  DO_ID
-    'd',
+static char serveropts[256]; /* should be large enough for anything */
+
+const char* debug_serveropts(void)
+{
+  int bp;
+  int i = 0;
+#define AddC(c)        serveropts[i++] = (c)
+
+  bp = feature_int(FEAT_BUFFERPOOL);
+  if (bp < 1000000) {
+    AddC('b');
+    if (bp > 99999)
+      AddC((char)('0' + (bp / 100000)));
+    if (bp > 9999)
+      AddC((char)('0' + (bp / 10000) % 10));
+    AddC((char)('0' + (bp / 1000) % 10));
+  } else {
+    AddC('B');
+    if (bp > 99999999)
+      AddC((char)('0' + (bp / 100000000)));
+    if (bp > 9999999)
+      AddC((char)('0' + (bp / 10000000) % 10));
+    AddC((char)('0' + (bp / 1000000) % 10));
+  }
+
+#ifndef NDEBUG
+  AddC('A');
 #endif
 #ifdef  DEBUGMODE
-    'D',
-#endif
-#ifdef  LOCOP_REHASH
-    'e',
-#endif
-#ifdef  OPER_REHASH
-    'E',
-#endif
-#ifdef OPER_NO_CHAN_LIMIT
-    'F',
-#endif
-#ifdef OPER_MODE_LCHAN
-    'f',
-#endif
-#ifdef  HUB
-    'H',
-#endif
-#if defined(SHOW_INVISIBLE_USERS) ||  defined(SHOW_ALL_INVISIBLE_USERS)
-#ifdef  SHOW_ALL_INVISIBLE_USERS
-    'I',
-#else
-    'i',
-#endif
-#endif
-#ifdef  OPER_KILL
-#ifdef  LOCAL_KILL_ONLY
-    'k',
-#else
-    'K',
-#endif
-#endif
-#ifdef  LEAST_IDLE
-    'L',
-#endif
-#ifdef OPER_WALK_THROUGH_LMODES
-    'l',
-#endif
-#ifdef  IDLE_FROM_MSG
-    'M',
-#endif
-#ifdef  USEONE
-    'O',
-#endif
-#ifdef NO_OPER_DEOP_LCHAN
-    'o',
-#endif
-#ifdef  CRYPT_OPER_PASSWORD
-    'p',
-#endif
-#ifdef  CRYPT_LINK_PASSWORD
-    'P',
-#endif
-#ifdef  DEBUGMALLOC
-#ifdef  MEMLEAKSTATS
-    'Q',
-#else
-    'q',
-#endif
-#endif
-#ifdef  RELIABLE_CLOCK
-    'R',
-#endif
-#ifdef  LOCOP_RESTART
-    's',
-#endif
-#ifdef  OPER_RESTART
-    'S',
-#endif
-#ifdef  OPER_REMOTE
-    't',
+  AddC('D');
 #endif
+
+  if (feature_bool(FEAT_LOCOP_REHASH))
+    AddC('e');
+
+  if (feature_bool(FEAT_OPER_REHASH))
+    AddC('E');
+
+  if (feature_bool(FEAT_OPER_NO_CHAN_LIMIT))
+    AddC('F');
+
+  if (feature_bool(FEAT_OPER_MODE_LCHAN))
+    AddC('f');
+
+  if (feature_bool(FEAT_HUB))
+    AddC('H');
+
+  if (feature_bool(FEAT_SHOW_ALL_INVISIBLE_USERS))
+    AddC('I');
+  else if (feature_bool(FEAT_SHOW_INVISIBLE_USERS))
+    AddC('i');
+
+  if (feature_bool(FEAT_OPER_KILL)) {
+    if (feature_bool(FEAT_LOCAL_KILL_ONLY))
+      AddC('k');
+    else
+      AddC('K');
+  }
+
+  if (feature_bool(FEAT_OPER_WALK_THROUGH_LMODES))
+    AddC('l');
+
+  if (feature_bool(FEAT_IDLE_FROM_MSG))
+    AddC('M');
+
+  if (feature_bool(FEAT_NO_OPER_DEOP_LCHAN))
+    AddC('o');
+
+  if (feature_bool(FEAT_CRYPT_OPER_PASSWORD))
+    AddC('p');
+
+  if (feature_bool(FEAT_RELIABLE_CLOCK))
+    AddC('R');
+
+  if (feature_bool(FEAT_LOCOP_RESTART))
+    AddC('s');
+
+  if (feature_bool(FEAT_OPER_RESTART))
+    AddC('S');
+
 #if defined(USE_POLL) && defined(HAVE_POLL_H)
-    'U',
-#endif
-#ifdef  VIRTUAL_HOST
-    'v',
+  AddC('U');
 #endif
-#ifdef BADCHAN
-    'W',
-#ifdef LOCAL_BADCHAN
-    'x',
-#endif
-#endif
-    '\0'
-};
 
-/* *INDENT-ON* */
+  if (feature_bool(FEAT_VIRTUAL_HOST))
+    AddC('v');
 
+  serveropts[i] = '\0';
+
+  return serveropts;
+}
 
 /*
  * debug_init
@@ -190,7 +168,7 @@ void debug_init(int use_tty)
 #ifdef  DEBUGMODE
   if (debuglevel >= 0) {
     printf("isatty = %d ttyname = %s\n", isatty(2), ttyname(2));
-    log_debug_init(use_tty ? 0 : LOGFILE);
+    log_debug_init(use_tty);
   }
 #endif
 }
@@ -231,7 +209,8 @@ static void debug_enumerator(struct Client* cptr, const char* msg)
  * different field names for "struct rusage".
  * -avalon
  */
-void send_usage(struct Client *cptr, char *nick)
+void send_usage(struct Client *cptr, struct StatDesc *sd, int stat,
+                char *param)
 {
   os_get_rusage(cptr, CurrentTime - cli_since(&me), debug_enumerator);
 
@@ -240,7 +219,8 @@ void send_usage(struct Client *cptr, char *nick)
 }
 #endif /* DEBUGMODE */
 
-void count_memory(struct Client *cptr, char *nick)
+void count_memory(struct Client *cptr, struct StatDesc *sd, int stat,
+                  char *param)
 {
   struct Client *acptr;
   struct SLink *link;
@@ -249,7 +229,8 @@ void count_memory(struct Client *cptr, char *nick)
   const struct ConnectionClass* cltmp;
   struct Membership* member;
 
-  int c = 0,                    /* clients */
+  int acc = 0,                  /* accounts */
+      c = 0,                    /* clients */
       cn = 0,                   /* connections */
       ch = 0,                   /* channels */
       lcc = 0,                  /* local client conf links */
@@ -263,7 +244,9 @@ void count_memory(struct Client *cptr, char *nick)
 
   int usi = 0,                  /* users invited */
       aw = 0,                   /* aways set */
-      wwa = 0;                  /* whowas aways */
+      wwa = 0,                  /* whowas aways */
+      gl = 0,                   /* glines */
+      ju = 0;                   /* jupes */
 
   size_t chm = 0,               /* memory used by channels */
       chbm = 0,                 /* memory used by channel bans */
@@ -272,18 +255,18 @@ void count_memory(struct Client *cptr, char *nick)
       awm = 0,                  /* memory used by aways */
       wwam = 0,                 /* whowas away memory used */
       wwm = 0,                  /* whowas array memory used */
+      glm = 0,                  /* memory used by glines */
+      jum = 0,                  /* memory used by jupes */
       com = 0,                  /* memory used by conf lines */
       dbufs_allocated = 0,      /* memory used by dbufs */
       dbufs_used = 0,           /* memory used by dbufs */
       msg_allocated = 0,       /* memory used by struct Msg */
-      msg_used = 0,            /* memory used by struct Msg */
       msgbuf_allocated = 0,    /* memory used by struct MsgBuf */
-      msgbuf_used = 0,         /* memory used by struct MsgBuf */
       rm = 0,                   /* res memory used */
       totcl = 0, totch = 0, totww = 0, tot = 0;
 
   count_whowas_memory(&wwu, &wwm, &wwa, &wwam);
-  wwm += sizeof(struct Whowas) * NICKNAMEHISTORYLENGTH;
+  wwm += sizeof(struct Whowas) * feature_int(FEAT_NICKNAMEHISTORYLENGTH);
   wwm += sizeof(struct Whowas *) * WW_MAX;
 
   for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr))
@@ -308,6 +291,9 @@ void count_memory(struct Client *cptr, char *nick)
         awm += (strlen(cli_user(acptr)->away) + 1);
       }
     }
+
+    if (IsAccount(acptr))
+      acc++;
   }
   cm = c * sizeof(struct Client);
   cnm = cn * sizeof(struct Connection);
@@ -316,13 +302,6 @@ void count_memory(struct Client *cptr, char *nick)
   {
     ch++;
     chm += (strlen(chptr->chname) + sizeof(struct Channel));
-#if 0
-    /*
-     * XXX - Members already counted in clients, don't count twice
-     */
-    for (member = chptr->members; member; member = member->next_member)
-      chu++;
-#endif
     for (link = chptr->invites; link; link = link->next)
       chi++;
     for (link = chptr->banlist; link; link = link->next)
@@ -347,7 +326,8 @@ void count_memory(struct Client *cptr, char *nick)
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
             ":Clients %d(%zu) Connections %d(%zu)", c, cm, cn, cnm);
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
-            ":Users %d(%zu) Invites %d(%zu)", us, us * sizeof(struct User),
+            ":Users %d(%zu) Accounts %d(%zu) Invites %d(%zu)",
+             us, us * sizeof(struct User), acc, acc * (ACCOUNTLEN + 1),
             usi, usi * sizeof(struct SLink));
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
             ":User channels %d(%zu) Aways %d(%zu)", memberships,
@@ -377,10 +357,17 @@ void count_memory(struct Client *cptr, char *nick)
             ":Whowas users %d(%zu) away %d(%zu)", wwu,
             wwu * sizeof(struct User), wwa, wwam);
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Whowas array %d(%zu)",
-            NICKNAMEHISTORYLENGTH, wwm);
+            feature_int(FEAT_NICKNAMEHISTORYLENGTH), wwm);
 
   totww = wwu * sizeof(struct User) + wwam + wwm;
 
+  motd_memory_count(cptr);
+
+  gl = gline_memory_count(&glm);
+  ju = jupe_memory_count(&jum);
+  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+            ":Glines %d(%zu) Jupes %d(%zu)", gl, glm, ju, jum);
+
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
             ":Hash: client %d(%zu), chan is the same", HASHSIZE,
             sizeof(void *) * HASHSIZE);
@@ -398,14 +385,10 @@ void count_memory(struct Client *cptr, char *nick)
             ":DBufs allocated %d(%zu) used %d(%zu)", DBufAllocCount,
             dbufs_allocated, DBufUsedCount, dbufs_used);
 
-  msgq_count_memory(&msg_allocated, &msg_used, &msgbuf_allocated,
-                   &msgbuf_used);
-  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
-            ":Msgs allocated %d(%zu) used %d(%zu)", msgCounts.alloc,
-            msg_allocated, msgCounts.used, msg_used);
-  send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
-            ":MsgBufs allocated %d(%zu) used %d(%zu)", msgBufCounts.alloc,
-            msgbuf_allocated, msgBufCounts.used, msgbuf_used);
+  /* The DBuf caveats now count for this, but this routine now sends
+   * replies all on its own.
+   */
+  msgq_count_memory(cptr, &msg_allocated, &msgbuf_allocated);
 
   rm = cres_mem(cptr);
 
@@ -414,7 +397,7 @@ void count_memory(struct Client *cptr, char *nick)
       dbufs_allocated + msg_allocated + msgbuf_allocated + rm;
   tot += sizeof(void *) * HASHSIZE * 3;
 
-#if !defined(NDEBUG)
+#if defined(MDEBUG)
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Allocations: %zu(%zu)",
             fda_get_block_count(), fda_get_byte_count());
 #endif