home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ircd4652.zip / ircd-df-4.6.5-os2 / src / s_debug.c < prev    next >
C/C++ Source or Header  |  1997-12-29  |  13KB  |  521 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    NOTE_FORWARDER
  47. 'f',
  48. #endif
  49. #ifdef    HUB
  50. 'H',
  51. #endif
  52. #ifdef    SHOW_INVISIBLE_LUSERS
  53. 'i',
  54. #endif
  55. #ifndef    NO_DEFAULT_INVISIBLE
  56. 'I',
  57. #endif
  58. #ifdef    LEAST_IDLE
  59. 'L',
  60. #endif
  61. #ifdef    M4_PREPROC
  62. 'm',
  63. #endif
  64. #ifdef    IDLE_FROM_MSG
  65. 'M',
  66. #endif
  67. #ifdef    CRYPT_OPER_PASSWORD
  68. 'p',
  69. #endif
  70. #ifdef    CRYPT_LINK_PASSWORD
  71. 'P',
  72. #endif
  73. #ifdef NOSPOOF
  74. 'n',
  75. #endif
  76. #ifdef    NPATH
  77. 'N',
  78. #endif
  79. #ifdef SCRIPTINIFIX
  80. 's',
  81. #endif
  82. #ifdef    ENABLE_SUMMON
  83. 'S',
  84. #endif
  85. #ifdef    IRCII_KLUDGE
  86. 'u',
  87. #endif
  88. #ifdef    ENABLE_USERS
  89. 'U',
  90. #endif
  91. #ifdef    VALLOC
  92. 'V',
  93. #endif
  94. #ifdef    _WIN32
  95. 'W',
  96. #endif
  97. #ifdef    UNIXPORT
  98. 'X',
  99. #endif
  100. #ifdef    USE_SYSLOG
  101. 'Y',
  102. #endif
  103. #ifdef    V28PlusOnly
  104. '8',
  105. #endif
  106. #ifdef SCRIPTINIFIX
  107. 'S',
  108. #endif
  109. '\0'};
  110.  
  111. #include "numeric.h"
  112. #include "common.h"
  113. #include "sys.h"
  114. #include "whowas.h"
  115. #include "hash.h"
  116. #ifndef _WIN32
  117. #include <sys/file.h>
  118. #endif
  119. #ifdef HPUX
  120. #include <fcntl.h>
  121. #endif
  122. #if !defined(ULTRIX) && !defined(SGI) && !defined(sequent) && \
  123.     !defined(__convex__) && !defined(_WIN32)
  124. # include <sys/param.h>
  125. #endif
  126. #ifdef HPUX
  127. # include <sys/syscall.h>
  128. # define getrusage(a,b) syscall(SYS_GETRUSAGE, a, b)
  129. #endif
  130. #ifdef GETRUSAGE_2
  131. # ifdef SOL20
  132. #  include <sys/time.h>
  133. #  ifdef RUSAGEH
  134. #   include <sys/rusage.h>
  135. #  endif
  136. # endif
  137. # include <sys/resource.h>
  138. #else
  139. #  ifdef TIMES_2
  140. #   include <sys/times.h>
  141. #  endif
  142. #endif
  143. #ifdef PCS
  144. # include <time.h>
  145. #endif
  146. #ifdef HPUX
  147. #include <unistd.h>
  148. #ifdef DYNIXPTX
  149. #include <sys/types.h>
  150. #include <time.h>
  151. #endif
  152. #endif
  153. #include "h.h"
  154.  
  155. #ifndef ssize_t
  156. #define ssize_t unsigned int
  157. #endif
  158.  
  159. #ifdef DEBUGMODE
  160. static    char    debugbuf[1024];
  161.  
  162. #ifndef    USE_VARARGS
  163. /*VARARGS2*/
  164. void    debug(level, form, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
  165. int    level;
  166. char    *form, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
  167. {
  168. # ifndef _WIN32
  169.     int    err = errno;
  170. # else
  171.     int    err = WSAGetLastError();
  172. # endif
  173. #else
  174. void    debug(level, form, va_alist)
  175. int    level;
  176. char    *form;
  177. va_dcl
  178. {
  179.     va_list    vl;
  180. # ifndef _WIN32
  181.     int    err = errno;
  182. # else
  183.     int    err = WSAGetLastError();
  184. # endif
  185.  
  186.     va_start(vl);
  187. #endif
  188.  
  189.     if ((debuglevel >= 0) && (level <= debuglevel))
  190.         {
  191. #ifndef    USE_VARARGS
  192.         (void)sprintf(debugbuf, form,
  193.                 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  194. #else
  195.         (void)vsprintf(debugbuf, form, vl);
  196. #endif
  197. #ifndef _WIN32
  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. #else
  208.         strcat(debugbuf, "\r");
  209.         Cio_Puts(hCio, debugbuf, strlen(debugbuf));
  210.         }
  211.     WSASetLastError(err);
  212. #endif
  213. }
  214.  
  215. /*
  216.  * This is part of the STATS replies. There is no offical numeric for this
  217.  * since this isnt an official command, in much the same way as HASH isnt.
  218.  * It is also possible that some systems wont support this call or have
  219.  * different field names for "struct rusage".
  220.  * -avalon
  221.  */
  222. void    send_usage(cptr, nick)
  223. aClient *cptr;
  224. char    *nick;
  225. {
  226.  
  227. #ifdef GETRUSAGE_2
  228.     struct    rusage    rus;
  229.     time_t    secs, rup;
  230. #ifdef    hz
  231. # define hzz hz
  232. #else
  233. # ifdef HZ
  234. #  define hzz HZ
  235. # else
  236.     int    hzz = 1;
  237. #  ifdef HPUX
  238.     hzz = (int)sysconf(_SC_CLK_TCK);
  239. #  endif
  240. # endif
  241. #endif
  242.  
  243.     if (getrusage(RUSAGE_SELF, &rus) == -1)
  244.         {
  245. #if !defined(__FreeBSD__) && !defined(__NetBSD__)
  246.         extern char *sys_errlist[];
  247. #endif
  248.         sendto_one(cptr,":%s NOTICE %s :Getruseage error: %s.",
  249.                me.name, nick, sys_errlist[errno]);
  250.         return;
  251.         }
  252.     secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
  253.     rup = time(NULL) - me.since;
  254.     if (secs == 0)
  255.         secs = 1;
  256.  
  257.     sendto_one(cptr,
  258.            ":%s %d %s :CPU Secs %d:%d User %d:%d System %d:%d",
  259.            me.name, RPL_STATSDEBUG, nick, secs/60, secs%60,
  260.            rus.ru_utime.tv_sec/60, rus.ru_utime.tv_sec%60,
  261.            rus.ru_stime.tv_sec/60, rus.ru_stime.tv_sec%60);
  262.     sendto_one(cptr, ":%s %d %s :RSS %d ShMem %d Data %d Stack %d",
  263.            me.name, RPL_STATSDEBUG, nick, rus.ru_maxrss,
  264.            rus.ru_ixrss / (rup * hzz), rus.ru_idrss / (rup * hzz),
  265.            rus.ru_isrss / (rup * hzz));
  266.     sendto_one(cptr, ":%s %d %s :Swaps %d Reclaims %d Faults %d",
  267.            me.name, RPL_STATSDEBUG, nick, rus.ru_nswap,
  268.            rus.ru_minflt, rus.ru_majflt);
  269.     sendto_one(cptr, ":%s %d %s :Block in %d out %d",
  270.            me.name, RPL_STATSDEBUG, nick, rus.ru_inblock,
  271.            rus.ru_oublock);
  272.     sendto_one(cptr, ":%s %d %s :Msg Rcv %d Send %d",
  273.            me.name, RPL_STATSDEBUG, nick, rus.ru_msgrcv, rus.ru_msgsnd);
  274.     sendto_one(cptr, ":%s %d %s :Signals %d Context Vol. %d Invol %d",
  275.            me.name, RPL_STATSDEBUG, nick, rus.ru_nsignals,
  276.            rus.ru_nvcsw, rus.ru_nivcsw);
  277. #else
  278. # ifdef TIMES_2
  279.     struct    tms    tmsbuf;
  280.     time_t    secs, mins;
  281.     int    hzz = 1, ticpermin;
  282.     int    umin, smin, usec, ssec;
  283.  
  284. #  ifdef HPUX
  285.     hzz = sysconf(_SC_CLK_TCK);
  286. #  endif
  287.     ticpermin = hzz * 60;
  288.  
  289.     umin = tmsbuf.tms_utime / ticpermin;
  290.     usec = (tmsbuf.tms_utime%ticpermin)/(float)hzz;
  291.     smin = tmsbuf.tms_stime / ticpermin;
  292.     ssec = (tmsbuf.tms_stime%ticpermin)/(float)hzz;
  293.     secs = usec + ssec;
  294.     mins = (secs/60) + umin + smin;
  295.     secs %= hzz;
  296.  
  297.     if (times(&tmsbuf) == -1)
  298.         {
  299.         sendto_one(cptr,":%s %d %s :times(2) error: %s.",
  300. #  ifndef _WIN32
  301.                me.name, RPL_STATSDEBUG, nick, strerror(errno));
  302. #  else
  303.                me.name, RPL_STATSDEBUG, nick,
  304.                    strerror(WSAGetLastError()));
  305. #  endif
  306.         return;
  307.         }
  308.     secs = tmsbuf.tms_utime + tmsbuf.tms_stime;
  309.  
  310.     sendto_one(cptr,
  311.            ":%s %d %s :CPU Secs %d:%d User %d:%d System %d:%d",
  312.            me.name, RPL_STATSDEBUG, nick, mins, secs, umin, usec,
  313.            smin, ssec);
  314. # endif
  315. #endif
  316.     sendto_one(cptr, ":%s %d %s :Reads %d Writes %d",
  317.            me.name, RPL_STATSDEBUG, nick, readcalls, writecalls);
  318.     sendto_one(cptr, ":%s %d %s :DBUF alloc %d blocks %d",
  319.            me.name, RPL_STATSDEBUG, nick, dbufalloc, dbufblocks);
  320.     sendto_one(cptr,
  321.            ":%s %d %s :Writes:  <0 %d 0 %d <16 %d <32 %d <64 %d",
  322.            me.name, RPL_STATSDEBUG, nick,
  323.            writeb[0], writeb[1], writeb[2], writeb[3], writeb[4]);
  324.     sendto_one(cptr,
  325.            ":%s %d %s :<128 %d <256 %d <512 %d <1024 %d >1024 %d",
  326.            me.name, RPL_STATSDEBUG, nick,
  327.            writeb[5], writeb[6], writeb[7], writeb[8], writeb[9]);
  328.     return;
  329. }
  330. #endif
  331.  
  332. void    count_memory(cptr, nick)
  333. aClient    *cptr;
  334. char    *nick;
  335. {
  336.     extern    aChannel    *channel;
  337.     extern    aClass    *classes;
  338.     extern    aConfItem    *conf;
  339.     extern    int    flinks;
  340.     extern    Link    *freelink;
  341.  
  342.     aClient *acptr;
  343.     Ban *ban;
  344.     Link *link;
  345.     aChannel *chptr;
  346.     aConfItem *aconf;
  347.     aClass *cltmp;
  348.  
  349.     int    lc = 0,        /* local clients */
  350.         ch = 0,        /* channels */
  351.         lcc = 0,    /* local client conf links */
  352.         rc = 0,        /* remote clients */
  353.         us = 0,        /* user structs */
  354.         chu = 0,    /* channel users */
  355.         chi = 0,    /* channel invites */
  356.         chb = 0,    /* channel bans */
  357.         wwu = 0,    /* whowas users */
  358.         fl = 0,        /* free links */
  359.         cl = 0,        /* classes */
  360.         co = 0;        /* conf lines */
  361.  
  362.     int    usi = 0,    /* users invited */
  363.         usc = 0,    /* users in channels */
  364.         aw = 0,        /* aways set */
  365.         wwa = 0,    /* whowas aways */
  366.         wlh = 0,    /* watchlist headers */
  367.         wle = 0;    /* watchlist entries */
  368.  
  369.     u_long    chm = 0,    /* memory used by channels */
  370.         chbm = 0,    /* memory used by channel bans */
  371.         lcm = 0,    /* memory used by local clients */
  372.         rcm = 0,    /* memory used by remote clients */
  373.         awm = 0,    /* memory used by aways */
  374.         wwam = 0,    /* whowas away memory used */
  375.         wwm = 0,    /* whowas array memory used */
  376.         com = 0,    /* memory used by conf lines */
  377.         wlhm = 0,    /* watchlist memory used */
  378.         db = 0,        /* memory used by dbufs */
  379.         rm = 0,        /* res memory used */
  380.         totcl = 0,
  381.         totch = 0,
  382.         totww = 0,
  383.         tot = 0;
  384.  
  385.     count_whowas_memory(&wwu, &wwa, &wwam);
  386.     count_watch_memory(&wlh, &wlhm);
  387.     wwm = sizeof(aName) * NICKNAMEHISTORYLENGTH;
  388.  
  389.     for (acptr = client; acptr; acptr = acptr->next)
  390.         {
  391.         if (MyConnect(acptr))
  392.             {
  393.             lc++;
  394.             for (link = acptr->confs; link; link = link->next)
  395.                 lcc++;
  396.             wle += acptr->notifies;
  397.             }
  398.         else
  399.             rc++;
  400.         if (acptr->user)
  401.            {
  402.             us++;
  403.             for (link = acptr->user->invited; link;
  404.                  link = link->next)
  405.                 usi++;
  406.             for (link = acptr->user->channel; link;
  407.                  link = link->next)
  408.                 usc++;
  409.             if (acptr->user->away)
  410.                 {
  411.                 aw++;
  412.                 awm += (strlen(acptr->user->away)+1);
  413.                 }
  414.            }
  415.         }
  416.     lcm = lc * CLIENT_LOCAL_SIZE;
  417.     rcm = rc * CLIENT_REMOTE_SIZE;
  418.  
  419.     for (chptr = channel; chptr; chptr = chptr->nextch)
  420.         {
  421.         ch++;
  422.         chm += (strlen(chptr->chname) + sizeof(aChannel));
  423.         for (link = chptr->members; link; link = link->next)
  424.             chu++;
  425.         for (link = chptr->invites; link; link = link->next)
  426.             chi++;
  427.         for (ban = chptr->banlist; ban; ban = ban->next)
  428.             {
  429.             chb++;
  430.             chbm += (strlen(ban->banstr)+1+
  431.                  strlen(ban->who)+1+sizeof(Ban));
  432.             }
  433.         }
  434.  
  435.     for (aconf = conf; aconf; aconf = aconf->next)
  436.         {
  437.         co++;
  438.         com += aconf->host ? strlen(aconf->host)+1 : 0;
  439.         com += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
  440.         com += aconf->name ? strlen(aconf->name)+1 : 0;
  441.         com += sizeof(aConfItem);
  442.         }
  443.  
  444.     for (cltmp = classes; cltmp; cltmp = cltmp->next)
  445.         cl++;
  446.  
  447.     sendto_one(cptr, ":%s %d %s :Client Local %d(%d) Remote %d(%d)",
  448.            me.name, RPL_STATSDEBUG, nick, lc, lcm, rc, rcm);
  449.     sendto_one(cptr, ":%s %d %s :Users %d(%d) Invites %d(%d)",
  450.            me.name, RPL_STATSDEBUG, nick, us, us*sizeof(anUser), usi,
  451.            usi * sizeof(Link));
  452.     sendto_one(cptr, ":%s %d %s :User channels %d(%d) Aways %d(%d)",
  453.            me.name, RPL_STATSDEBUG, nick, usc, usc*sizeof(Link),
  454.            aw, awm);
  455.     sendto_one(cptr, ":%s %d %s :WATCH headers %d(%d) entries %d(%d)",
  456.            me.name, RPL_STATSDEBUG, nick, wlh, wlhm,
  457.            wle, wle*sizeof(Link));
  458.     sendto_one(cptr, ":%s %d %s :Attached confs %d(%d)",
  459.            me.name, RPL_STATSDEBUG, nick, lcc, lcc*sizeof(Link));
  460.  
  461.     totcl = lcm + rcm + us*sizeof(anUser) + usc*sizeof(Link) + awm;
  462.     totcl += lcc*sizeof(Link) + usi*sizeof(Link) + wlhm;
  463.     totcl += wle*sizeof(Link);
  464.  
  465.     sendto_one(cptr, ":%s %d %s :Conflines %d(%d)",
  466.            me.name, RPL_STATSDEBUG, nick, co, com);
  467.  
  468.     sendto_one(cptr, ":%s %d %s :Classes %d(%d)",
  469.            me.name, RPL_STATSDEBUG, nick, cl, cl*sizeof(aClass));
  470.  
  471.     sendto_one(cptr, ":%s %d %s :Channels %d(%d) Bans %d(%d)",
  472.            me.name, RPL_STATSDEBUG, nick, ch, chm, chb, chbm);
  473.     sendto_one(cptr, ":%s %d %s :Channel membrs %d(%d) invite %d(%d)",
  474.            me.name, RPL_STATSDEBUG, nick, chu, chu*sizeof(Link),
  475.            chi, chi*sizeof(Link));
  476.  
  477.     totch = chm + chbm + chu*sizeof(Link) + chi*sizeof(Link);
  478.  
  479.     sendto_one(cptr, ":%s %d %s :Whowas users %d(%d) away %d(%d)",
  480.            me.name, RPL_STATSDEBUG, nick, wwu, wwu*sizeof(anUser),
  481.            wwa, wwam);
  482.     sendto_one(cptr, ":%s %d %s :Whowas array %d(%d)",
  483.            me.name, RPL_STATSDEBUG, nick, NICKNAMEHISTORYLENGTH, wwm);
  484.  
  485.     totww = wwu*sizeof(anUser) + wwam + wwm;
  486.  
  487.     sendto_one(cptr, ":%s %d %s :Hash: client %d(%d) chan %d(%d) watch %d(%d)",
  488.            me.name, RPL_STATSDEBUG, nick, HASHSIZE,
  489.            sizeof(aHashEntry) * HASHSIZE,
  490.            CHANNELHASHSIZE, sizeof(aHashEntry) * CHANNELHASHSIZE,
  491.            NOTIFYHASHSIZE, sizeof(aNotify *) * NOTIFYHASHSIZE);
  492.     db = dbufblocks * sizeof(dbufbuf);
  493.     sendto_one(cptr, ":%s %d %s :Dbuf blocks %d(%d)",
  494.            me.name, RPL_STATSDEBUG, nick, dbufblocks, db);
  495.  
  496.     link=freelink; while(link=link->next) fl++; fl++;
  497.     sendto_one(cptr, ":%s %d %s :Link blocks free %d(%d) total %d(%d)",
  498.            me.name, RPL_STATSDEBUG, nick, fl, fl*sizeof(Link), 
  499.            flinks, flinks*sizeof(Link));
  500.  
  501.     rm = cres_mem(cptr);
  502.  
  503.     tot = totww + totch + totcl + com + cl*sizeof(aClass) + db + rm;
  504.     tot += fl*sizeof(Link);
  505.     tot += sizeof(aHashEntry) * HASHSIZE;
  506.     tot += sizeof(aHashEntry) * CHANNELHASHSIZE;
  507.     tot += sizeof(aNotify *) * NOTIFYHASHSIZE;
  508.  
  509.     sendto_one(cptr, ":%s %d %s :Total: ww %d ch %d cl %d co %d db %d",
  510.            me.name, RPL_STATSDEBUG, nick, totww, totch, totcl, com, db);
  511. #ifndef _WIN32
  512.     sendto_one(cptr, ":%s %d %s :TOTAL: %d sbrk(0)-etext: %u",
  513.            me.name, RPL_STATSDEBUG, nick, tot,
  514.            (u_int)sbrk((size_t)0)-(u_int)sbrk0);
  515. #else
  516.     sendto_one(cptr, ":%s %d %s :TOTAL: %d",
  517.            me.name, RPL_STATSDEBUG, nick, tot);
  518. #endif
  519.     return;
  520. }
  521.