diff options
author | Sergey Poznyakoff <gray@Pirx.gnu.org.ua> | 2009-04-27 17:23:50 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@Pirx.gnu.org.ua> | 2009-04-27 17:23:50 +0300 |
commit | 4d22b4e8668cc717440d66120b8607be9a273c97 (patch) | |
tree | 93b4addac108a1c8e913f0d5c68cb513f5c82c31 /src/main.c | |
parent | fe8f5226e8bc39bdc75e40e1c1ea464e9fc60ad3 (diff) | |
download | tagr-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.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 46 |
1 files changed, 27 insertions, 19 deletions
@@ -433,7 +433,7 @@ change_user () if (user == NULL) return; - if (getuid () == 0) + if (getuid ()) { logmsg (L_NOTICE, _("not a superuser: ignoring the `user' statement")); return; @@ -494,15 +494,17 @@ decode_buffer () } } - open_db (TAGR_DB_WR); - for (i = 0; i < reply->n_addr; i++, sp++) + if (open_db (TAGR_DB_WR) == 0) { - sp->in = ntohl (sp->in); - sp->out = ntohl (sp->out); - verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out); - report (sp, reply->timestamp); + for (i = 0; i < reply->n_addr; i++, sp++) + { + sp->in = ntohl (sp->in); + sp->out = ntohl (sp->out); + verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out); + report (sp, reply->timestamp); + } + close_db (); } - close_db (); if (child) exit (0); @@ -531,9 +533,9 @@ read_input (const char *name) name, strerror (errno)); } - verbose (2, _("Reading `%s'"), name); - - open_db (TAGR_DB_WR); + if (open_db (TAGR_DB_WR)) + exit (EX_UNAVAILABLE); + while (getline (&buf, &bufsize, fp) > 0) { char *p; @@ -771,6 +773,8 @@ main (int argc, char **argv) if (html_template_option) html_template = html_template_option; + if (user_option) + user = user_option; argc -= index; argv += index; @@ -790,11 +794,6 @@ main (int argc, char **argv) exit (0); } - if (log_to_stderr == -1) - log_to_stderr = foreground && isatty (0); - grecs_log_to_stderr = log_to_stderr; - init_syslog (program_invocation_short_name); - if (test_template_option) { CHECK_USAGE (import_option, "--import", "--test-template"); @@ -804,6 +803,18 @@ main (int argc, char **argv) exit (check_template ()); } + if (user) + change_user (); + + if (log_to_stderr == -1) + log_to_stderr = (import_option + || read_option + || rebuild_option + || list_option + || foreground) && isatty (0); + grecs_log_to_stderr = log_to_stderr; + init_syslog (program_invocation_short_name); + if (import_option) { CHECK_USAGE (read_option, "--read", "--import"); @@ -838,9 +849,6 @@ main (int argc, char **argv) exit (EX_CONFIG); } - if (user_option) - change_user (); - sockfd = socket (listen_sockaddr.sa->sa_family, SOCK_DGRAM, 0); if (sockfd < 0) |