void
vlog_init(void)
{
+ static char *program_name_copy;
time_t now;
if (vlog_inited) {
}
vlog_inited = true;
- openlog(program_name, LOG_NDELAY, LOG_DAEMON);
+ /* 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];
- localtime_r(&now, &tm);
- strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S %z", &tm);
+ gmtime_r(&now, &tm);
+ strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S", &tm);
VLOG_ERR("current time is negative: %s (%ld)", s, (long int) now);
}
case 'r':
ds_put_format(s, "%lld", time_msec() - time_boot_msec());
break;
+ case 't':
+ ds_put_cstr(s, subprogram_name[0] ? subprogram_name : "main");
+ break;
+ case 'T':
+ if (subprogram_name[0]) {
+ ds_put_format(s, "(%s)", subprogram_name);
+ }
+ break;
default:
ds_put_char(s, p[-1]);
break;
va_end(args);
}
+/* Logs 'message' to 'module' at maximum verbosity, then exits with a failure
+ * exit code. Always writes the message to stderr, even if the console
+ * facility is disabled.
+ *
+ * Choose this function instead of vlog_abort_valist() if the daemon monitoring
+ * facility shouldn't automatically restart the current daemon. */
void
vlog_fatal_valist(const struct vlog_module *module_,
const char *message, va_list args)
ovs_fatal_valist(0, message, args);
}
+/* Logs 'message' to 'module' at maximum verbosity, then exits with a failure
+ * exit code. Always writes the message to stderr, even if the console
+ * facility is disabled.
+ *
+ * Choose this function instead of vlog_abort() if the daemon monitoring
+ * facility shouldn't automatically restart the current daemon. */
void
vlog_fatal(const struct vlog_module *module, const char *message, ...)
{
va_end(args);
}
+/* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always
+ * writes the message to stderr, even if the console facility is disabled.
+ *
+ * Choose this function instead of vlog_fatal_valist() if the daemon monitoring
+ * facility should automatically restart the current daemon. */
+void
+vlog_abort_valist(const struct vlog_module *module_,
+ const char *message, va_list args)
+{
+ struct vlog_module *module = (struct vlog_module *) module_;
+
+ /* Don't log this message to the console to avoid redundancy with the
+ * message written by the later ovs_abort_valist(). */
+ module->levels[VLF_CONSOLE] = VLL_OFF;
+
+ vlog_valist(module, VLL_EMER, message, args);
+ ovs_abort_valist(0, message, args);
+}
+
+/* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always
+ * writes the message to stderr, even if the console facility is disabled.
+ *
+ * Choose this function instead of vlog_fatal() if the daemon monitoring
+ * facility should automatically restart the current daemon. */
+void
+vlog_abort(const struct vlog_module *module, const char *message, ...)
+{
+ va_list args;
+
+ va_start(args, message);
+ vlog_abort_valist(module, message, args);
+ va_end(args);
+}
+
bool
vlog_should_drop(const struct vlog_module *module, enum vlog_level level,
struct vlog_rate_limit *rl)
return true;
}
- if (rl->tokens < VLOG_MSG_TOKENS) {
+ if (!token_bucket_withdraw(&rl->token_bucket, VLOG_MSG_TOKENS)) {
time_t now = time_now();
- if (rl->last_fill > now) {
- /* Last filled in the future? Time must have gone backward, or
- * 'rl' has not been used before. */
- rl->tokens = rl->burst;
- } else if (rl->last_fill < now) {
- unsigned int add = sat_mul(rl->rate, now - rl->last_fill);
- unsigned int tokens = sat_add(rl->tokens, add);
- rl->tokens = MIN(tokens, rl->burst);
- rl->last_fill = now;
- }
- if (rl->tokens < VLOG_MSG_TOKENS) {
- if (!rl->n_dropped) {
- rl->first_dropped = now;
- }
- rl->last_dropped = now;
- rl->n_dropped++;
- return true;
+ if (!rl->n_dropped) {
+ rl->first_dropped = now;
}
+ rl->last_dropped = now;
+ rl->n_dropped++;
+ return true;
}
- rl->tokens -= VLOG_MSG_TOKENS;
if (rl->n_dropped) {
time_t now = time_now();