Commit 24921523 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Log all accesses to the data base.

parent 5c8ec4b0
Tue Oct 27 05:27:55 1992 Per Cederqvist (ceder@ruben)
* version.incl: Version 1.2.6.
* simple-cache.c (LOGFILE): If #define'd, log every usage of the
database to the file whose filename LOGFILE is set to.
Thu Oct 8 08:51:23 1992 Per Cederqvist (ceder@mauritz)
* tmp-limits.h: Allow 333333 texts.
......
#define LOGFILE "/users/ceder/log-from-lyskom"
/*
* $Id: simple-cache.c,v 0.25 1992/08/12 04:11:14 ceder Exp $
* $Id: simple-cache.c,v 0.26 1992/10/27 04:42:51 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -33,7 +34,7 @@
* New save algorithm by ceder.
*/
static char *rcsid = "$Id: simple-cache.c,v 0.25 1992/08/12 04:11:14 ceder Exp $";
static char *rcsid = "$Id: simple-cache.c,v 0.26 1992/10/27 04:42:51 ceder Exp $";
......@@ -124,6 +125,9 @@ static Text_no highest_text_no;
BUGDECL;
#ifdef LOGFILE
static FILE *logfile=NULL;
#endif
/* Macros */
......@@ -210,10 +214,24 @@ conf_set_mru(Conf_no conf_no)
static Cache_node *
get_pers_node(Pers_no pers_no)
{
#ifdef LOGFILE
Cache_node *res;
#endif
if ( pers_no >= next_free_num )
return NULL;
#ifndef LOGFILE
return get_cache_node(pers_mcb, pers_no);
#else
res = get_cache_node(pers_mcb, pers_no);
if (logfile)
{
putc(0, logfile);
putw(pers_no, logfile);
}
return res;
#endif
}
static void
......@@ -237,19 +255,49 @@ unlink_pers_lru (Cache_node *node)
static Cache_node *
get_conf_node(Conf_no conf_no)
{
#ifdef LOGFILE
Cache_node *res;
#endif
if ( conf_no >= next_free_num )
return NULL;
#ifndef LOGFILE
return get_cache_node(conf_mcb, conf_no);
#else
res = get_cache_node(conf_mcb, conf_no);
if (logfile)
{
putc(1, logfile);
putw(conf_no, logfile);
}
return res;
#endif
}
static Cache_node *
get_text_node(Text_no text_no)
{
#ifdef LOGFILE
Cache_node *res;
#endif
if ( text_no >= next_text_num )
return NULL;
#ifndef LOGFILE
return get_cache_node(text_mcb, text_no);
#else
res = get_cache_node(text_mcb, text_no);
if(logfile)
{
putc(2, logfile);
putw(text_no, logfile);
}
return res;
#endif
}
......@@ -722,6 +770,13 @@ cached_get_text( Text_no text )
return EMPTY_STRING;
else
{
#ifdef LOGFILE
if(logfile)
{
putc(5, logfile);
putw(text, logfile);
}
#endif
the_string.string = tmp_alloc( t_stat->no_of_chars );
the_string.len = t_stat->no_of_chars;
fseek(text_file, t_stat->file_pos, SEEK_SET);
......@@ -944,6 +999,13 @@ cached_lock_person(Pers_no pers_no)
}
node->lock_cnt++;
#ifdef LOGFILE
if(logfile)
{
putc(6, logfile);
putw(pers_no, logfile);
}
#endif
}
/* Decrease reference count. If zero, unlock person. */
......@@ -966,6 +1028,13 @@ cached_unlock_person(Pers_no pers_no)
}
else
node->lock_cnt--;
#ifdef LOGFILE
if(logfile)
{
putc(7, logfile);
putw(pers_no, logfile);
}
#endif
}
......@@ -1000,6 +1069,13 @@ cached_lock_conf(Conf_no conf_no)
}
node->lock_cnt++;
#ifdef LOGFILE
if(logfile)
{
putc(8, logfile);
putw(conf_no, logfile);
}
#endif
}
/* Decrease reference count. If zero, unlock conf. */
......@@ -1021,6 +1097,14 @@ cached_unlock_conf(Conf_no conf_no)
}
else
node->lock_cnt--;
#ifdef LOGFILE
if(logfile)
{
putc(9, logfile);
putw(conf_no, logfile);
}
#endif
}
......@@ -1661,6 +1745,11 @@ Bool
sync_part(void)
{
static time_t last_sync_start = NO_TIME;
#ifdef LOGFILE
FILE *lfsave = logfile;
logfile = NULL;
#endif
if ( last_sync_start == NO_TIME )
{
......@@ -1684,16 +1773,34 @@ sync_part(void)
case sync_ready:
if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_INTERVAL )
{
#ifdef LOGFILE
logfile = lfsave;
#endif
return TRUE;
}
last_sync_start = time(NULL);
#ifdef LOGFILE
if(lfsave)
{
putc(255, lfsave);
putw(-1, lfsave);
putc(10, lfsave);
putw(time(NULL), lfsave);
}
#endif
pre_sync();
break;
case sync_wait:
if ( difftime(time(NULL), last_sync_start) < 60 * SYNC_RETRY_INTERVAL )
{
#ifdef LOGFILE
logfile = lfsave;
#endif
return TRUE;
}
last_sync_start = time(NULL);
......@@ -1716,6 +1823,9 @@ sync_part(void)
if ( file_b != NULL && ferror(file_b) != 0)
sync_state = sync_error;
#ifdef LOGFILE
logfile = lfsave;
#endif
return FALSE;
}
......@@ -1744,6 +1854,20 @@ init_cache(void)
Person tmp_pers = EMPTY_PERSON;
Text_stat tmp_text = EMPTY_TEXT_STAT;
#ifdef LOGFILE
logfile = fopen(LOGFILE, "a");
if (logfile == NULL)
{
log("MSG: can not open cache-status logfile.\n");
}
else
{
putc(255, logfile);
putw(-1, logfile);
putc(3, logfile);
putw(time(NULL), logfile);
}
#endif
pers_mcb = create_cache_node_mcb(100, MAX_CONF);
conf_mcb = create_cache_node_mcb(100, MAX_CONF);
text_mcb = create_cache_node_mcb(100, MAX_TEXT);
......@@ -1871,6 +1995,14 @@ init_cache(void)
log("Read %d confs/persons and %d texts\n",
next_free_num, next_text_num);
#ifdef LOGFILE
if(logfile)
{
putc(4, logfile);
putw(time(NULL), logfile);
}
#endif
return OK;
}
......@@ -1894,6 +2026,12 @@ free_all_cache (void)
int i;
Cache_node *node;
#ifdef LOGFILE
if(logfile)
fclose(logfile); /* Stop gathering data. */
logfile = NULL;
#endif
for ( i = 0; i < next_free_num; i++ )
{
node = get_conf_node(i);
......
/*
* $Id: version.incl,v 0.32 1992/09/06 18:59:29 ceder Exp $
* $Id: version.incl,v 0.33 1992/10/27 04:43:02 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -27,4 +27,4 @@
* The version number is encoded in a long. It shall be printed as
* in sed s/\(.*\)\(..\)\(..\)/\1.\2.\3/
*/
10205
10206
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment