[git commit] small fixes atop syslog config patch

Denys Vlasenko vda.linux at googlemail.com
Sat Apr 16 18:15:14 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=0288b27ad870adc437c370c262b7b41990ae0118
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 docs/syslog.conf.txt       |   28 ++++++++++++++++++++++++++++
 libbb/get_line_from_file.c |    6 +++++-
 sysklogd/Config.src        |    2 +-
 sysklogd/syslogd.c         |   12 +++++-------
 4 files changed, 39 insertions(+), 9 deletions(-)
 create mode 100644 docs/syslog.conf.txt

diff --git a/docs/syslog.conf.txt b/docs/syslog.conf.txt
new file mode 100644
index 0000000..6d9c4a1
--- /dev/null
+++ b/docs/syslog.conf.txt
@@ -0,0 +1,28 @@
+If syslogd applet compiled with FEATURE_SYSLOGD_CFG=y, then it supports restricted syslog.conf.
+The config resembles rsyslog.conf in RULES part:
+
+LINE = DELIM [RULE | COMMENT]
+COMMENT = #.*
+DELIM = SPACE TAB
+RULE = SELECTOR [;SELECTOR]* DELIM* ACTION DELIM*
+SELECTOR = FACILITY [,FACILITY]* .[[!]=] PRIORITY
+FACILITY = * | kern | user ... (see syslog.h)
+PRIORITY = * | emerg | alert ... (see syslog.h)
+ACTION = FILE
+
+"mark" facility is NOT supported.
+"none" priority is supported.
+In FACILITY and PRIORITY "*" stands for "any".
+FILE is a regular file or tty device.
+
+Here is an example:
+
+#syslog.conf
+kern,user.*                                 /var/log/messages	#all messages of kern and user facilities
+kern.!err                                   /var/log/critical	#all messages of kern facility with priorities lower than err (warn, notice ...)
+*.*;auth,authpriv.none                      /var/log/noauth	#all messages except ones with auth and authpriv facilities
+kern,user.*;kern.!=notice;*.err;syslog.none /var/log/OMG	#some whicked rule just as an example =)
+*.*                                         /dev/null		#this prevents from logging to default log file (-O FILE or /var/log/messages)
+
+Even in the case of match with some rule another rules will be tried too.
+If there was no match with any of the rules, logging to default log file or shared memory will be performed.
diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c
index a0ed919..9be1068 100644
--- a/libbb/get_line_from_file.c
+++ b/libbb/get_line_from_file.c
@@ -44,8 +44,12 @@ char* FAST_FUNC bb_get_chunk_with_continuation(FILE *file, int *end, int *lineno
 			idx -= 2;
 		}
 	}
-	if (end)
+	if (end) {
 		*end = idx;
+		/* handle corner case when the file is not ended with '\n' */
+		if (ch == EOF && lineno != NULL)
+			(*lineno)++;
+	}
 	if (linebuf) {
 		// huh, does fgets discard prior data on error like this?
 		// I don't think so....
diff --git a/sysklogd/Config.src b/sysklogd/Config.src
index b3e13d7..b7a494e 100644
--- a/sysklogd/Config.src
+++ b/sysklogd/Config.src
@@ -57,7 +57,7 @@ config FEATURE_SYSLOGD_CFG
 	default y
 	depends on SYSLOGD
 	help
-	  Supports restricted syslogd config.
+	  Supports restricted syslogd config. See docs/syslog.conf.txt
 
 config FEATURE_SYSLOGD_READ_BUFFER_SIZE
 	int "Read buffer size in bytes"
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 0799038..b6f409f 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -33,6 +33,8 @@
 //usage:     "\n	-D		Drop duplicates")
 //usage:	IF_FEATURE_IPC_SYSLOG(
 //usage:     "\n	-C[size(KiB)]	Log to shared mem buffer (read it using logread)")
+//usage:	IF_FEATURE_SYSLOGD_CFG(
+//usage:     "\n	-f FILE		Use FILE as config (default is /etc/syslog.conf)")
 /* NB: -Csize shouldn't have space (because size is optional) */
 /* //usage:  "\n	-m MIN		Minutes between MARK lines (default:20, 0=off)" */
 //usage:
@@ -284,10 +286,8 @@ static void parse_syslogdcfg(const char *file)
 		logRule_t *cur_rule;
 
 		/* unexpected trailing token? */
-		if (tok[2]) {
-			t = tok[2];
+		if (tok[2])
 			goto cfgerr;
-		}
 
 		cur_rule = *pp_rule = xzalloc(sizeof(*cur_rule));
 
@@ -307,10 +307,8 @@ static void parse_syslogdcfg(const char *file)
 				*next_selector++ = '\0';
 
 			t = strchr(cur_selector, '.');
-			if (!t) {
-				t = cur_selector;
+			if (!t)
 				goto cfgerr;
-			}
 			*t++ = '\0'; /* separate facility from priority */
 
 			negated_prio = 0;
@@ -414,7 +412,7 @@ static void parse_syslogdcfg(const char *file)
 	return;
 
  cfgerr:
-	bb_error_msg_and_die("bad line %d: wrong token '%s'", parser->lineno, t);
+	bb_error_msg_and_die("error in '%s' at line %d", file, parser->lineno);
 }
 #endif
 
-- 
1.7.3.4



More information about the busybox-cvs mailing list