diff --git a/Changes b/Changes index d10409ae1..3ee67bf93 100644 --- a/Changes +++ b/Changes @@ -486,3 +486,5 @@ seen. gmtime warning still there - Added richedit 1.0 support so Credits,License, etc show the bold and underline formats in win32 code by codemastr with help from McSkaf (still needs work to support reverse and color) - Added code so the rich edit _should_ work with any version of the richedit dll +- Changed all TStime() to use timeofday - CPU SAVE +- Removed userload.c & userload.h diff --git a/include/h.h b/include/h.h index df996fa53..03395bb42 100644 --- a/include/h.h +++ b/include/h.h @@ -46,6 +46,7 @@ extern time_t TSoffset; /* Prototype added to force errors -- Barubary */ extern TS check_pings(TS now, int check_kills); extern TS TS2ts(char *s); +extern time_t timeofday; /* newconf */ #define get_sendq(x) ((x)->class ? (x)->class->sendq : MAXSENDQLENGTH) diff --git a/include/struct.h b/include/struct.h index 1145e5554..8febfb871 100644 --- a/include/struct.h +++ b/include/struct.h @@ -1346,7 +1346,7 @@ struct DSlink { #define MyClient(x) (MyConnect(x) && IsClient(x)) #define MyOper(x) (MyConnect(x) && IsOper(x)) -#define TStime() (time(NULL)+TSoffset) +#define TStime() (timeofday) /* Lifted somewhat from Undernet code --Rak */ diff --git a/include/sys.h b/include/sys.h index 9a9628b89..25adb570d 100644 --- a/include/sys.h +++ b/include/sys.h @@ -189,7 +189,4 @@ static const struct in6_addr in6addr_any = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # define IRCDCONF_DELIMITER ':' #endif -#ifndef RTLD_NOW -#define RTLD_NOW RTLD_LAZY -#endif #endif /* __sys_include__ */ diff --git a/include/userload.h b/include/userload.h deleted file mode 100644 index 4049d1bde..000000000 --- a/include/userload.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * Userload module by Michael L. VanLoon (mlv) - * Written 2/93. Originally grafted into irc2.7.2g 4/93. - * - * Unreal Internet Relay Chat Daemon, ircd/userload.h - * Copyright (C) 1990 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. - ****************************************************************************/ - -/* $Id$ */ - -/* This needs to be defined for the counts to be correct--it should be the - * default anyway, as opers shouldn't be superior to lusers except where - * absolutely necessary, and here it isn't necessary. */ -#ifndef SHOW_INVISIBLE_LUSERS -#define SHOW_INVISIBLE_LUSERS -#endif - -struct current_load_struct { - u_short client_count, local_count, conn_count; - u_long entries; -}; - -extern struct current_load_struct current_load_data; - -struct load_entry { - struct load_entry *prev; - u_short client_count, local_count, conn_count; -#ifdef DEBUGMODE - u_short cpu_usage; -#endif - long time_incr; -}; - -extern struct load_entry *load_list_head, *load_list_tail, - *load_free_head, *load_free_tail; - - -extern void initload PROTO((void)); -extern void update_load PROTO((void)); -extern void calc_load PROTO((aClient *, char *)); diff --git a/src/Makefile b/src/Makefile index c5cd6e883..255d4618a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -27,7 +27,7 @@ OBJS=agent.o aln.o badwords.o bsd.o channel.o cloak.o crule.o dbuf.o \ res_init.o res_comp.o res_mkquery.o res_skipname.o s_auth.o \ s_bsd.o s_conf.o s_debug.o s_err.o s_extra.o s_kline.o \ s_misc.o s_numeric.o s_serv.o s_socks.o s_svs.o $(STRTOUL) ssl.o s_unreal.o \ - s_user.o scache.o send.o support.o userload.o version.o webtv.o \ + s_user.o scache.o send.o support.o version.o webtv.o \ whowas.o zip.o SRC=$(OBJS:%.o=%.c) diff --git a/src/channel.c b/src/channel.c index 5b9c9ead6..6e29bf291 100644 --- a/src/channel.c +++ b/src/channel.c @@ -4005,7 +4005,7 @@ int check_for_chan_flood(aClient *cptr, aClient *sptr, aChannel *chptr) int m_list(aClient *cptr, aClient *sptr, int parc, char *parv[]) { aChannel *chptr; - TS currenttime = time(NULL); + TS currenttime = TStime(); char *name, *p = NULL; LOpts *lopt = NULL; Link *lp, *next; diff --git a/src/hash.c b/src/hash.c index 4b2563bd9..0ad2e940a 100644 --- a/src/hash.c +++ b/src/hash.c @@ -569,7 +569,7 @@ int hash_check_notify(cptr, reply) return 0; /* This nick isn't on notify */ /* Update the time of last change to item */ - anptr->lasttime = time(NULL); + anptr->lasttime = TStime(); /* Send notifies out to everybody on the list in header */ for (lp = anptr->notify; lp; lp = lp->next) diff --git a/src/ircd.c b/src/ircd.c index 2f134a0a6..2e6a367d4 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -81,6 +81,7 @@ int un_gid = 99; extern char unreallogo[]; #endif +time_t timeofday = 0; LoopStruct loop; extern aMotd *opermotd; extern aMotd *svsmotd; @@ -740,6 +741,8 @@ char chess[] = { 85, 110, 114, 101, 97, 108, 0 }; +extern time_t TSoffset; + #ifndef _WIN32 int main(argc, argv) #else @@ -796,7 +799,6 @@ int InitwIRCD(argc, argv) #endif bzero((char *)&me, sizeof(me)); setup_signals(); - initload(); init_ircstats(); clear_scache_hash_table(); #ifdef FORCE_CORE @@ -1157,7 +1159,7 @@ int InitwIRCD(argc, argv) void SocketLoop(void *dummy) { - TS delay = 0, now; + TS delay = 0; static TS lastglinecheck = 0; TS last_tune; #ifndef NO_FDLIST @@ -1168,11 +1170,11 @@ void SocketLoop(void *dummy) for (;;) #endif { - now = TStime(); - if ((now - lastglinecheck) > 4) + timeofday = time(NULL) + TSoffset; + if ((timeofday - lastglinecheck) > 4) { tkl_check_expire(); - lastglinecheck = now; + lastglinecheck = timeofday; #ifdef STATSWRITING save_stats(); #endif @@ -1189,7 +1191,7 @@ void SocketLoop(void *dummy) save_tunefile(); } - if (((now - last_garbage_collect) > + if (((timeofday - last_garbage_collect) > GARBAGE_COLLECT_EVERY || (loop.do_garbage_collect == 1))) { extern int freelinks; @@ -1219,7 +1221,7 @@ void SocketLoop(void *dummy) } if (loop.do_garbage_collect == 1) loop.do_garbage_collect = 0; - last_garbage_collect = now; + last_garbage_collect = timeofday; } /* ** Run through the hashes and check lusers every @@ -1232,9 +1234,9 @@ void SocketLoop(void *dummy) static TS lasttime = 0; static long lastrecvK, lastsendK; static int lrv; - if (now - lasttime < LCF) + if (timeofday - lasttime < LCF) goto done_check; - lasttime = now; + lasttime = timeofday; lrv = LRV * LCF; if ((me.receiveK - lrv >= lastrecvK) || HTMLOCK == 1) { @@ -1281,21 +1283,21 @@ void SocketLoop(void *dummy) lifesux = 0; if (noisy_htm) sendto_realops - ("Resuming standard operation (incoming = %0.2f kb/s, outgoing = %0.2f kb/s now)", + ("Resuming standard operation (incoming = %0.2f kb/s, outgoing = %0.2f kb/s timeofday)", currentrate, currentrate2); } } lastrecvK = me.receiveK; lastsendK = me.sendK; done_check: - if (lasttime != now) + if (lasttime != timeofday) { currentrate = ((float)(me.receiveK - - lastrecvK)) / ((float)(now - lasttime)); + lastrecvK)) / ((float)(timeofday - lasttime)); currentrate2 = ((float)(me.sendK - - lastsendK)) / ((float)(now - lasttime)); + lastsendK)) / ((float)(timeofday - lasttime)); if (currentrate > highest_rate) highest_rate = currentrate; if (currentrate2 > highest_rate2) @@ -1314,15 +1316,15 @@ void SocketLoop(void *dummy) ** active C lines, this call to Tryconnections is ** made once only; it will return 0. - avalon */ - if (nextconnect && now >= nextconnect) - nextconnect = try_connections(now); + if (nextconnect && timeofday >= nextconnect) + nextconnect = try_connections(timeofday); /* ** DNS checks. One to timeout queries, one for cache expiries. */ - if (now >= nextdnscheck) - nextdnscheck = timeout_query_list(now); - if (now >= nextexpire) - nextexpire = expire_cache(now); + if (timeofday >= nextdnscheck) + nextdnscheck = timeout_query_list(timeofday); + if (timeofday >= nextexpire) + nextexpire = expire_cache(timeofday); /* ** take the smaller of the two 'timed' event times as ** the time of next event (stops us being late :) - avalon @@ -1334,7 +1336,7 @@ void SocketLoop(void *dummy) delay = nextping; delay = MIN(nextdnscheck, delay); delay = MIN(nextexpire, delay); - delay -= now; + delay -= timeofday; /* ** Adjust delay to something reasonable [ad hoc values] ** (one might think something more clever here... --msa) @@ -1366,16 +1368,16 @@ void SocketLoop(void *dummy) } { static TS lasttime = 0; - if ((lasttime + (lifesux + 1) * 2) < (now = TStime())) + if ((lasttime + (lifesux + 1) * 2) < (timeofday = TStime())) { read_message(delay, NULL); /* check everything */ - lasttime = now; + lasttime = timeofday; } } #endif Debug((DEBUG_DEBUG, "Got message(s)")); - now = TStime(); + timeofday = TStime(); /* ** ...perhaps should not do these loops every time, ** but only if there is some chance of something @@ -1385,25 +1387,25 @@ void SocketLoop(void *dummy) ** ping times) --msa */ #ifdef NO_FDLIST - if (now >= nextping) + if (timeofday >= nextping) #else - if (now >= nextping && !lifesux) + if (timeofday >= nextping && !lifesux) #endif - nextping = check_pings(now, 0); + nextping = check_pings(timeofday, 0); if (dorehash) { (void)rehash(&me, &me, 1); dorehash = 0; } /* - ** Flush output buffers on all connections now if they + ** Flush output buffers on all connections timeofday if they ** have data in them (or at least try to flush) ** -avalon */ #ifndef NO_FDLIST /* check which clients are active */ - if (now > nextfdlistcheck) - nextfdlistcheck = check_fdlists(now); + if (timeofday > nextfdlistcheck) + nextfdlistcheck = check_fdlists(timeofday); #endif flush_connections(me.fd); } diff --git a/src/modules.c b/src/modules.c index 30a8baff1..f198d409d 100644 --- a/src/modules.c +++ b/src/modules.c @@ -41,6 +41,9 @@ #endif #include #include "h.h" +#ifndef RTLD_NOW +#define RTLD_NOW RTLD_LAZY +#endif ModuleInfo *Modules[MAXMODULES]; Hook *Hooks[MAXHOOKTYPES]; diff --git a/src/res.c b/src/res.c index 1623a7a0b..bf7bfb118 100644 --- a/src/res.c +++ b/src/res.c @@ -98,7 +98,7 @@ int init_resolver(op) int ret = 0; #ifdef LRAND48 - srand48(time(NULL)); + srand48(TStime()); #endif if (op & RES_INITLIST) { diff --git a/src/s_debug.c b/src/s_debug.c index 41ba08087..bc4eb14d7 100644 --- a/src/s_debug.c +++ b/src/s_debug.c @@ -259,7 +259,7 @@ void send_usage(cptr, nick) return; } secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec; - rup = time(NULL) - me.since; + rup = TStime() - me.since; if (secs == 0) secs = 1; diff --git a/src/s_misc.c b/src/s_misc.c index e310cce30..be1ff6692 100644 --- a/src/s_misc.c +++ b/src/s_misc.c @@ -35,7 +35,6 @@ Computing Center and Jarkko Oikarinen"; #include "common.h" #include "sys.h" #include "numeric.h" -#include "userload.h" #include #include #if !defined(ULTRIX) && !defined(SGI) && \ @@ -483,15 +482,11 @@ int exit_client(cptr, sptr, from, comment) sptr->user->realhost, comment, sptr->sockhost); } - current_load_data.conn_count--; if (IsPerson(sptr)) { char mydom_mask[HOSTLEN + 1]; mydom_mask[0] = '\0'; strncpy(&mydom_mask[1], DOMAINNAME, HOSTLEN - 1); - current_load_data.client_count--; - if (match(mydom_mask, sptr->sockhost) == 0) - current_load_data.local_count--; /* Clean out list and watch structures -Donwulff */ hash_del_notify_list(sptr); if (sptr->user && sptr->user->lopt) @@ -501,7 +496,6 @@ int exit_client(cptr, sptr, from, comment) MyFree(sptr->user->lopt); } } - update_load(); on_for = TStime() - sptr->firsttime; # if defined(USE_SYSLOG) && defined(SYSLOG_USERS) if (IsPerson(sptr)) diff --git a/src/s_serv.c b/src/s_serv.c index ac85b0ac3..0c676a430 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -33,7 +33,6 @@ static char sccsid[] = #include "numeric.h" #include "msg.h" #include "channel.h" -#include "userload.h" #include "version.h" #include #include @@ -991,8 +990,6 @@ int m_server_synch(aClient *cptr, long numeric, ConfigItem_link *aconf) aChannel *chptr; int i; - current_load_data.conn_count++; - update_load(); if (cptr->passwd) { @@ -1313,8 +1310,6 @@ int m_server_estab(cptr) split = mycmp(cptr->name, cptr->sockhost); host = cptr->name; - current_load_data.conn_count++; - update_load(); if (!(aconf = find_conf(cptr->confs, host, CONF_NOCONNECT_SERVER))) { @@ -2807,10 +2802,6 @@ int m_stats(cptr, sptr, parc, parv) } case 'V': break; - case 'W': - case 'w': - calc_load(sptr, parv[0]); - break; case 'X': case 'x': for (link_p = conf_link; link_p; link_p = (ConfigItem_link *) link_p->next) @@ -2899,8 +2890,6 @@ int m_stats(cptr, sptr, parc, parv) "v - Send the V line list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, parv[0], "V - Send the vhost list"); - sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, parv[0], - "W - Send load information"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, parv[0], "Y - Send the Y line list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, parv[0], @@ -3136,9 +3125,6 @@ int m_lusers(cptr, sptr, parc, parv) sendto_ops("Maximum connections: %d (%d clients)", max_connection_count, IRCstats.me_clients); } - current_load_data.client_count = IRCstats.me_clients; - current_load_data.conn_count = - IRCstats.me_clients + IRCstats.me_servers; return 0; } diff --git a/src/s_user.c b/src/s_user.c index f3a790de4..958b5f384 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -988,7 +988,6 @@ static int register_user(cptr, sptr, nick, username, umode, virthost) ssl_get_cipher(sptr->ssl)); #endif (void)m_lusers(sptr, sptr, 1, parv); - update_load(); (void)m_motd(sptr, sptr, 1, parv); #ifdef EXPERIMENTAL sendto_one(sptr, @@ -3715,7 +3714,7 @@ int m_mkpasswd(cptr, sptr, parc, parv) me.name, parv[0]); return 0; } - srandom(time(0)); + srandom(TStime()); #ifndef _WIN32 salt[0] = saltChars[random() % 64]; salt[1] = saltChars[random() % 64]; diff --git a/src/userload.c b/src/userload.c deleted file mode 100644 index 6ebcf81aa..000000000 --- a/src/userload.c +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Userload module by Michael L. VanLoon (mlv) - * Written 2/93. Originally grafted into irc2.7.2g 4/93. - * - * Unreal Internet Relay Chat Daemon, src/userload.c - * Copyright (C) 1990 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. - ****************************************************************************/ - -#include "struct.h" -#include "common.h" -#include "sys.h" -#include "userload.h" -#include -#ifndef _WIN32 -#include -#include -#include -#else -#include -#endif -#include -#include -#ifndef _WIN32 -#include -#endif -#include "h.h" - - -struct current_load_struct current_load_data; -struct load_entry *load_list_head = NULL, *load_list_tail = NULL, - *load_free_head = NULL, *load_free_tail = NULL; - -#ifdef DEBUGMODE -clock_t clock_last = 0; -#endif - -void update_load() -{ - static struct timeval now, last; - struct load_entry *cur_load_entry; - - /* This seems to get polluted on startup by an exit_client() - * before any connections have been recorded. - */ - if (current_load_data.local_count > MAXCONNECTIONS || - current_load_data.client_count > MAXCONNECTIONS || - current_load_data.conn_count > MAXCONNECTIONS) - bzero(¤t_load_data, sizeof(struct current_load_struct)); - - memcpy(&last, &now, sizeof(struct timeval)); -#ifndef _WIN32 - if (gettimeofday(&now, NULL) != 0) - return; /* error getting time of day--can't calculate time diff */ -#else - /* Well, since the windows libs don't have gettimeofday() we have - * to improvise a bit, hopefully this will achieve close to the - * same result. -Cabal95 - */ - now.tv_sec = TStime(); -#endif - - if (load_free_tail == NULL) - { - if ((cur_load_entry = - (struct load_entry *)MyMalloc(sizeof(struct load_entry))) == - NULL) - return; - /* printf("malloc pointer: %x\n", cur_load_entry); */ - } - else - { - cur_load_entry = load_free_tail; - load_free_tail = cur_load_entry->prev; - if (load_free_tail == NULL) - load_free_head = NULL; - /* printf("free pointer: %x\n", cur_load_entry); */ - } - if (load_list_tail != NULL) - { -#ifndef _WIN32 - cur_load_entry->time_incr = - ((now.tv_sec * 1000 + now.tv_usec / 1000 + 5) - - (last.tv_sec * 1000 + last.tv_usec / 1000)) / 10; -#else - /* Don't even use *.tv_usec since its an unknown value. -Cabal95 */ - cur_load_entry->time_incr = ((now.tv_sec * 1000 + 5) - - last.tv_sec * 1000) / 10; -#endif - cur_load_entry->local_count = current_load_data.local_count; - cur_load_entry->client_count = current_load_data.client_count; - cur_load_entry->conn_count = current_load_data.conn_count; -#ifdef DEBUGMODE - cur_load_entry->cpu_usage = (clock() - clock_last); - clock_last = clock(); -#endif - } - else - { - load_list_head = cur_load_entry; - bzero(cur_load_entry, sizeof(struct load_entry)); - cur_load_entry->time_incr = 1; - } - cur_load_entry->prev = load_list_tail; - load_list_tail = cur_load_entry; -} - - -void calc_load(sptr, parv) - aClient *sptr; - char *parv; /* we only get passed the original parv[0] */ -{ - struct load_entry *cur_load_entry; - struct load_entry *last; -#ifdef DEBUGMODE - u_long secs = 0, adj_secs, total[4], adj[4]; /*[local,client,conn,cpu] */ - int i; - u_int times[5][4]; /* [min,hour,day,Yest,YYest][local,client,conn,cpu] */ - char what[4][HOSTLEN + 1]; - - bzero(total, 4 * sizeof(u_long)); -#else - u_long secs = 0, adj_secs, total[3], adj[3]; /*[local,client,conn] */ - int i, times[5][3]; /* [min,hour,day,Yest,YYest][local,client,conn] */ - char what[3][HOSTLEN + 1]; - - bzero(total, 3 * sizeof(u_long)); -#endif - - current_load_data.entries = 0; - - update_load(); /* we want stats accurate as of *now* */ - - for (cur_load_entry = load_list_tail; (secs < 6000) && - (cur_load_entry != NULL); cur_load_entry = cur_load_entry->prev) - { - u_long time_incr = cur_load_entry->time_incr; - total[0] += time_incr * cur_load_entry->local_count; - total[1] += time_incr * cur_load_entry->client_count; - total[2] += time_incr * cur_load_entry->conn_count; -#ifdef DEBUGMODE - total[3] += cur_load_entry->cpu_usage; -#endif - last = cur_load_entry; - secs += cur_load_entry->time_incr; - current_load_data.entries++; - } - if ((secs > 6000) && (last != NULL)) - { - adj_secs = secs - 6000; - adj[0] = adj_secs * last->local_count; - adj[1] = adj_secs * last->client_count; - adj[2] = adj_secs * last->conn_count; -#ifdef DEBUGMODE - times[0][3] = - total[3] - - (last->cpu_usage * (double)adj_secs / last->time_incr); - } - else - { - adj_secs = adj[0] = adj[1] = adj[2] = adj[3] = 0; - times[0][3] = total[3]; - } -#else - } - else - adj_secs = adj[0] = adj[1] = adj[2] = 0; -#endif - for (i = 0; i < 3; i++) - { - times[0][i] = - ((total[i] - adj[i]) * 1000 / (secs - adj_secs) + 5) / 10; - } - - secs = (secs + 5) / 10; - for (i = 0; i < 3; i++) - total[i] = (total[i] + 5) / 10; - - for (; (secs < 36000) && (cur_load_entry != NULL); secs += - (cur_load_entry->time_incr + 5) / 10, cur_load_entry = - cur_load_entry->prev, current_load_data.entries++) - { - u_long time_incr = (cur_load_entry->time_incr + 5) / 10; - total[0] += time_incr * cur_load_entry->local_count; - total[1] += time_incr * cur_load_entry->client_count; - total[2] += time_incr * cur_load_entry->conn_count; -#ifdef DEBUGMODE - total[3] += cur_load_entry->cpu_usage; -#endif - last = cur_load_entry; - } - if ((secs > 36000) && (last != NULL)) - { - adj_secs = secs - 36000; - adj[0] = adj_secs * last->local_count; - adj[1] = adj_secs * last->client_count; - adj[2] = adj_secs * last->conn_count; -#ifdef DEBUGMODE - times[1][3] = - total[3] - - (last->cpu_usage * (double)adj_secs / last->time_incr); - } - else - { - adj_secs = adj[0] = adj[1] = adj[2] = adj[3] = 0; - times[1][3] = total[3]; - } -#else - } - else - adj_secs = adj[0] = adj[1] = adj[2] = 0; -#endif - for (i = 0; i < 3; i++) - { - times[1][i] = - ((total[i] - adj[i]) * 100 / (secs - adj_secs) + 5) / 10; - } - - secs = (secs + 5) / 10; - for (i = 0; i < 3; i++) - total[i] = (total[i] + 5) / 10; - - for (; (secs < 86400) && (cur_load_entry != NULL); secs += - (cur_load_entry->time_incr + 50) / 100, cur_load_entry = - cur_load_entry->prev, current_load_data.entries++) - { - u_long time_incr = (cur_load_entry->time_incr + 50) / 100; - total[0] += time_incr * cur_load_entry->local_count; - total[1] += time_incr * cur_load_entry->client_count; - total[2] += time_incr * cur_load_entry->conn_count; -#ifdef DEBUGMODE - total[3] += cur_load_entry->cpu_usage; -#endif - last = cur_load_entry; - } - if ((secs > 86400) && (last != NULL)) - { - adj_secs = secs - 86400; - adj[0] = adj_secs * last->local_count; - adj[1] = adj_secs * last->client_count; - adj[2] = adj_secs * last->conn_count; -#ifdef DEBUGMODE - times[2][3] = - total[3] - - (last->cpu_usage * (double)adj_secs / last->time_incr); - } - else - { - adj_secs = adj[0] = adj[1] = adj[2] = adj[3] = 0; - times[2][3] = total[3]; - } -#else - } - else - adj_secs = adj[0] = adj[1] = adj[2] = 0; -#endif - for (i = 0; i < 3; i++) - { - times[2][i] = - ((total[i] - adj[i]) * 10 / (secs - adj_secs) + 5) / 10; - } - -#ifdef DEBUGMODE - bzero(total, 4 * sizeof(u_long)); -#else - bzero(total, 3 * sizeof(u_long)); -#endif - - for (secs = 1; (secs < 86400) && (cur_load_entry != NULL); secs += - (cur_load_entry->time_incr + 50) / 100, cur_load_entry = - cur_load_entry->prev, current_load_data.entries++) - { - u_long time_incr = (cur_load_entry->time_incr + 50) / 100; - total[0] += time_incr * cur_load_entry->local_count; - total[1] += time_incr * cur_load_entry->client_count; - total[2] += time_incr * cur_load_entry->conn_count; -#ifdef DEBUGMODE - total[3] += cur_load_entry->cpu_usage; -#endif - last = cur_load_entry; - } - if ((secs > 86400) && (last != NULL)) - { - adj_secs = secs - 86400; - adj[0] = adj_secs * last->local_count; - adj[1] = adj_secs * last->client_count; - adj[2] = adj_secs * last->conn_count; -#ifdef DEBUGMODE - times[3][3] = - total[3] - - (last->cpu_usage * (double)adj_secs / last->time_incr); - } - else - { - adj_secs = adj[0] = adj[1] = adj[2] = adj[3] = 0; - times[3][3] = total[3]; - } -#else - } - else - adj_secs = adj[0] = adj[1] = adj[2] = 0; -#endif - for (i = 0; i < 3; i++) - { - times[3][i] = - ((total[i] - adj[i]) * 10 / (secs - adj_secs) + 5) / 10; - } - -#ifdef DEBUGMODE - bzero(total, 4 * sizeof(u_long)); -#else - bzero(total, 3 * sizeof(u_long)); -#endif - - for (secs = 1; (secs < 86400) && (cur_load_entry != NULL); secs += - (cur_load_entry->time_incr + 50) / 100, cur_load_entry = - cur_load_entry->prev, current_load_data.entries++) - { - u_long time_incr = (cur_load_entry->time_incr + 50) / 100; - total[0] += time_incr * cur_load_entry->local_count; - total[1] += time_incr * cur_load_entry->client_count; - total[2] += time_incr * cur_load_entry->conn_count; -#ifdef DEBUGMODE - total[3] += cur_load_entry->cpu_usage; -#endif - last = cur_load_entry; - } - if ((secs > 86400) && (last != NULL)) - { - adj_secs = secs - 86400; - adj[0] = adj_secs * last->local_count; - adj[1] = adj_secs * last->client_count; - adj[2] = adj_secs * last->conn_count; -#ifdef DEBUGMODE - times[4][3] = - total[3] - - (last->cpu_usage * (double)adj_secs / last->time_incr); - } - else - { - adj_secs = adj[0] = adj[1] = adj[2] = adj[3] = 0; - times[4][3] = total[3]; - } -#else - } - else - adj_secs = adj[0] = adj[1] = adj[2] = 0; -#endif - for (i = 0; i < 3; i++) - { - times[4][i] = - ((total[i] - adj[i]) * 10 / (secs - adj_secs) + 5) / 10; - } - - if ((cur_load_entry != NULL) && (cur_load_entry->prev != NULL) && - (secs > 86400)) - { /* have nodes to free -- more than 3 days old */ - struct load_entry *cur_free_entry = load_free_head; - - load_free_head = load_list_head; - load_list_head = cur_load_entry; - if (cur_free_entry != NULL) - cur_free_entry->prev = cur_load_entry->prev; - else - load_free_tail = cur_load_entry->prev; - - /* printf("freeing: %x (head: %x, tail: %x)\n", cur_load_entry->prev, - load_free_head, load_free_tail); */ - - cur_load_entry->prev = NULL; - } - - strcpy(what[0], DOMAINNAME); - strcat(what[0], " clients"); - strcpy(what[1], "total clients"); - strcpy(what[2], "total connections"); -#ifdef DEBUGMODE - strcpy(what[3], "CPU usage"); -#endif - sendto_one(sptr, - ":%s NOTICE %s :Minute Hour Day Yest. YYest. Userload for:", - me.name, parv); - for (i = 0; i < 3; i++) - sendto_one(sptr, - ":%s NOTICE %s :%3d.%02d %3d.%01d %3d %3d %3d %s", - me.name, parv, times[0][i] / 100, times[0][i] % 100, - times[1][i] / 10, times[1][i] % 10, times[2][i], - times[3][i], times[4][i], what[i]); - -#ifdef DEBUGMODE - sendto_one(sptr, - ":%s NOTICE %s :%6.2f%% %5.1f%% %3d%% %3d%% %3d%% %s", - me.name, parv, - (double)((double)times[0][3] / (0.6 * CLOCKS_PER_SEC)), - (double)((double)times[1][3] / (36 * CLOCKS_PER_SEC)), - (int)((double)times[2][3] / (864 * CLOCKS_PER_SEC)), - (int)((double)times[3][3] / (864 * CLOCKS_PER_SEC)), - (int)((double)times[4][3] / (864 * CLOCKS_PER_SEC)), what[3]); -#endif -} - - -void initload() -{ - bzero(¤t_load_data, sizeof(struct current_load_struct)); - update_load(); /* Initialize the load list */ -}