summaryrefslogtreecommitdiffabout
path: root/src/report.c
authorSergey Poznyakoff <gray@gnu.org.ua>2009-04-29 15:11:56 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2009-04-29 15:11:56 (GMT)
commit5a1f674eecba607ffa328484ca34c598690ff8d2 (patch) (unidiff)
tree5dcda78e8352461d2ee7fdc29c64a265024cb219 /src/report.c
parent20d7f1d7e051c6b021a3f5d088985a74c3370b29 (diff)
downloadtagr-5a1f674eecba607ffa328484ca34c598690ff8d2.tar.gz
tagr-5a1f674eecba607ffa328484ca34c598690ff8d2.tar.bz2
Fix locking issues. Improve stream interface.
* gnulib.modules: Add c-type, c-strcase, crypto/md5, xgetdomainname, xgethostname. * src/Makefile.am (tagr_SOURCES): Add apop.c, udb.c, xhostname.c * src/graph.c (draw_graph): Rename `now' to `start'. * src/main.c (hostname, rebuild_last_option): New globals. (main): Init hostname. * src/output.c (update_output): Change semantics of the last parameter. * src/readconfig.c (cb_facility): Use c_strcasecmp. (tagr_kw): New keywords: hostname, udb-file, lock-count, lock-timeout, idle-timeout. * src/report.c: Fix locking issues. (update_monitor): Change semantics of the last parameter. (rebuild): Likewise. * src/server.c: Rewrite stream interface. * src/tagr.h (TAGR_ARG_UNUSED, TAGR_PRINTFLIKE): New macros. (lock_retry_count_option, lock_retry_timeout_option) (stream_idle_timeout, hostname): New declarations. (TAGR_UPD_FORCE, TAGR_UPD_LASTTIME): New defines. (trim_crlf, tagr_local_hostnamem tagr_auth_init, tagr_auth) (tagr_udb_name) (udb_get_passwordudb_free_password): New declarations. * TODO: Update
Diffstat (limited to 'src/report.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/report.c37
1 files changed, 23 insertions, 14 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 @@
33#include <fprintftime.h> 33#include <fprintftime.h>
34#include <gdbm.h> 34#include <gdbm.h>
35 35
36unsigned lock_retry_count_option = 5;
37unsigned lock_retry_timeout_option = 1;
38
36static char *dbname; 39static char *dbname;
37static GDBM_FILE dbf; 40static GDBM_FILE dbf;
38 41
@@ -45,13 +48,20 @@ tagr_db_report (char *str)
45int 48int
46open_db (int flag) 49open_db (int flag)
47{ 50{
48 dbname = xmalloc (strlen (basedir) + 1 + sizeof (TAGR_DBNAME)); 51 unsigned i;
49 strcpy (dbname, basedir); 52
50 strcat (dbname, "/"); 53 dbname = mkfilename (basedir, TAGR_DBNAME, NULL);
51 strcat (dbname, TAGR_DBNAME); 54
52 dbf = gdbm_open (dbname, 0, 55 for (i = 0; i < lock_retry_count_option; i++)
53 flag == TAGR_DB_WR ? GDBM_WRCREAT : GDBM_READER, 56 {
54 TAGR_DBMODE, tagr_db_report); 57 dbf = gdbm_open (dbname, 0,
58 flag == TAGR_DB_WR ? GDBM_WRCREAT : GDBM_READER,
59 TAGR_DBMODE, tagr_db_report);
60 if (dbf || errno != EAGAIN)
61 break;
62 sleep (lock_retry_timeout_option);
63 }
64
55 if (dbf == NULL) 65 if (dbf == NULL)
56 { 66 {
57 logmsg (L_ERR, _("cannot open database %s: %s"), 67 logmsg (L_ERR, _("cannot open database %s: %s"),
@@ -251,7 +261,7 @@ report (Stat *stat, time_t timestamp)
251} 261}
252 262
253int 263int
254update_monitor (datum key, time_t timestamp, int force) 264update_monitor (datum key, time_t timestamp, int flags)
255{ 265{
256 char id[MAX_NAME_LENGTH+1]; 266 char id[MAX_NAME_LENGTH+1];
257 struct traffic_record *tr = NULL; 267 struct traffic_record *tr = NULL;
@@ -273,8 +283,7 @@ update_monitor (datum key, time_t timestamp, int force)
273 _read_db (key, &tr); 283 _read_db (key, &tr);
274 if (tr) 284 if (tr)
275 { 285 {
276 update_output (mon, tr, tr->last.time /*FIXME: must be now? */, 286 update_output (mon, tr, timestamp, flags);
277 force);
278 free (tr); 287 free (tr);
279 } 288 }
280 289
@@ -282,20 +291,20 @@ update_monitor (datum key, time_t timestamp, int force)
282} 291}
283 292
284void 293void
285rebuild (int force) 294rebuild (int flags)
286{ 295{
287 datum key; 296 datum key;
288 datum content; 297 datum content;
289 time_t now = time (NULL); 298 time_t now = time (NULL);
290 299
291 verbose (1, _("rebuild initiated")); 300 verbose (1, _("rebuild initiated"));
292 if (open_db (TAGR_DB_RD) == 0) 301 if (open_db (TAGR_DB_RD) == 0)
293 { 302 {
294 key = gdbm_firstkey (dbf); 303 key = gdbm_firstkey (dbf);
295 while (key.dptr) 304 while (key.dptr)
296 { 305 {
297 datum nextkey = gdbm_nextkey ( dbf, key ); 306 datum nextkey = gdbm_nextkey (dbf, key);
298 update_monitor (key, now, force); 307 update_monitor (key, now, flags);
299 free (key.dptr); 308 free (key.dptr);
300 key = nextkey; 309 key = nextkey;
301 } 310 }

Return to:

Send suggestions and report system problems to the System administrator.