Add '6' to server options when compiled with IPv6 support (and related
[ircu2.10.12-pk.git] / ircd / s_debug.c
index dca9205def79ba1615c22485f0c40e31eb47c587..4a202bfef1b0dc0de4cf2b97bfa38bc6e61881f7 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- *
+ */
+/** @file
+ * @brief Debug support for the ircd.
+ * @version $Id$
  */
 #include "config.h"
 
@@ -26,6 +27,7 @@
 #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_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 "whowas.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 #include <errno.h>
 #include <fcntl.h>
 #include <stdarg.h>
@@ -59,6 +64,9 @@
  */
 static char serveropts[256]; /* should be large enough for anything */
 
+/** Return a string describing important configuration information.
+ * @return Pointer to a static buffer.
+ */
 const char* debug_serveropts(void)
 {
   int bp;
@@ -82,82 +90,42 @@ const char* debug_serveropts(void)
     AddC((char)('0' + (bp / 1000000) % 10));
   }
 
-#ifdef  CHROOTDIR
-  AddC('c');
+#ifndef NDEBUG
+  AddC('A');
 #endif
 #ifdef  DEBUGMODE
   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)
   AddC('U');
 #endif
-
-  if (feature_bool(FEAT_VIRTUAL_HOST))
-    AddC('v');
+#ifdef  IPV6
+  AddC('6');
+#endif
 
   serveropts[i] = '\0';
 
   return serveropts;
 }
 
-/*
- * debug_init
- *
+/** Initialize debugging.
  * If the -t option is not given on the command line when the server is
  * started, all debugging output is sent to the file set by LPATH in config.h
  * Here we just open that file and make sure it is opened to fd 2 so that
  * any fprintf's to stderr also goto the logfile.  If the debuglevel is not
  * set from the command line by -x, use /dev/null as the dummy logfile as long
  * as DEBUGMODE has been defined, else dont waste the fd.
+ * @param use_tty Passed to log_debug_init().
  */
 void debug_init(int use_tty)
 {
@@ -170,6 +138,12 @@ void debug_init(int use_tty)
 }
 
 #ifdef DEBUGMODE
+/** Log a debug message using a va_list.
+ * If the current #debuglevel is less than \a level, do not display.
+ * @param level Debug level for message.
+ * @param form Format string, passed to log_vwrite().
+ * @param vl Varargs argument list for format string.
+ */
 void vdebug(int level, const char *form, va_list vl)
 {
   static int loop = 0;
@@ -184,6 +158,11 @@ void vdebug(int level, const char *form, va_list vl)
   errno = err;
 }
 
+/** Log a debug message using a variable number of arguments.
+ * This is a simple wrapper around debug(\a level, \a form, vl).
+ * @param level Debug level for message.
+ * @param form Format string of message.
+ */
 void debug(int level, const char *form, ...)
 {
   va_list vl;
@@ -192,20 +171,23 @@ void debug(int level, const char *form, ...)
   va_end(vl);
 }
 
+/** Send a literal RPL_STATSDEBUG message to a user.
+ * @param cptr Client to receive the message.
+ * @param msg Text message to send to user.
+ */
 static void debug_enumerator(struct Client* cptr, const char* msg)
 {
   assert(0 != cptr);
   send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":%s", msg);
 }
 
-/*
- * This is part of the STATS replies. There is no offical numeric for this
- * since this isnt an official command, in much the same way as HASH isnt.
- * It is also possible that some systems wont support this call or have
- * different field names for "struct rusage".
- * -avalon
+/** Send resource usage statistics to a client.
+ * @param cptr Client to send data to.
+ * @param sd StatDesc that generated the stats request (ignored).
+ * @param param Extra parameter from user (ignored).
  */
-void send_usage(struct Client *cptr, char *nick)
+void send_usage(struct Client *cptr, const struct StatDesc *sd,
+                char *param)
 {
   os_get_rusage(cptr, CurrentTime - cli_since(&me), debug_enumerator);
 
@@ -214,16 +196,24 @@ void send_usage(struct Client *cptr, char *nick)
 }
 #endif /* DEBUGMODE */
 
-void count_memory(struct Client *cptr, char *nick)
+/** Report memory usage statistics to a client.
+ * @param cptr Client to send data to.
+ * @param sd StatDesc that generated the stats request (ignored).
+ * @param param Extra parameter from user (ignored).
+ */
+void count_memory(struct Client *cptr, const struct StatDesc *sd,
+                  char *param)
 {
   struct Client *acptr;
   struct SLink *link;
+  struct Ban *ban;
   struct Channel *chptr;
   struct ConfItem *aconf;
   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 */
@@ -237,7 +227,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 */
@@ -246,13 +238,13 @@ 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;
 
@@ -282,6 +274,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);
@@ -292,10 +287,10 @@ void count_memory(struct Client *cptr, char *nick)
     chm += (strlen(chptr->chname) + sizeof(struct Channel));
     for (link = chptr->invites; link; link = link->next)
       chi++;
-    for (link = chptr->banlist; link; link = link->next)
+    for (ban = chptr->banlist; link; ban = ban->next)
     {
       chb++;
-      chbm += (strlen(link->value.cp) + 1 + sizeof(struct SLink));
+      chbm += strlen(ban->who) + strlen(ban->banstr) + 2 + sizeof(*ban);
     }
   }
 
@@ -314,7 +309,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,
@@ -348,6 +344,13 @@ void count_memory(struct Client *cptr, char *nick)
 
   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);
@@ -365,14 +368,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);
 
@@ -381,7 +380,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