aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@Pirx.gnu.org.ua>2009-04-27 17:23:50 +0300
committerSergey Poznyakoff <gray@Pirx.gnu.org.ua>2009-04-27 17:23:50 +0300
commit4d22b4e8668cc717440d66120b8607be9a273c97 (patch)
tree93b4addac108a1c8e913f0d5c68cb513f5c82c31
parentfe8f5226e8bc39bdc75e40e1c1ea464e9fc60ad3 (diff)
downloadtagr-4d22b4e8668cc717440d66120b8607be9a273c97.tar.gz
tagr-4d22b4e8668cc717440d66120b8607be9a273c97.tar.bz2
Bugfixes.
* src/main.c (change_user): Bugfix (main): Reset user to the value of user_option, if set. Fix (again) log_to_stderr initialization. Switch to user privileges before actually performing any actions that modify the database and other output files. * src/report.c (open_db): Don't exit if unable to open database. Return 1 instead. All callers updated. * src/tagr.h (open_db): Update prototype.
-rw-r--r--src/main.c46
-rw-r--r--src/report.c26
-rw-r--r--src/stat.c6
-rw-r--r--src/tagr.h2
4 files changed, 47 insertions, 33 deletions
diff --git a/src/main.c b/src/main.c
index 9b98ec5..6530ca0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -435,3 +435,3 @@ change_user ()
435 435
436 if (getuid () == 0) 436 if (getuid ())
437 { 437 {
@@ -496,11 +496,13 @@ decode_buffer ()
496 496
497 open_db (TAGR_DB_WR); 497 if (open_db (TAGR_DB_WR) == 0)
498 for (i = 0; i < reply->n_addr; i++, sp++)
499 { 498 {
500 sp->in = ntohl (sp->in); 499 for (i = 0; i < reply->n_addr; i++, sp++)
501 sp->out = ntohl (sp->out); 500 {
502 verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out); 501 sp->in = ntohl (sp->in);
503 report (sp, reply->timestamp); 502 sp->out = ntohl (sp->out);
503 verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out);
504 report (sp, reply->timestamp);
505 }
506 close_db ();
504 } 507 }
505 close_db ();
506 508
@@ -533,5 +535,5 @@ read_input (const char *name)
533 535
534 verbose (2, _("Reading `%s'"), name); 536 if (open_db (TAGR_DB_WR))
535 537 exit (EX_UNAVAILABLE);
536 open_db (TAGR_DB_WR); 538
537 while (getline (&buf, &bufsize, fp) > 0) 539 while (getline (&buf, &bufsize, fp) > 0)
@@ -773,2 +775,4 @@ main (int argc, char **argv)
773 html_template = html_template_option; 775 html_template = html_template_option;
776 if (user_option)
777 user = user_option;
774 778
@@ -792,7 +796,2 @@ main (int argc, char **argv)
792 796
793 if (log_to_stderr == -1)
794 log_to_stderr = foreground && isatty (0);
795 grecs_log_to_stderr = log_to_stderr;
796 init_syslog (program_invocation_short_name);
797
798 if (test_template_option) 797 if (test_template_option)
@@ -806,2 +805,14 @@ main (int argc, char **argv)
806 805
806 if (user)
807 change_user ();
808
809 if (log_to_stderr == -1)
810 log_to_stderr = (import_option
811 || read_option
812 || rebuild_option
813 || list_option
814 || foreground) && isatty (0);
815 grecs_log_to_stderr = log_to_stderr;
816 init_syslog (program_invocation_short_name);
817
807 if (import_option) 818 if (import_option)
@@ -840,5 +851,2 @@ main (int argc, char **argv)
840 851
841 if (user_option)
842 change_user ();
843
844 sockfd = socket (listen_sockaddr.sa->sa_family, 852 sockfd = socket (listen_sockaddr.sa->sa_family,
diff --git a/src/report.c b/src/report.c
index ed3a81b..398881b 100644
--- a/src/report.c
+++ b/src/report.c
@@ -43,3 +43,3 @@ tagr_db_report (char *str)
43 43
44void 44int
45open_db (int flag) 45open_db (int flag)
@@ -57,4 +57,5 @@ open_db (int flag)
57 dbname, gdbm_strerror (gdbm_errno)); 57 dbname, gdbm_strerror (gdbm_errno));
58 exit (1); 58 return 1;
59 } 59 }
60 return 0;
60} 61}
@@ -204,3 +205,4 @@ list_db ()
204 205
205 open_db (TAGR_DB_RD); 206 if (open_db (TAGR_DB_RD))
207 exit (EX_UNAVAILABLE);
206 key = gdbm_firstkey (dbf); 208 key = gdbm_firstkey (dbf);
@@ -280,12 +282,14 @@ rebuild (int force)
280 verbose (1, _("rebuild initiated")); 282 verbose (1, _("rebuild initiated"));
281 open_db (TAGR_DB_WR); 283 if (open_db (TAGR_DB_RD) == 0)
282 key = gdbm_firstkey (dbf);
283 while (key.dptr)
284 { 284 {
285 datum nextkey = gdbm_nextkey ( dbf, key ); 285 key = gdbm_firstkey (dbf);
286 update_monitor (key, now, force); 286 while (key.dptr)
287 free (key.dptr); 287 {
288 key = nextkey; 288 datum nextkey = gdbm_nextkey ( dbf, key );
289 update_monitor (key, now, force);
290 free (key.dptr);
291 key = nextkey;
292 }
293 close_db ();
289 } 294 }
290 close_db ();
291 verbose (1, _("rebuild finished")); 295 verbose (1, _("rebuild finished"));
diff --git a/src/stat.c b/src/stat.c
index 85b76d9..813c5cb 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -428,3 +428,4 @@ import (const char *dirname)
428 { 428 {
429 open_db (TAGR_DB_WR); 429 if (open_db (TAGR_DB_WR))
430 exit (EX_UNAVAILABLE);
430 if (import_log (dirname) == 0) 431 if (import_log (dirname) == 0)
@@ -447,3 +448,4 @@ import (const char *dirname)
447 case 0: 448 case 0:
448 open_db (TAGR_DB_WR); 449 if (open_db (TAGR_DB_WR))
450 exit (EX_UNAVAILABLE);
449 for (i = 0; i < gl.gl_pathc; i++) 451 for (i = 0; i < gl.gl_pathc; i++)
diff --git a/src/tagr.h b/src/tagr.h
index fafd56b..a66837e 100644
--- a/src/tagr.h
+++ b/src/tagr.h
@@ -218,3 +218,3 @@ struct traffic_record
218#define TAGR_DB_WR 1 218#define TAGR_DB_WR 1
219void open_db (int); 219int open_db (int);
220void close_db (); 220void close_db ();

Return to:

Send suggestions and report system problems to the System administrator.