[ovs-dev] [vlog 6/6] vlog: Make vlog initialize itself when necessary.

Ben Pfaff blp at nicira.com
Wed Jul 14 16:20:55 PDT 2010


---
 lib/vlog.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/lib/vlog.c b/lib/vlog.c
index 329f656..65bc08e 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -87,6 +87,9 @@ static long long int boot_time;
 static char *log_file_name;
 static FILE *log_file;
 
+/* vlog initialized? */
+static bool vlog_inited;
+
 static void format_log_message(const struct vlog_module *, enum vlog_level,
                                enum vlog_facility, unsigned int msg_num,
                                const char *message, va_list, struct ds *)
@@ -441,6 +444,11 @@ vlog_init(void)
 {
     time_t now;
 
+    if (vlog_inited) {
+        return;
+    }
+    vlog_inited = true;
+
     time_init();
 
     openlog(program_name, LOG_NDELAY, LOG_DAEMON);
@@ -465,7 +473,10 @@ vlog_init(void)
 void
 vlog_exit(void) 
 {
-    closelog(); 
+    if (vlog_inited) {
+        closelog();
+        vlog_inited = false;
+    }
 }
 
 /* Print the current logging level for each module. */
@@ -620,6 +631,8 @@ vlog_valist(const struct vlog_module *module, enum vlog_level level,
         static unsigned int msg_num;
         struct ds s;
 
+        vlog_init();
+
         ds_init(&s);
         ds_reserve(&s, 1024);
         msg_num++;
-- 
1.7.1





More information about the dev mailing list