If we are not detached (option -n is used), then print only to stdout.
This is useful if connman is run by systemd which would duplicate
the log entries if the program outputs both to syslog and stdout.
---
Hi,

Lucas sent a patch in July that removed the syslog prints
in order to avoid double prints if run under systemd.

This patch retains the syslog and does not cause double prints
in syslog when run under systemd. This is done by not printing
to syslog if -n command line option is used. 

Cheers,
Jukka


 src/log.c | 43 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/src/log.c b/src/log.c
index 9a68a4b..43ea57a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -37,6 +37,33 @@
 
 static const char *program_exec;
 static const char *program_path;
+static connman_bool_t print_syslog = TRUE;
+
+static void _syslog(int priority, const char *format, ...)
+{
+       va_list ap;
+
+       va_start(ap, format);
+
+       if (print_syslog == TRUE)
+               vsyslog(priority, format, ap);
+       else {
+               printf(format, ap);
+               printf("\n");
+       }
+
+       va_end(ap);
+}
+
+static void _vsyslog(int priority, const char *format, va_list ap)
+{
+       if (print_syslog == TRUE)
+               vsyslog(priority, format, ap);
+       else {
+               vprintf(format, ap);
+               printf("\n");
+       }
+}
 
 /**
  * connman_info:
@@ -51,7 +78,7 @@ void connman_info(const char *format, ...)
 
        va_start(ap, format);
 
-       vsyslog(LOG_INFO, format, ap);
+       _vsyslog(LOG_INFO, format, ap);
 
        va_end(ap);
 }
@@ -69,7 +96,7 @@ void connman_warn(const char *format, ...)
 
        va_start(ap, format);
 
-       vsyslog(LOG_WARNING, format, ap);
+       _vsyslog(LOG_WARNING, format, ap);
 
        va_end(ap);
 }
@@ -87,7 +114,7 @@ void connman_error(const char *format, ...)
 
        va_start(ap, format);
 
-       vsyslog(LOG_ERR, format, ap);
+       _vsyslog(LOG_ERR, format, ap);
 
        va_end(ap);
 }
@@ -105,7 +132,7 @@ void connman_debug(const char *format, ...)
 
        va_start(ap, format);
 
-       vsyslog(LOG_DEBUG, format, ap);
+       _vsyslog(LOG_DEBUG, format, ap);
 
        va_end(ap);
 }
@@ -305,22 +332,24 @@ int __connman_log_init(const char *program, const char 
*debug,
 
        __connman_log_enable(__start___debug, __stop___debug);
 
-       if (detach == FALSE)
+       if (detach == FALSE) {
                option |= LOG_PERROR;
+               print_syslog = FALSE;
+       }
 
        if (backtrace == TRUE)
                signal_setup(signal_handler);
 
        openlog(basename(program), option, LOG_DAEMON);
 
-       syslog(LOG_INFO, "Connection Manager version %s", VERSION);
+       _syslog(LOG_INFO, "Connection Manager version %s", VERSION);
 
        return 0;
 }
 
 void __connman_log_cleanup(connman_bool_t backtrace)
 {
-       syslog(LOG_INFO, "Exit");
+       _syslog(LOG_INFO, "Exit");
 
        closelog();
 
-- 
1.7.11.4

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to