diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-29 18:11:56 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-29 18:11:56 +0300 |
commit | 5a1f674eecba607ffa328484ca34c598690ff8d2 (patch) | |
tree | 5dcda78e8352461d2ee7fdc29c64a265024cb219 /src/report.c | |
parent | 20d7f1d7e051c6b021a3f5d088985a74c3370b29 (diff) | |
download | tagr-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')
-rw-r--r-- | src/report.c | 37 |
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 | |||
@@ -30,31 +30,41 @@ | |||
30 | #include <arpa/inet.h> | 30 | #include <arpa/inet.h> |
31 | #include <tagr.h> | 31 | #include <tagr.h> |
32 | #include <report.h> | 32 | #include <report.h> |
33 | #include <fprintftime.h> | 33 | #include <fprintftime.h> |
34 | #include <gdbm.h> | 34 | #include <gdbm.h> |
35 | 35 | ||
36 | unsigned lock_retry_count_option = 5; | ||
37 | unsigned lock_retry_timeout_option = 1; | ||
38 | |||
36 | static char *dbname; | 39 | static char *dbname; |
37 | static GDBM_FILE dbf; | 40 | static GDBM_FILE dbf; |
38 | 41 | ||
39 | static void | 42 | static void |
40 | tagr_db_report (char *str) | 43 | tagr_db_report (char *str) |
41 | { | 44 | { |
42 | logmsg (L_CRIT, "%s: %s", dbname, str); | 45 | logmsg (L_CRIT, "%s: %s", dbname, str); |
43 | } | 46 | } |
44 | 47 | ||
45 | int | 48 | int |
46 | open_db (int flag) | 49 | open_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"), |
58 | dbname, gdbm_strerror (gdbm_errno)); | 68 | dbname, gdbm_strerror (gdbm_errno)); |
59 | return 1; | 69 | return 1; |
60 | } | 70 | } |
@@ -248,13 +258,13 @@ report (Stat *stat, time_t timestamp) | |||
248 | } | 258 | } |
249 | else | 259 | else |
250 | logmsg (L_WARNING, _("%s not found in config"), stat->name); | 260 | logmsg (L_WARNING, _("%s not found in config"), stat->name); |
251 | } | 261 | } |
252 | 262 | ||
253 | int | 263 | int |
254 | update_monitor (datum key, time_t timestamp, int force) | 264 | update_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; |
258 | struct monitor *mon; | 268 | struct monitor *mon; |
259 | 269 | ||
260 | if (key.dsize > MAX_NAME_LENGTH) | 270 | if (key.dsize > MAX_NAME_LENGTH) |
@@ -270,35 +280,34 @@ update_monitor (datum key, time_t timestamp, int force) | |||
270 | logmsg (L_ERR, _("%s: no such monitor"), id); | 280 | logmsg (L_ERR, _("%s: no such monitor"), id); |
271 | return 1; | 281 | return 1; |
272 | } | 282 | } |
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 | ||
281 | return 0; | 290 | return 0; |
282 | } | 291 | } |
283 | 292 | ||
284 | void | 293 | void |
285 | rebuild (int force) | 294 | rebuild (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 | } |
302 | close_db (); | 311 | close_db (); |
303 | } | 312 | } |
304 | verbose (1, _("rebuild finished")); | 313 | verbose (1, _("rebuild finished")); |