1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
/*
* Unreal Internet Relay Chat Daemon, src/s_debug.c
* Copyright (C) 1990 Jarkko Oikarinen and
* University of Oulu, Computing Center
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/
#ifndef CLEAN_COMPILE
static char sccsid[] =
"@(#)s_debug.c 2.30 1/3/94 (C) 1988 University of Oulu, \
Computing Center and Jarkko Oikarinen";
#endif
#include "struct.h"
#include <string.h>
#include "proto.h"
/*
* Option string. Must be before #ifdef DEBUGMODE.
*/
MODVAR char serveropts[] = {
#ifdef CHROOTDIR
'c',
#endif
#ifdef CMDLINE_CONFIG
'C',
#endif
#ifdef DEBUGMODE
'D',
#endif
#ifndef NO_FDLIST
'F',
#endif
/*
* Marks that the ircd is ``compiled as'' a hub.
* Now always defined as it's impossible to build unrealircd
* without hub support AFAIK. (#0003891) --binki
*/
'h',
#ifdef SHOW_INVISIBLE_LUSERS
'i',
#endif
/* NOSPOOF is always compiled in now. --nenolod */
'n',
#ifdef VALLOC
'V',
#endif
#ifdef _WIN32
'W',
#endif
#ifdef USE_SYSLOG
'Y',
#endif
#ifdef INET6
'6',
#endif
#ifdef STRIPBADWORDS
'X',
#endif
#ifdef USE_SSL
'e',
#endif
#ifndef NO_OPEROVERRIDE
'O',
#endif
#ifndef OPEROVERRIDE_VERIFY
'o',
#endif
#ifdef ZIP_LINKS
'Z',
#endif
#ifdef EXTCMODE
'E',
#endif
'\0', /* Don't change those 3 nuls. -- Syzop */
'\0',
'\0'
};
char *extraflags = NULL;
#include "numeric.h"
#include "common.h"
#include "sys.h"
#include "whowas.h"
#include "hash.h"
#ifndef _WIN32
#include <sys/file.h>
#endif
#ifdef HPUX
#include <fcntl.h>
#endif
#if !defined(ULTRIX) && !defined(SGI) && \
!defined(__convex__) && !defined(_WIN32)
# include <sys/param.h>
#endif
#ifdef HPUX
# include <sys/syscall.h>
# define getrusage(a,b) syscall(SYS_GETRUSAGE, a, b)
#endif
#ifdef GETRUSAGE_2
# ifdef _SOLARIS
# include <sys/time.h>
# ifdef RUSAGEH
# include <sys/rusage.h>
# endif
# endif
# include <sys/resource.h>
#else
# ifdef TIMES_2
# include <sys/times.h>
# endif
#endif
#ifdef PCS
# include <time.h>
#endif
#ifdef HPUX
#include <unistd.h>
#endif
#include "h.h"
#ifndef ssize_t
#define ssize_t unsigned int
#endif
void flag_add(char ch)
{
char *newextra;
if (extraflags)
{
char tmp[2] = { ch, 0 };
newextra = (char *)MyMalloc(strlen(extraflags) + 2);
strcpy(newextra, extraflags);
strcat(newextra, tmp);
MyFree(extraflags);
extraflags = newextra;
}
else
{
extraflags = malloc(2);
extraflags[0] = ch;
extraflags[1] = 0;
}
}
void flag_del(char ch)
{
int newsz;
char *p, *op;
char *newflags;
newsz = 0;
p = extraflags;
for (newsz = 0, p = extraflags; *p; p++)
if (*p != ch)
newsz++;
newflags = MyMalloc(newsz + 1);
for (p = newflags, op = extraflags; (*op) && (newsz); newsz--, op++)
if (*op != ch)
*p++ = *op;
*p = '\0';
MyFree(extraflags);
extraflags = newflags;
}
#ifdef DEBUGMODE
#ifndef _WIN32
#define SET_ERRNO(x) errno = x
#else
#define SET_ERRNO(x) WSASetLastError(x)
#endif /* _WIN32 */
static char debugbuf[4096];
#ifndef USE_VARARGS
/*VARARGS2*/
void debug(level, form, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
int level;
char *form, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
{
#else
void debug(int level, char *form, ...)
#endif
{
int err = ERRNO;
va_list vl;
va_start(vl, form);
if ((debuglevel >= 0) && (level <= debuglevel))
{
#ifndef USE_VARARGS
(void)ircsprintf(debugbuf, form, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
#else
(void)ircvsprintf(debugbuf, form, vl);
#if 0
# ifdef _WIN32
strcat(debugbuf,"\r\n");
# endif
#endif
#endif
#if 0
if (local[2])
{
local[2]->sendM++;
local[2]->sendB += strlen(debugbuf);
}
#endif
#ifndef _WIN32
(void)fprintf(stderr, "%s", debugbuf);
(void)fputc('\n', stderr);
#else
//# ifndef _WIN32GUI
// Cio_Puts(hCio, debugbuf, strlen(debugbuf));
//# else
strcat(debugbuf, "\r\n");
OutputDebugString(debugbuf);
//# endif
#endif
}
va_end(vl);
SET_ERRNO(err);
}
/*
* 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
*/
void send_usage(aClient *cptr, char *nick)
{
#ifdef GETRUSAGE_2
struct rusage rus;
time_t secs, rup;
#ifdef hz
# define hzz hz
#else
# ifdef HZ
# define hzz HZ
# else
int hzz = 1;
# ifdef HPUX
hzz = (int)sysconf(_SC_CLK_TCK);
# endif
# endif
#endif
if (getrusage(RUSAGE_SELF, &rus) == -1)
{
sendto_one(cptr, ":%s NOTICE %s :Getruseage error: %s.",
me.name, nick, strerror(errno));
return;
}
secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
rup = TStime() - me.since;
if (secs == 0)
secs = 1;
sendto_one(cptr,
":%s %d %s :CPU Secs %ld:%ld User %ld:%ld System %ld:%ld",
me.name, RPL_STATSDEBUG, nick, secs / 60, secs % 60,
rus.ru_utime.tv_sec / 60, rus.ru_utime.tv_sec % 60,
rus.ru_stime.tv_sec / 60, rus.ru_stime.tv_sec % 60);
sendto_one(cptr, ":%s %d %s :RSS %ld ShMem %ld Data %ld Stack %ld",
me.name, RPL_STATSDEBUG, nick, rus.ru_maxrss,
rus.ru_ixrss / (rup * hzz), rus.ru_idrss / (rup * hzz),
rus.ru_isrss / (rup * hzz));
sendto_one(cptr, ":%s %d %s :Swaps %ld Reclaims %ld Faults %ld",
me.name, RPL_STATSDEBUG, nick, rus.ru_nswap,
rus.ru_minflt, rus.ru_majflt);
sendto_one(cptr, ":%s %d %s :Block in %ld out %ld",
me.name, RPL_STATSDEBUG, nick, rus.ru_inblock, rus.ru_oublock);
sendto_one(cptr, ":%s %d %s :Msg Rcv %ld Send %ld",
me.name, RPL_STATSDEBUG, nick, rus.ru_msgrcv, rus.ru_msgsnd);
sendto_one(cptr, ":%s %d %s :Signals %ld Context Vol. %ld Invol %ld",
me.name, RPL_STATSDEBUG, nick, rus.ru_nsignals,
rus.ru_nvcsw, rus.ru_nivcsw);
#else
# ifdef TIMES_2
struct tms tmsbuf;
time_t secs, mins;
int hzz = 1, ticpermin;
int umin, smin, usec, ssec;
# ifdef HPUX
hzz = sysconf(_SC_CLK_TCK);
# endif
ticpermin = hzz * 60;
umin = tmsbuf.tms_utime / ticpermin;
usec = (tmsbuf.tms_utime % ticpermin) / (float)hzz;
smin = tmsbuf.tms_stime / ticpermin;
ssec = (tmsbuf.tms_stime % ticpermin) / (float)hzz;
secs = usec + ssec;
mins = (secs / 60) + umin + smin;
secs %= hzz;
if (times(&tmsbuf) == -1)
{
sendto_one(cptr, ":%s %d %s :times(2) error: %s.",
me.name, RPL_STATSDEBUG, nick, STRERROR(ERRNO));
return;
}
secs = tmsbuf.tms_utime + tmsbuf.tms_stime;
sendto_one(cptr,
":%s %d %s :CPU Secs %d:%d User %d:%d System %d:%d",
me.name, RPL_STATSDEBUG, nick, mins, secs, umin, usec, smin, ssec);
# endif
#endif
sendto_one(cptr, ":%s %d %s :Reads %d Writes %d",
me.name, RPL_STATSDEBUG, nick, readcalls, writecalls);
sendto_one(cptr, ":%s %d %s :DBUF alloc %d blocks %d",
me.name, RPL_STATSDEBUG, nick, dbufalloc, dbufblocks);
sendto_one(cptr,
":%s %d %s :Writes: <0 %d 0 %d <16 %d <32 %d <64 %d",
me.name, RPL_STATSDEBUG, nick,
writeb[0], writeb[1], writeb[2], writeb[3], writeb[4]);
sendto_one(cptr,
":%s %d %s :<128 %d <256 %d <512 %d <1024 %d >1024 %d",
me.name, RPL_STATSDEBUG, nick,
writeb[5], writeb[6], writeb[7], writeb[8], writeb[9]);
return;
}
int checkprotoflags(aClient *sptr, int flags, char *file, int line)
{
if (!MyConnect(sptr))
ircd_log(LOG_ERROR, "[Debug] [BUG] ERROR: %s:%d: IsToken(<%s>,%d) on remote client",
file, line, sptr->name, flags);
return (sptr->proto & flags) ? 1 : 0;
}
#endif
|