CHECKER.C
LIB3/GLOBAL/CHECKER.C · 2.7 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
#define MAIL_LIST "/log/TEMPORARY_ERRORS"
#define YEAR 31449600
#define WEEK 604800
#define DAY 86400
#define HOUR 3600
#define MINUTE 60
#include "log.h";
int check_time;
static mapping list;
create()
{
seteuid( "Root" );
restore_object( file_name( this_object() ) );
if( !list )
list = ([ ]);
check_time();
}
check_time()
{
if( time() > check_time )
{
/* Next check is in 7 days */
check_time += WEEK;
check_error_log();
mail_forgoten_reports();
save_me();
}
}
check_error_log()
{
int i, j, rtime;
string reports, report;
string name, filename;
string person;
string temp;
reports = read_file( MAIL_LIST );
if( reports )
{
j = file_length( MAIL_LIST );
list = ([ ]);
for( i = 0; i < j; i++ )
{
sscanf( reports, "%s %d %s\n%s", name, rtime, filename, reports );
if( filename[ 0..1 ] == "d/" )
{
temp = "/secure/master"->get_dom_name( filename );
temp = "/d/" + temp + "/master";
person = temp->query_lord();
}
else
person = "debug";
if( rtime + (2 * WEEK) < time() )
{
if( undefinedp( list[ person ] ) )
list[ person ] = ({ filename, rtime });
else
list[ person ] += ({ filename, rtime });
}
}
}
}
mail_forgoten_reports()
{
int i, j;
string file;
string *lord;
string body;
lord = keys( list );
for( i = 0; i < sizeof( lord ); i++ )
{
body = "The following files have not been checked :\n\n";
for( j = 0; j < sizeof( list[ lord[ i ] ] ); j += 2 )
body += " " + list[ lord[ i ] ][ j ] + " for\n " +
secs_to_time( time() - list[ lord[ i ] ][ j + 1 ] ) + "\n\n";
body += "This was brought to you by :\n" +
"\tGhost's automatic error notification service.";
"/obj/handlers/mailer"->do_mail_message( lord[ i ], "Driver",
"Forgoten error reports", "", body, 0, 0 );
}
}
secs_to_time( int s )
{
int i;
string t;
t = "";
i = s / YEAR;
s -= i * YEAR;
if( i > 0 )
if( i == 1 )
t += i + " year, ";
else
t += i + " years, ";
i = s / WEEK;
s -= i * WEEK;
if( i > 0 )
if( i == 1 )
t += i + " week, ";
else
t += i + " weeks, ";
i = s / DAY;
s -= i * DAY;
if( i > 0 )
{
if( i == 1 )
t += i + " day, ";
else
t += i + " days, ";
}
i = s / HOUR;
s -= i * HOUR;
if( i == 1 )
t += i + " hour, ";
else
t += i + " hours, ";
i = s / MINUTE;
s -= i * MINUTE;
if( i == 1 )
t += i + " minute, ";
else
t += i + " minutes, ";
t += "and ";
if( s == 1 )
t += i + " second.";
else
t += i + " seconds.";
return t;
}
save_me()
{
save_object( file_name( this_object() ) );
}