home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / other / irc / ircd / s_debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-14  |  11.6 KB  |  481 lines

  1. /************************************************************************
  2.  *   IRC - Internet Relay Chat, ircd/s_debug.c
  3.  *   Copyright (C) 1990 Jarkko Oikarinen and
  4.  *                      University of Oulu, Computing Center
  5.  *
  6.  *   This program is free software; you can redistribute it and/or modify
  7.  *   it under the terms of the GNU General Public License as published by
  8.  *   the Free Software Foundation; either version 1, or (at your option)
  9.  *   any later version.
  10.  *
  11.  *   This program is distributed in the hope that it will be useful,
  12.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *   GNU General Public License for more details.
  15.  *
  16.  *   You should have received a copy of the GNU General Public License
  17.  *   along with this program; if not, write to the Free Software
  18.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef lint
  22. static  char sccsid[] = "@(#)s_debug.c    2.30 1/3/94 (C) 1988 University of Oulu, \
  23. Computing Center and Jarkko Oikarinen";
  24. #endif
  25.  
  26. #include "struct.h"
  27. /*
  28.  * Option string.  Must be before #ifdef DEBUGMODE.
  29.  */
  30. char    serveropts[] = {
  31. #ifdef    SENDQ_ALWAYS
  32. 'A',
  33. #endif
  34. #ifdef    CHROOTDIR
  35. 'c',
  36. #endif
  37. #ifdef    CMDLINE_CONFIG
  38. 'C',
  39. #endif
  40. #ifdef    DO_ID
  41. 'd',
  42. #endif
  43. #ifdef    DEBUGMODE
  44. 'D',
  45. #endif
  46. #ifdef    LOCOP_REHASH
  47. 'e',
  48. #endif
  49. #ifdef    OPER_REHASH
  50. 'E',
  51. #endif
  52. #ifdef    NOTE_FORWARDER
  53. 'f',
  54. #endif
  55. #ifdef    HUB
  56. 'H',
  57. #endif
  58. #ifdef    SHOW_INVISIBLE_LUSERS
  59. 'i',
  60. #endif
  61. #ifndef    NO_DEFAULT_INVISIBLE
  62. 'I',
  63. #endif
  64. #ifdef    OPER_KILL
  65. # ifdef  LOCAL_KILL_ONLY
  66. 'k',
  67. # else
  68. 'K',
  69. # endif
  70. #endif
  71. #ifdef    LEAST_IDLE
  72. 'L',
  73. #endif
  74. #ifdef    M4_PREPROC
  75. 'm',
  76. #endif
  77. #ifdef    IDLE_FROM_MSG
  78. 'M',
  79. #endif
  80. #ifdef    CRYPT_OPER_PASSWORD
  81. 'p',
  82. #endif
  83. #ifdef    CRYPT_LINK_PASSWORD
  84. 'P',
  85. #endif
  86. #ifdef    NPATH
  87. 'N',
  88. #endif
  89. #ifdef    LOCOP_RESTART
  90. 'r',
  91. #endif
  92. #ifdef    OPER_RESTART
  93. 'R',
  94. #endif
  95. #ifdef    ENABLE_SUMMON
  96. 'S',
  97. #endif
  98. #ifdef    OPER_REMOTE
  99. 't',
  100. #endif
  101. #ifdef    IRCII_KLUDGE
  102. 'u',
  103. #endif
  104. #ifdef    ENABLE_USERS
  105. 'U',
  106. #endif
  107. #ifdef    VALLOC
  108. 'V',
  109. #endif
  110. #ifdef    UNIXPORT
  111. 'X',
  112. #endif
  113. #ifdef    USE_SYSLOG
  114. 'Y',
  115. #endif
  116. #ifdef    V28PlusOnly
  117. '8',
  118. #endif
  119. '\0'};
  120.  
  121. #include "numeric.h"
  122. #include "common.h"
  123. #include "sys.h"
  124. #include "whowas.h"
  125. #include "hash.h"
  126. #include <sys/file.h>
  127. #ifdef HPUX
  128. #include <fcntl.h>
  129. #endif
  130. #if !defined(ULTRIX) && !defined(SGI) && !defined(sequent) && \
  131.     !defined(__convex__)
  132. # include <sys/param.h>
  133. #endif
  134. #ifdef HPUX
  135. # include <sys/syscall.h>
  136. # define getrusage(a,b) syscall(SYS_GETRUSAGE, a, b)
  137. #endif
  138. #ifdef GETRUSAGE_2
  139. # ifdef SOL20
  140. #  include <sys/time.h>
  141. #  include <sys/rusage.h>
  142. # endif
  143. # include <sys/resource.h>
  144. #else
  145. #  ifdef TIMES_2
  146. #   include <sys/times.h>
  147. #  endif
  148. #endif
  149. #ifdef PCS
  150. # include <time.h>
  151. #endif
  152. #ifdef HPUX
  153. #include <unistd.h>
  154. #ifdef DYNIXPTX
  155. #include <sys/types.h>
  156. #include <time.h>
  157. #endif
  158. #endif
  159. #include "h.h"
  160.  
  161. #ifndef ssize_t
  162. #define ssize_t unsigned int
  163. #endif
  164.  
  165. #ifdef DEBUGMODE
  166. static    char    debugbuf[1024];
  167.  
  168. #ifndef    USE_VARARGS
  169. /*VARARGS2*/
  170. void    debug(level, form, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
  171. int    level;
  172. char    *form, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
  173. {
  174. #else
  175. void    debug(level, form, va_alist)
  176. int    level;
  177. char    *form;
  178. va_dcl
  179. {
  180.     va_list    vl;
  181.  
  182.     va_start(vl);
  183. #endif
  184.     int    err = errno;
  185.  
  186. #ifdef    USE_SYSLOG
  187.     if (level == DEBUG_ERROR)
  188.         syslog(LOG_ERR, form, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  189. #endif
  190.     if ((debuglevel >= 0) && (level <= debuglevel))
  191.         {
  192. #ifndef    USE_VARARGS
  193.         (void)sprintf(debugbuf, form,
  194.                 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  195. #else
  196.         (void)vsprintf(debugbuf, form, vl);
  197. #endif
  198.         if (local[2])
  199.             {
  200.             local[2]->sendM++;
  201.             local[2]->sendB += strlen(debugbuf);
  202.             }
  203.         (void)fprintf(stderr, "%s", debugbuf);
  204.         (void)fputc('\n', stderr);
  205.         }
  206.     errno = err;
  207. }
  208.  
  209. /*
  210.  * This is part of the STATS replies. There is no offical numeric for this
  211.  * since this isnt an official command, in much the same way as HASH isnt.
  212.  * It is also possible that some systems wont support this call or have
  213.  * different field names for "struct rusage".
  214.  * -avalon
  215.  */
  216. void    send_usage(cptr, nick)
  217. aClient *cptr;
  218. char    *nick;
  219. {
  220.  
  221. #ifdef GETRUSAGE_2
  222.     struct    rusage    rus;
  223.     time_t    secs, rup;
  224. #ifdef    hz
  225. # define hzz hz
  226. #else
  227. # ifdef HZ
  228. #  define hzz HZ
  229. # else
  230.     int    hzz = 1;
  231. #  ifdef HPUX
  232.     hzz = (int)sysconf(_SC_CLK_TCK);
  233. #  endif
  234. # endif
  235. #endif
  236.  
  237.     if (getrusage(RUSAGE_SELF, &rus) == -1)
  238.         {
  239.         extern char *sys_errlist[];
  240.         sendto_one(cptr,":%s NOTICE %s :Getruseage error: %s.",
  241.                me.name, nick, sys_errlist[errno]);
  242.         return;
  243.         }
  244.     secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
  245.     rup = time(NULL) - me.since;
  246.     if (secs == 0)
  247.         secs = 1;
  248.  
  249.     sendto_one(cptr,
  250.            ":%s %d %s :CPU Secs %d:%d User %d:%d System %d:%d",
  251.            me.name, RPL_STATSDEBUG, nick, secs/60, secs%60,
  252.            rus.ru_utime.tv_sec/60, rus.ru_utime.tv_sec%60,
  253.            rus.ru_stime.tv_sec/60, rus.ru_stime.tv_sec%60);
  254.     sendto_one(cptr, ":%s %d %s :RSS %d ShMem %d Data %d Stack %d",
  255.            me.name, RPL_STATSDEBUG, nick, rus.ru_maxrss,
  256.            rus.ru_ixrss / (rup * hzz), rus.ru_idrss / (rup * hzz),
  257.            rus.ru_isrss / (rup * hzz));
  258.     sendto_one(cptr, ":%s %d %s :Swaps %d Reclaims %d Faults %d",
  259.            me.name, RPL_STATSDEBUG, nick, rus.ru_nswap,
  260.            rus.ru_minflt, rus.ru_majflt);
  261.     sendto_one(cptr, ":%s %d %s :Block in %d out %d",
  262.            me.name, RPL_STATSDEBUG, nick, rus.ru_inblock,
  263.            rus.ru_oublock);
  264.     sendto_one(cptr, ":%s %d %s :Msg Rcv %d Send %d",
  265.            me.name, RPL_STATSDEBUG, nick, rus.ru_msgrcv, rus.ru_msgsnd);
  266.     sendto_one(cptr, ":%s %d %s :Signals %d Context Vol. %d Invol %d",
  267.            me.name, RPL_STATSDEBUG, nick, rus.ru_nsignals,
  268.            rus.ru_nvcsw, rus.ru_nivcsw);
  269. #else
  270. # ifdef TIMES_2
  271.     struct    tms    tmsbuf;
  272.     time_t    secs, mins;
  273.     int    hzz = 1, ticpermin;
  274.     int    umin, smin, usec, ssec;
  275.  
  276. #  ifdef HPUX
  277.     hzz = sysconf(_SC_CLK_TCK);
  278. #  endif
  279.     ticpermin = hzz * 60;
  280.  
  281.     umin = tmsbuf.tms_utime / ticpermin;
  282.     usec = (tmsbuf.tms_utime%ticpermin)/(float)hzz;
  283.     smin = tmsbuf.tms_stime / ticpermin;
  284.     ssec = (tmsbuf.tms_stime%ticpermin)/(float)hzz;
  285.     secs = usec + ssec;
  286.     mins = (secs/60) + umin + smin;
  287.     secs %= hzz;
  288.  
  289.     if (times(&tmsbuf) == -1)
  290.         {
  291.         sendto_one(cptr,":%s %d %s :times(2) error: %s.",
  292.                me.name, RPL_STATSDEBUG, nick, strerror(errno));
  293.         return;
  294.         }
  295.     secs = tmsbuf.tms_utime + tmsbuf.tms_stime;
  296.  
  297.     sendto_one(cptr,
  298.            ":%s %d %s :CPU Secs %d:%d User %d:%d System %d:%d",
  299.            me.name, RPL_STATSDEBUG, nick, mins, secs, umin, usec,
  300.            smin, ssec);
  301. # endif
  302. #endif
  303.     sendto_one(cptr, ":%s %d %s :Reads %d Writes %d",
  304.            me.name, RPL_STATSDEBUG, nick, readcalls, writecalls);
  305.     sendto_one(cptr, ":%s %d %s :DBUF alloc %d blocks %d",
  306.            me.name, RPL_STATSDEBUG, nick, dbufalloc, dbufblocks);
  307.     sendto_one(cptr,
  308.            ":%s %d %s :Writes:  <0 %d 0 %d <16 %d <32 %d <64 %d",
  309.            me.name, RPL_STATSDEBUG, nick,
  310.            writeb[0], writeb[1], writeb[2], writeb[3], writeb[4]);
  311.     sendto_one(cptr,
  312.            ":%s %d %s :<128 %d <256 %d <512 %d <1024 %d >1024 %d",
  313.            me.name, RPL_STATSDEBUG, nick,
  314.            writeb[5], writeb[6], writeb[7], writeb[8], writeb[9]);
  315.     return;
  316. }
  317. #endif
  318.  
  319. void    count_memory(cptr, nick)
  320. aClient    *cptr;
  321. char    *nick;
  322. {
  323.     extern    aChannel    *channel;
  324.     extern    aClass    *classes;
  325.     extern    aConfItem    *conf;
  326.  
  327.     Reg1 aClient *acptr;
  328.     Reg2 Link *link;
  329.     Reg3 aChannel *chptr;
  330.     Reg4 aConfItem *aconf;
  331.     Reg5 aClass *cltmp;
  332.  
  333.     int    lc = 0,        /* local clients */
  334.         ch = 0,        /* channels */
  335.         lcc = 0,    /* local client conf links */
  336.         rc = 0,        /* remote clients */
  337.         us = 0,        /* user structs */
  338.         chu = 0,    /* channel users */
  339.         chi = 0,    /* channel invites */
  340.         chb = 0,    /* channel bans */
  341.         wwu = 0,    /* whowas users */
  342.         cl = 0,        /* classes */
  343.         co = 0;        /* conf lines */
  344.  
  345.     int    usi = 0,    /* users invited */
  346.         usc = 0,    /* users in channels */
  347.         aw = 0,        /* aways set */
  348.         wwa = 0;    /* whowas aways */
  349.  
  350.     u_long    chm = 0,    /* memory used by channels */
  351.         chbm = 0,    /* memory used by channel bans */
  352.         lcm = 0,    /* memory used by local clients */
  353.         rcm = 0,    /* memory used by remote clients */
  354.         awm = 0,    /* memory used by aways */
  355.         wwam = 0,    /* whowas away memory used */
  356.         wwm = 0,    /* whowas array memory used */
  357.         com = 0,    /* memory used by conf lines */
  358.         db = 0,        /* memory used by dbufs */
  359.         rm = 0,        /* res memory used */
  360.         totcl = 0,
  361.         totch = 0,
  362.         totww = 0,
  363.         tot = 0;
  364.  
  365.     count_whowas_memory(&wwu, &wwa, &wwam);
  366.     wwm = sizeof(aName) * NICKNAMEHISTORYLENGTH;
  367.  
  368.     for (acptr = client; acptr; acptr = acptr->next)
  369.         {
  370.         if (MyConnect(acptr))
  371.             {
  372.             lc++;
  373.             for (link = acptr->confs; link; link = link->next)
  374.                 lcc++;
  375.             }
  376.         else
  377.             rc++;
  378.         if (acptr->user)
  379.            {
  380.             us++;
  381.             for (link = acptr->user->invited; link;
  382.                  link = link->next)
  383.                 usi++;
  384.             for (link = acptr->user->channel; link;
  385.                  link = link->next)
  386.                 usc++;
  387.             if (acptr->user->away)
  388.                 {
  389.                 aw++;
  390.                 awm += (strlen(acptr->user->away)+1);
  391.                 }
  392.            }
  393.         }
  394.     lcm = lc * CLIENT_LOCAL_SIZE;
  395.     rcm = rc * CLIENT_REMOTE_SIZE;
  396.  
  397.     for (chptr = channel; chptr; chptr = chptr->nextch)
  398.         {
  399.         ch++;
  400.         chm += (strlen(chptr->chname) + sizeof(aChannel));
  401.         for (link = chptr->members; link; link = link->next)
  402.             chu++;
  403.         for (link = chptr->invites; link; link = link->next)
  404.             chi++;
  405.         for (link = chptr->banlist; link; link = link->next)
  406.             {
  407.             chb++;
  408.             chbm += (strlen(link->value.cp)+1+sizeof(Link));
  409.             }
  410.         }
  411.  
  412.     for (aconf = conf; aconf; aconf = aconf->next)
  413.         {
  414.         co++;
  415.         com += aconf->host ? strlen(aconf->host)+1 : 0;
  416.         com += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
  417.         com += aconf->name ? strlen(aconf->name)+1 : 0;
  418.         com += sizeof(aConfItem);
  419.         }
  420.  
  421.     for (cltmp = classes; cltmp; cltmp = cltmp->next)
  422.         cl++;
  423.  
  424.     sendto_one(cptr, ":%s %d %s :Client Local %d(%d) Remote %d(%d)",
  425.            me.name, RPL_STATSDEBUG, nick, lc, lcm, rc, rcm);
  426.     sendto_one(cptr, ":%s %d %s :Users %d(%d) Invites %d(%d)",
  427.            me.name, RPL_STATSDEBUG, nick, us, us*sizeof(anUser), usi,
  428.            usi * sizeof(Link));
  429.     sendto_one(cptr, ":%s %d %s :User channels %d(%d) Aways %d(%d)",
  430.            me.name, RPL_STATSDEBUG, nick, usc, usc*sizeof(Link),
  431.            aw, awm);
  432.     sendto_one(cptr, ":%s %d %s :Attached confs %d(%d)",
  433.            me.name, RPL_STATSDEBUG, nick, lcc, lcc*sizeof(Link));
  434.  
  435.     totcl = lcm + rcm + us*sizeof(anUser) + usc*sizeof(Link) + awm;
  436.     totcl += lcc*sizeof(Link) + usi*sizeof(Link);
  437.  
  438.     sendto_one(cptr, ":%s %d %s :Conflines %d(%d)",
  439.            me.name, RPL_STATSDEBUG, nick, co, com);
  440.  
  441.     sendto_one(cptr, ":%s %d %s :Classes %d(%d)",
  442.            me.name, RPL_STATSDEBUG, nick, cl, cl*sizeof(aClass));
  443.  
  444.     sendto_one(cptr, ":%s %d %s :Channels %d(%d) Bans %d(%d)",
  445.            me.name, RPL_STATSDEBUG, nick, ch, chm, chb, chbm);
  446.     sendto_one(cptr, ":%s %d %s :Channel membrs %d(%d) invite %d(%d)",
  447.            me.name, RPL_STATSDEBUG, nick, chu, chu*sizeof(Link),
  448.            chi, chi*sizeof(Link));
  449.  
  450.     totch = chm + chbm + chu*sizeof(Link) + chi*sizeof(Link);
  451.  
  452.     sendto_one(cptr, ":%s %d %s :Whowas users %d(%d) away %d(%d)",
  453.            me.name, RPL_STATSDEBUG, nick, wwu, wwu*sizeof(anUser),
  454.            wwa, wwam);
  455.     sendto_one(cptr, ":%s %d %s :Whowas array %d(%d)",
  456.            me.name, RPL_STATSDEBUG, nick, NICKNAMEHISTORYLENGTH, wwm);
  457.  
  458.     totww = wwu*sizeof(anUser) + wwam + wwm;
  459.  
  460.     sendto_one(cptr, ":%s %d %s :Hash: client %d(%d) chan %d(%d)",
  461.            me.name, RPL_STATSDEBUG, nick, HASHSIZE,
  462.            sizeof(aHashEntry) * HASHSIZE,
  463.            CHANNELHASHSIZE, sizeof(aHashEntry) * CHANNELHASHSIZE);
  464.     db = dbufblocks * sizeof(dbufbuf);
  465.     sendto_one(cptr, ":%s %d %s :Dbuf blocks %d(%d)",
  466.            me.name, RPL_STATSDEBUG, nick, dbufblocks, db);
  467.  
  468.     rm = cres_mem(cptr);
  469.  
  470.     tot = totww + totch + totcl + com + cl*sizeof(aClass) + db + rm;
  471.     tot += sizeof(aHashEntry) * HASHSIZE;
  472.     tot += sizeof(aHashEntry) * CHANNELHASHSIZE;
  473.  
  474.     sendto_one(cptr, ":%s %d %s :Total: ww %d ch %d cl %d co %d db %d",
  475.            me.name, RPL_STATSDEBUG, nick, totww, totch, totcl, com, db);
  476.     sendto_one(cptr, ":%s %d %s :TOTAL: %d sbrk(0)-etext: %u",
  477.            me.name, RPL_STATSDEBUG, nick, tot,
  478.            (u_int)sbrk((size_t)0)-(u_int)sbrk0);
  479.     return;
  480. }
  481.