* $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_HUB))
+ AddC('H');
+
+ if (feature_bool(FEAT_IDLE_FROM_MSG))
+ AddC('M');
+
+ if (feature_bool(FEAT_RELIABLE_CLOCK))
+ AddC('R');
+
#if defined(USE_POLL) && defined(HAVE_POLL_H)
- 'U',
-#endif
-#ifdef VIRTUAL_HOST
- 'v',
-#endif
-#ifdef BADCHAN
- 'W',
-#ifdef LOCAL_BADCHAN
- 'x',
+ AddC('U');
#endif
-#endif
-#ifdef USE_SYSLOG
- 'Y',
-#endif
- '\0'
-};
-/* *INDENT-ON* */
+ serveropts[i] = '\0';
+ return serveropts;
+}
/*
- * open_debugfile
+ * debug_init
*
* 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
* 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.
*/
-void open_debugfile(void)
+void debug_init(int use_tty)
{
#ifdef DEBUGMODE
if (debuglevel >= 0) {
- printf("isatty = %d ttyname = %#x\n", isatty(2), (unsigned int)ttyname(2));
- if (!(bootopt & BOOT_TTY)) {
- int fd;
- /*
- * leave debugging output on fd 2
- */
- if ((fd = open(LOGFILE, O_CREAT | O_WRONLY | O_APPEND, 0600)) < 0) {
- if ((fd = open("/dev/null", O_WRONLY)) < 0)
- exit(-1);
- }
- if (fd != 2) {
- dup2(fd, 2);
- close(fd);
- }
- }
+ printf("isatty = %d ttyname = %s\n", isatty(2), ttyname(2));
+ log_debug_init(use_tty);
}
#endif
}
#ifdef DEBUGMODE
-static char debugbuf[1024];
-
void vdebug(int level, const char *form, va_list vl)
{
+ static int loop = 0;
int err = errno;
- if ((debuglevel >= 0) && (level <= debuglevel))
+ if (!loop && (debuglevel >= 0) && (level <= debuglevel))
{
- vsprintf(debugbuf, form, vl);
- fprintf(stderr, "%s\n", debugbuf);
+ loop = 1;
+ log_vwrite(LS_DEBUG, L_DEBUG, 0, form, vl);
+ loop = 0;
}
errno = err;
}
static void debug_enumerator(struct Client* cptr, const char* msg)
{
assert(0 != cptr);
- sendto_one(cptr, ":%s %d %s :%s", me.name, RPL_STATSDEBUG, cptr->name, msg);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":%s", msg);
}
/*
* different field names for "struct rusage".
* -avalon
*/
-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 - me.since, debug_enumerator);
+ os_get_rusage(cptr, CurrentTime - cli_since(&me), debug_enumerator);
- sendto_one(cptr, ":%s %d %s :DBUF alloc %d used %d",
- me.name, RPL_STATSDEBUG, nick, DBufAllocCount, DBufUsedCount);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":DBUF alloc %d used %d",
+ DBufAllocCount, DBufUsedCount);
}
#endif /* DEBUGMODE */
-void count_memory(struct Client *cptr, char *nick)
+void count_memory(struct Client *cptr, const struct StatDesc *sd,
+ char *param)
{
struct Client *acptr;
struct SLink *link;
struct Channel *chptr;
struct ConfItem *aconf;
- struct ConfClass *cltmp;
+ const struct ConnectionClass* cltmp;
struct Membership* member;
- int lc = 0, /* local clients */
+ int acc = 0, /* accounts */
+ c = 0, /* clients */
+ cn = 0, /* connections */
ch = 0, /* channels */
lcc = 0, /* local client conf links */
- rc = 0, /* remote clients */
us = 0, /* user structs */
chi = 0, /* channel invites */
chb = 0, /* channel bans */
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 */
- lcm = 0, /* memory used by local clients */
- rcm = 0, /* memory used by remote clients */
+ cm = 0, /* memory used by clients */
+ cnm = 0, /* memory used by connections */
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 */
+ msgbuf_allocated = 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 = acptr->next)
+ for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr))
{
+ c++;
if (MyConnect(acptr))
{
- lc++;
- for (link = acptr->confs; link; link = link->next)
+ cn++;
+ for (link = cli_confs(acptr); link; link = link->next)
lcc++;
}
- else
- rc++;
- if (acptr->user)
+ if (cli_user(acptr))
{
us++;
- for (link = acptr->user->invited; link; link = link->next)
+ for (link = cli_user(acptr)->invited; link; link = link->next)
usi++;
- for (member = acptr->user->channel; member; member = member->next_channel)
+ for (member = cli_user(acptr)->channel; member; member = member->next_channel)
++memberships;
- if (acptr->user->away)
+ if (cli_user(acptr)->away)
{
aw++;
- awm += (strlen(acptr->user->away) + 1);
+ awm += (strlen(cli_user(acptr)->away) + 1);
}
}
+
+ if (IsAccount(acptr))
+ acc++;
}
- lcm = lc * CLIENT_LOCAL_SIZE;
- rcm = rc * CLIENT_REMOTE_SIZE;
+ cm = c * sizeof(struct Client);
+ cnm = cn * sizeof(struct Connection);
for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
{
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)
com += sizeof(struct ConfItem);
}
- for (cltmp = classes; cltmp; cltmp = cltmp->next)
+ for (cltmp = get_class_list(); cltmp; cltmp = cltmp->next)
cl++;
- sendto_one(cptr, ":%s %d %s :Client Local %d(" SIZE_T_FMT
- ") Remote %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, lc, lcm, rc, rcm);
- sendto_one(cptr, ":%s %d %s :Users %d(" SIZE_T_FMT
- ") Invites %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, us, us * sizeof(struct User), usi,
- usi * sizeof(struct SLink));
- sendto_one(cptr,
- ":%s %d %s :User channels %d(" SIZE_T_FMT ") Aways %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, memberships,
- memberships * sizeof(struct Membership), aw, awm);
- sendto_one(cptr, ":%s %d %s :Attached confs %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, lcc, lcc * sizeof(struct SLink));
-
- totcl = lcm + rcm + us * sizeof(struct User) + memberships * sizeof(struct Membership) + awm;
+ 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) 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,
+ memberships * sizeof(struct Membership), aw, awm);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Attached confs %d(%zu)",
+ lcc, lcc * sizeof(struct SLink));
+
+ totcl = cm + cnm + us * sizeof(struct User) + memberships * sizeof(struct Membership) + awm;
totcl += lcc * sizeof(struct SLink) + usi * sizeof(struct SLink);
- sendto_one(cptr, ":%s %d %s :Conflines %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, co, com);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Conflines %d(%zu)", co,
+ com);
- sendto_one(cptr, ":%s %d %s :Classes %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, cl, cl * sizeof(struct ConfClass));
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Classes %d(%zu)", cl,
+ cl * sizeof(struct ConnectionClass));
- sendto_one(cptr, ":%s %d %s :Channels %d(" SIZE_T_FMT
- ") Bans %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, ch, chm, chb, chbm);
- sendto_one(cptr, ":%s %d %s :Channel membrs %d(" SIZE_T_FMT ") invite %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, memberships, memberships * sizeof(struct Membership),
- chi, chi * sizeof(struct SLink));
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":Channels %d(%zu) Bans %d(%zu)", ch, chm, chb, chbm);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":Channel membrs %d(%zu) invite %d(%zu)", memberships,
+ memberships * sizeof(struct Membership), chi,
+ chi * sizeof(struct SLink));
totch = chm + chbm + chi * sizeof(struct SLink);
- sendto_one(cptr, ":%s %d %s :Whowas users %d(" SIZE_T_FMT
- ") away %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, wwu, wwu * sizeof(struct User), wwa, wwam);
- sendto_one(cptr, ":%s %d %s :Whowas array %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, NICKNAMEHISTORYLENGTH, wwm);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":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)",
+ feature_int(FEAT_NICKNAMEHISTORYLENGTH), wwm);
totww = wwu * sizeof(struct User) + wwam + wwm;
- sendto_one(cptr, ":%s %d %s :Hash: client %d(" SIZE_T_FMT
- "), chan is the same",
- me.name, RPL_STATSDEBUG, nick, HASHSIZE, sizeof(void *) * HASHSIZE);
+ 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);
/*
* NOTE: this count will be accurate only for the exact instant that this
* are sent.
*/
dbuf_count_memory(&dbufs_allocated, &dbufs_used);
- sendto_one(cptr,
- ":%s %d %s :DBufs allocated %d(" SIZE_T_FMT ") used %d(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, DBufAllocCount, dbufs_allocated,
- DBufUsedCount, dbufs_used);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":DBufs allocated %d(%zu) used %d(%zu)", DBufAllocCount,
+ dbufs_allocated, DBufUsedCount, dbufs_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);
tot =
- totww + totch + totcl + com + cl * sizeof(struct ConfClass) + dbufs_allocated +
- rm;
+ totww + totch + totcl + com + cl * sizeof(struct ConnectionClass) +
+ dbufs_allocated + msg_allocated + msgbuf_allocated + rm;
tot += sizeof(void *) * HASHSIZE * 3;
-#if !defined(NDEBUG)
- sendto_one(cptr, ":%s %d %s :Allocations: " SIZE_T_FMT "(" SIZE_T_FMT ")",
- me.name, RPL_STATSDEBUG, nick, fda_get_block_count(),
- fda_get_byte_count());
+#if defined(MDEBUG)
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Allocations: %zu(%zu)",
+ fda_get_block_count(), fda_get_byte_count());
#endif
- sendto_one(cptr, ":%s %d %s :Total: ww " SIZE_T_FMT " ch " SIZE_T_FMT
- " cl " SIZE_T_FMT " co " SIZE_T_FMT " db " SIZE_T_FMT,
- me.name, RPL_STATSDEBUG, nick, totww, totch, totcl, com, dbufs_allocated);
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
+ ":Total: ww %zu ch %zu cl %zu co %zu db %zu ms %zu mb %zu",
+ totww, totch, totcl, com, dbufs_allocated, msg_allocated,
+ msgbuf_allocated);
}