summaryrefslogtreecommitdiff
path: root/sysdep/unix/config.Y
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2018-11-14 17:16:05 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2018-11-18 14:03:50 +0100
commit6712e77271fb3cb4a3c48cd7b027b39c5cea00a2 (patch)
tree9fd54c0a94001e27cc4dfe65f78dc4474126ea3f /sysdep/unix/config.Y
parentc68ba7d093e1fcf01fceb341438fc5dc95f93ac5 (diff)
Unix: Implement log file size limit / log rotation
Allow to specify log file size limit and ensure that log file is rotated to secondary name to avoid exceeding of log size limit. The patch also fixes a bug related to keeping old fds open after reconfiguration and using old fds after 'configure undo'.
Diffstat (limited to 'sysdep/unix/config.Y')
-rw-r--r--sysdep/unix/config.Y34
1 files changed, 22 insertions, 12 deletions
diff --git a/sysdep/unix/config.Y b/sysdep/unix/config.Y
index b8572c90..e7ecd735 100644
--- a/sysdep/unix/config.Y
+++ b/sysdep/unix/config.Y
@@ -11,13 +11,16 @@ CF_HDR
#include "sysdep/unix/unix.h"
#include <stdio.h>
+CF_DEFINES
+
+static struct log_config *this_log;
+
CF_DECLS
CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG, STDERR, SOFT)
CF_KEYWORDS(NAME, CONFIRM, UNDO, CHECK, TIMEOUT, DEBUG, LATENCY, LIMIT, WATCHDOG, WARNING)
%type <i> log_mask log_mask_list log_cat cfg_timeout
-%type <g> log_file
%type <t> cfg_name
%type <tf> timeformat_which
%type <t> syslog_name
@@ -26,11 +29,11 @@ CF_GRAMMAR
conf: log_config ;
-log_config: LOG log_file log_mask ';' {
- struct log_config *c = cfg_allocz(sizeof(struct log_config));
- c->fh = $2;
- c->mask = $3;
- add_tail(&new_config->logfiles, &c->n);
+log_begin: { this_log = cfg_allocz(sizeof(struct log_config)); };
+
+log_config: LOG log_begin log_file log_mask ';' {
+ this_log->mask = $4;
+ add_tail(&new_config->logfiles, &this_log->n);
}
;
@@ -39,14 +42,21 @@ syslog_name:
| { $$ = bird_name; }
;
+log_limit:
+ /* empty */
+ | expr text { this_log->limit = $1; this_log->backup = $2; }
+ ;
+
log_file:
- text {
- struct rfile *f = rf_open(new_config->pool, $1, "a");
- if (!f) cf_error("Unable to open log file '%s': %m", $1);
- $$ = rf_file(f);
+ text log_limit {
+ this_log->rf = rf_open(new_config->pool, $1, "a");
+ if (!this_log->rf) cf_error("Unable to open log file '%s': %m", $1);
+ this_log->fh = rf_file(this_log->rf);
+ this_log->pos = -1;
+ this_log->filename = $1;
}
- | SYSLOG syslog_name { $$ = NULL; new_config->syslog_name = $2; }
- | STDERR { $$ = stderr; }
+ | SYSLOG syslog_name { this_log->fh = NULL; new_config->syslog_name = $2; }
+ | STDERR { this_log->fh = stderr; }
;
log_mask: