aboutsummaryrefslogtreecommitdiff
path: root/src/report.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/report.c')
-rw-r--r--src/report.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/report.c b/src/report.c
index 71a735f..ab4cada 100644
--- a/src/report.c
+++ b/src/report.c
@@ -33,6 +33,9 @@
#include <fprintftime.h>
#include <gdbm.h>
+unsigned lock_retry_count_option = 5;
+unsigned lock_retry_timeout_option = 1;
+
static char *dbname;
static GDBM_FILE dbf;
@@ -45,13 +48,20 @@ tagr_db_report (char *str)
int
open_db (int flag)
{
- dbname = xmalloc (strlen (basedir) + 1 + sizeof (TAGR_DBNAME));
- strcpy (dbname, basedir);
- strcat (dbname, "/");
- strcat (dbname, TAGR_DBNAME);
+ unsigned i;
+
+ dbname = mkfilename (basedir, TAGR_DBNAME, NULL);
+
+ for (i = 0; i < lock_retry_count_option; i++)
+ {
dbf = gdbm_open (dbname, 0,
flag == TAGR_DB_WR ? GDBM_WRCREAT : GDBM_READER,
TAGR_DBMODE, tagr_db_report);
+ if (dbf || errno != EAGAIN)
+ break;
+ sleep (lock_retry_timeout_option);
+ }
+
if (dbf == NULL)
{
logmsg (L_ERR, _("cannot open database %s: %s"),
@@ -251,7 +261,7 @@ report (Stat *stat, time_t timestamp)
}
int
-update_monitor (datum key, time_t timestamp, int force)
+update_monitor (datum key, time_t timestamp, int flags)
{
char id[MAX_NAME_LENGTH+1];
struct traffic_record *tr = NULL;
@@ -273,8 +283,7 @@ update_monitor (datum key, time_t timestamp, int force)
_read_db (key, &tr);
if (tr)
{
- update_output (mon, tr, tr->last.time /*FIXME: must be now? */,
- force);
+ update_output (mon, tr, timestamp, flags);
free (tr);
}
@@ -282,7 +291,7 @@ update_monitor (datum key, time_t timestamp, int force)
}
void
-rebuild (int force)
+rebuild (int flags)
{
datum key;
datum content;
@@ -295,7 +304,7 @@ rebuild (int force)
while (key.dptr)
{
datum nextkey = gdbm_nextkey (dbf, key);
- update_monitor (key, now, force);
+ update_monitor (key, now, flags);
free (key.dptr);
key = nextkey;
}

Return to:

Send suggestions and report system problems to the System administrator.