- static char *program_name_copy;
- time_t now;
-
- if (vlog_inited) {
- return;
- }
- vlog_inited = true;
-
- /* openlog() is allowed to keep the pointer passed in, without making a
- * copy. The daemonize code sometimes frees and replaces 'program_name',
- * so make a private copy just for openlog(). (We keep a pointer to the
- * private copy to suppress memory leak warnings in case openlog() does
- * make its own copy.) */
- program_name_copy = program_name ? xstrdup(program_name) : NULL;
- openlog(program_name_copy, LOG_NDELAY, LOG_DAEMON);
-
- now = time_wall();
- if (now < 0) {
- struct tm tm;
- char s[128];
+ static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+
+ if (ovsthread_once_start(&once)) {
+ static char *program_name_copy;
+ long long int now;
+
+ /* Do initialization work that needs to be done before any logging
+ * occurs. We want to keep this really minimal because any attempt to
+ * log anything before calling ovsthread_once_done() will deadlock. */
+
+ /* openlog() is allowed to keep the pointer passed in, without making a
+ * copy. The daemonize code sometimes frees and replaces
+ * 'program_name', so make a private copy just for openlog(). (We keep
+ * a pointer to the private copy to suppress memory leak warnings in
+ * case openlog() does make its own copy.) */
+ program_name_copy = program_name ? xstrdup(program_name) : NULL;
+ openlog(program_name_copy, LOG_NDELAY, LOG_DAEMON);
+ ovsthread_once_done(&once);
+
+ /* Now do anything that we want to happen only once but doesn't have to
+ * finish before we start logging. */
+
+ now = time_wall_msec();
+ if (now < 0) {
+ char *s = xastrftime_msec("%a, %d %b %Y %H:%M:%S", now, true);
+ VLOG_ERR("current time is negative: %s (%lld)", s, now);
+ free(s);
+ }