diff mbox

[conntrack-tools,1/3] log: introduce a mechanism to know if log was initialized

Message ID 147825582201.31164.6123720868667079634.stgit@nfdev2.cica.es
State Accepted
Delegated to: Pablo Neira
Headers show

Commit Message

Arturo Borrero Gonzalez Nov. 4, 2016, 10:37 a.m. UTC
This will allow to call dlog() function from all the points in the
execution at runtime.

If the log was not initialized, then we just fprintf and return.

By now, we can't init the log engine earlier because we require config
from the user, so there is a egg-chicken problem.
This means that we can't log parsing messages to logfiles but only to
stderr/stdout.

Signed-off-by: Arturo Borrero Gonzalez <arturo@debian.org>
---
 include/conntrackd.h |    1 +
 src/log.c            |    9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)


--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Pablo Neira Ayuso Nov. 8, 2016, 11:30 p.m. UTC | #1
On Fri, Nov 04, 2016 at 11:37:02AM +0100, Arturo Borrero Gonzalez wrote:
> This will allow to call dlog() function from all the points in the
> execution at runtime.
> 
> If the log was not initialized, then we just fprintf and return.
> 
> By now, we can't init the log engine earlier because we require config
> from the user, so there is a egg-chicken problem.
> This means that we can't log parsing messages to logfiles but only to
> stderr/stdout.

Series applied, thanks Arturo.

A couple of things that would be good to revisit, just for the record:

1) Get rid of deprecated stuff. By digging into the git log history I
   guess you can probably find that they have been deprecated since
   ~2008, so it's been already enough time for people to update
   configuration files.

2) Make sure the configuration parser works fine with defaults, I mean
   with the bare minimum configuration. I remember reports from people
   that wrote configuration files from scratch, that were not working.
   So I pointed them to the example files to use as template.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/conntrackd.h b/include/conntrackd.h
index 8406c54..f995f4b 100644
--- a/include/conntrackd.h
+++ b/include/conntrackd.h
@@ -147,6 +147,7 @@  struct ct_general_state {
 	sigset_t 			block;
 	FILE 				*log;
 	FILE				*stats_log;
+	int				log_init;
 	struct local_server		local;
 	struct ct_mode 			*mode;
 	struct ct_filter		*us_filter;
diff --git a/src/log.c b/src/log.c
index 0796ba9..6deccfa 100644
--- a/src/log.c
+++ b/src/log.c
@@ -57,6 +57,8 @@  int init_log(void)
 	    CONFIG(stats).syslog_facility != -1)
 		openlog(PACKAGE, LOG_PID, CONFIG(syslog_facility));
 
+	STATE(log_init) = 1;
+
 	return 0;
 }
 
@@ -101,7 +103,7 @@  void dlog(int priority, const char *format, ...)
 	FILE *console_out;
  	va_list args;
 
-	if (CONFIG(running_mode) != DAEMON) {
+	if (CONFIG(running_mode) != DAEMON || STATE(log_init) == 0) {
 		switch (priority) {
 		case LOG_INFO:
 		case LOG_NOTICE:
@@ -118,6 +120,9 @@  void dlog(int priority, const char *format, ...)
 		va_end(args);
 	}
 
+	if (STATE(log_init) == 0)
+		return;
+
 	if (fd) {
 		va_start(args, format);
 		logline_put(fd, priority, format, &args);
@@ -211,6 +216,8 @@  void dlog_exp(FILE *fd, struct nf_expect *exp, unsigned int type)
 
 void close_log(void)
 {
+	STATE(log_init) = 0;
+
 	if (STATE(log) != NULL)
 		fclose(STATE(log));