|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
b3514a |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
b3514a |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
b3514a |
* of the License, or (at your option) any later version.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b3514a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b3514a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b3514a |
* GNU General Public License for more details.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b3514a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b3514a |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
b3514a |
* 02110-1301, USA.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/logger.c#4 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "logger.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include <linux/delay.h>
|
|
Packit Service |
b3514a |
#include <linux/hardirq.h>
|
|
Packit Service |
b3514a |
#include <linux/module.h>
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "errors.h"
|
|
Packit Service |
b3514a |
#include "threadDevice.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static const int DEFAULT_PRIORITY = LOG_INFO;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef struct {
|
|
Packit Service |
b3514a |
const char *name;
|
|
Packit Service |
b3514a |
const int priority;
|
|
Packit Service |
b3514a |
} PRIORITY_NAMES;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static const PRIORITY_NAMES PRIORITIES[] = {
|
|
Packit Service |
b3514a |
{ "ALERT", LOG_ALERT },
|
|
Packit Service |
b3514a |
{ "CRIT", LOG_CRIT },
|
|
Packit Service |
b3514a |
{ "CRITICAL", LOG_CRIT },
|
|
Packit Service |
b3514a |
{ "DEBUG", LOG_DEBUG },
|
|
Packit Service |
b3514a |
{ "EMERG", LOG_EMERG },
|
|
Packit Service |
b3514a |
{ "EMERGENCY", LOG_EMERG },
|
|
Packit Service |
b3514a |
{ "ERR", LOG_ERR },
|
|
Packit Service |
b3514a |
{ "ERROR", LOG_ERR },
|
|
Packit Service |
b3514a |
{ "INFO", LOG_INFO },
|
|
Packit Service |
b3514a |
{ "NOTICE", LOG_NOTICE },
|
|
Packit Service |
b3514a |
{ "PANIC", LOG_EMERG },
|
|
Packit Service |
b3514a |
{ "WARN", LOG_WARNING },
|
|
Packit Service |
b3514a |
{ "WARNING", LOG_WARNING },
|
|
Packit Service |
b3514a |
{ NULL, -1 },
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
enum {
|
|
Packit Service |
b3514a |
PRIORITY_COUNT = 8
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static const char *PRIORITY_STRINGS[] = {
|
|
Packit Service |
b3514a |
"EMERGENCY",
|
|
Packit Service |
b3514a |
"ALERT",
|
|
Packit Service |
b3514a |
"CRITICAL",
|
|
Packit Service |
b3514a |
"ERROR",
|
|
Packit Service |
b3514a |
"WARN",
|
|
Packit Service |
b3514a |
"NOTICE",
|
|
Packit Service |
b3514a |
"INFO",
|
|
Packit Service |
b3514a |
"DEBUG",
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static int logLevel = LOG_INFO;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int stringToPriority(const char *string)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
for (int i = 0; PRIORITIES[i].name != NULL; i++) {
|
|
Packit Service |
b3514a |
if (strcasecmp(string, PRIORITIES[i].name) == 0) {
|
|
Packit Service |
b3514a |
return PRIORITIES[i].priority;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return DEFAULT_PRIORITY;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int getLogLevel(void)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return logLevel;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void setLogLevel(int newLogLevel)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
logLevel = newLogLevel;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
const char *priorityToString(int priority)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if ((priority < 0) || (priority >= PRIORITY_COUNT)) {
|
|
Packit Service |
b3514a |
return "unknown";
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return PRIORITY_STRINGS[priority];
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static const char *priorityToLogLevel(int priority)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
switch (priority) {
|
|
Packit Service |
b3514a |
case LOG_EMERG:
|
|
Packit Service |
b3514a |
case LOG_ALERT:
|
|
Packit Service |
b3514a |
case LOG_CRIT:
|
|
Packit Service |
b3514a |
return KERN_CRIT;
|
|
Packit Service |
b3514a |
case LOG_ERR:
|
|
Packit Service |
b3514a |
return KERN_ERR;
|
|
Packit Service |
b3514a |
case LOG_WARNING:
|
|
Packit Service |
b3514a |
return KERN_WARNING;
|
|
Packit Service |
b3514a |
case LOG_NOTICE:
|
|
Packit Service |
b3514a |
return KERN_NOTICE;
|
|
Packit Service |
b3514a |
case LOG_INFO:
|
|
Packit Service |
b3514a |
return KERN_INFO;
|
|
Packit Service |
b3514a |
case LOG_DEBUG:
|
|
Packit Service |
b3514a |
return KERN_DEBUG;
|
|
Packit Service |
b3514a |
default:
|
|
Packit Service |
b3514a |
return "";
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static const char *getCurrentInterruptType(void)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (in_nmi()) {
|
|
Packit Service |
b3514a |
return "NMI";
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
if (in_irq()) {
|
|
Packit Service |
b3514a |
return "HI";
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
if (in_softirq()) {
|
|
Packit Service |
b3514a |
return "SI";
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return "INTR";
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Emit a log message to the kernel log in a format suited to the current
|
|
Packit Service |
b3514a |
* thread context. Context info formats:
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* interrupt: kvdo[NMI]: blah
|
|
Packit Service |
b3514a |
* thread w/dev id: kvdo12:myprog: blah
|
|
Packit Service |
b3514a |
* kvdo thread: kvdo12:foobarQ: blah
|
|
Packit Service |
b3514a |
* other thread: kvdo: myprog: blah
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Fields: module name, interrupt level, process name, device ID.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param level A string describing the logging level
|
|
Packit Service |
b3514a |
* @param moduleName The name of the module doing the logging
|
|
Packit Service |
b3514a |
* @param prefix The prefix of the log message
|
|
Packit Service |
b3514a |
* @param vaf1 The first message format descriptor
|
|
Packit Service |
b3514a |
* @param vaf2 The second message format descriptor
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void emitLogMessage(const char *level,
|
|
Packit Service |
b3514a |
const char *moduleName,
|
|
Packit Service |
b3514a |
const char *prefix,
|
|
Packit Service |
b3514a |
const struct va_format *vaf1,
|
|
Packit Service |
b3514a |
const struct va_format *vaf2)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (in_interrupt()) {
|
|
Packit Service |
b3514a |
printk("%s%s[%s]: %s%pV%pV\n",
|
|
Packit Service |
b3514a |
level, moduleName, getCurrentInterruptType(),
|
|
Packit Service |
b3514a |
prefix, vaf1, vaf2);
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Not at interrupt level; we have a process we can look at, and
|
|
Packit Service |
b3514a |
// might have a device ID.
|
|
Packit Service |
b3514a |
int deviceInstance = getThreadDeviceID();
|
|
Packit Service |
b3514a |
if (deviceInstance != -1) {
|
|
Packit Service |
b3514a |
printk("%s%s%u:%s: %s%pV%pV\n",
|
|
Packit Service |
b3514a |
level, moduleName, deviceInstance, current->comm,
|
|
Packit Service |
b3514a |
prefix, vaf1, vaf2);
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (((current->flags & PF_KTHREAD) != 0)
|
|
Packit Service |
b3514a |
&& (strncmp(moduleName, current->comm, strlen(moduleName)) == 0)) {
|
|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* It's a kernel thread starting with "kvdo" (or whatever). Assume it's
|
|
Packit Service |
b3514a |
* ours and that its name is sufficient.
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
printk("%s%s: %s%pV%pV\n",
|
|
Packit Service |
b3514a |
level, current->comm,
|
|
Packit Service |
b3514a |
prefix, vaf1, vaf2);
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Identify the module and the process.
|
|
Packit Service |
b3514a |
printk("%s%s: %s: %s%pV%pV\n",
|
|
Packit Service |
b3514a |
level, moduleName, current->comm,
|
|
Packit Service |
b3514a |
prefix, vaf1, vaf2);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logMessagePack(int priority,
|
|
Packit Service |
b3514a |
const char *prefix,
|
|
Packit Service |
b3514a |
const char *fmt1,
|
|
Packit Service |
b3514a |
va_list args1,
|
|
Packit Service |
b3514a |
const char *fmt2,
|
|
Packit Service |
b3514a |
va_list args2)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (priority > getLogLevel()) {
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* The kernel's printk has some magic for indirection to a secondary
|
|
Packit Service |
b3514a |
* va_list. It wants us to supply a pointer to the va_list.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* However, va_list varies across platforms and can be an array
|
|
Packit Service |
b3514a |
* type, which makes passing it around as an argument kind of
|
|
Packit Service |
b3514a |
* tricky, due to the automatic conversion to a pointer. This makes
|
|
Packit Service |
b3514a |
* taking the address of the argument a dicey thing; if we use "&a"
|
|
Packit Service |
b3514a |
* it works fine for non-array types, but for array types we get the
|
|
Packit Service |
b3514a |
* address of a pointer. Functions like va_copy and sprintf don't
|
|
Packit Service |
b3514a |
* care as they get "va_list" values passed and are written to do
|
|
Packit Service |
b3514a |
* the right thing, but printk explicitly wants the address of the
|
|
Packit Service |
b3514a |
* va_list.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* So, we copy the va_list values to ensure that "&" consistently
|
|
Packit Service |
b3514a |
* works the way we want.
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
va_list args1Copy;
|
|
Packit Service |
b3514a |
va_copy(args1Copy, args1);
|
|
Packit Service |
b3514a |
va_list args2Copy;
|
|
Packit Service |
b3514a |
va_copy(args2Copy, args2);
|
|
Packit Service |
b3514a |
struct va_format vaf1 = {
|
|
Packit Service |
b3514a |
.fmt = (fmt1 != NULL) ? fmt1 : "",
|
|
Packit Service |
b3514a |
.va = &args1Copy,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
struct va_format vaf2 = {
|
|
Packit Service |
b3514a |
.fmt = (fmt2 != NULL) ? fmt2 : "",
|
|
Packit Service |
b3514a |
.va = &args2Copy,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (prefix == NULL) {
|
|
Packit Service |
b3514a |
prefix = "";
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
emitLogMessage(priorityToLogLevel(priority), THIS_MODULE->name,
|
|
Packit Service |
b3514a |
prefix, &vaf1, &vaf2);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_end(args1Copy);
|
|
Packit Service |
b3514a |
va_end(args2Copy);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logEmbeddedMessage(int priority,
|
|
Packit Service |
b3514a |
const char *prefix,
|
|
Packit Service |
b3514a |
const char *fmt1,
|
|
Packit Service |
b3514a |
va_list args1,
|
|
Packit Service |
b3514a |
const char *fmt2,
|
|
Packit Service |
b3514a |
...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list ap;
|
|
Packit Service |
b3514a |
va_start(ap, fmt2);
|
|
Packit Service |
b3514a |
logMessagePack(priority, prefix, fmt1, args1, fmt2, ap);
|
|
Packit Service |
b3514a |
va_end(ap);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#pragma GCC diagnostic push
|
|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* GCC (version 8.1.1 20180502 (Red Hat 8.1.1-1)) on Fedora 28 seems
|
|
Packit Service |
b3514a |
* to think that this function should get a printf format
|
|
Packit Service |
b3514a |
* attribute. But we have no second format string, and no additional
|
|
Packit Service |
b3514a |
* arguments at the call site, and GCC also gets unhappy trying to
|
|
Packit Service |
b3514a |
* analyze the format and values when there are none. So we'll just
|
|
Packit Service |
b3514a |
* shut it up.
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Log a message.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This helper function exists solely to create a valid va_list with
|
|
Packit Service |
b3514a |
* no useful info. It does the real work of vLogMessage, which wants a
|
|
Packit Service |
b3514a |
* second va_list object to pass down.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param priority The syslog priority value for the message.
|
|
Packit Service |
b3514a |
* @param format The format of the message (a printf style format)
|
|
Packit Service |
b3514a |
* @param args The variadic argument list of format parameters.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void vLogMessageHelper(int priority,
|
|
Packit Service |
b3514a |
const char *format,
|
|
Packit Service |
b3514a |
va_list args,
|
|
Packit Service |
b3514a |
...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list dummy;
|
|
Packit Service |
b3514a |
va_start(dummy, args);
|
|
Packit Service |
b3514a |
logMessagePack(priority, NULL, format, args, NULL, dummy);
|
|
Packit Service |
b3514a |
va_end(dummy);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
#pragma GCC diagnostic pop
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/*****************************************************************************/
|
|
Packit Service |
b3514a |
void vLogMessage(int priority, const char *format, va_list args)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
vLogMessageHelper(priority, format, args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logMessage(int priority, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(priority, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
__attribute__((format(printf, 2, 3)))
|
|
Packit Service |
b3514a |
static void logAtLevel(int priority, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(priority, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logDebug(const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(LOG_DEBUG, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logInfo(const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(LOG_INFO, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logNotice(const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(LOG_NOTICE, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logWarning(const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(LOG_WARNING, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logError(const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(LOG_ERR, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void vLogError(const char *format, va_list args)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
vLogMessage(LOG_ERR, format, args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logBacktrace(int priority)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
logAtLevel(priority, "[backtrace]");
|
|
Packit Service |
b3514a |
if (priority > logLevel) {
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
dump_stack();
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int vLogWithStringError(int priority,
|
|
Packit Service |
b3514a |
int errnum,
|
|
Packit Service |
b3514a |
const char *format,
|
|
Packit Service |
b3514a |
va_list args)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
char errbuf[ERRBUF_SIZE] = "";
|
|
Packit Service |
b3514a |
logEmbeddedMessage(priority, NULL, format, args, ": %s (%d)",
|
|
Packit Service |
b3514a |
stringError(errnum, errbuf, sizeof(errbuf)),
|
|
Packit Service |
b3514a |
errnum);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logWithStringError(int priority, int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(priority, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logErrorWithStringError(int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_ERR, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int vLogErrorWithStringError(int errnum, const char *format, va_list args)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_ERR, errnum, format, args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logWarningWithStringError(int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_WARNING, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logDebugWithStringError(int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_DEBUG, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logInfoWithStringError(int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_INFO, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logNoticeWithStringError(int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_NOTICE, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logFatalWithStringError(int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_CRIT, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int logUnrecoverable(int errnum, const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if ((errnum == UDS_SUCCESS || errnum == UDS_QUEUED) || (errnum == 0)) {
|
|
Packit Service |
b3514a |
return errnum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogWithStringError(LOG_CRIT, errnum, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
return makeUnrecoverable(errnum);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void logFatal(const char *format, ...)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
va_list args;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
va_start(args, format);
|
|
Packit Service |
b3514a |
vLogMessage(LOG_CRIT, format, args);
|
|
Packit Service |
b3514a |
va_end(args);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void pauseForLogger(void)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
// Hopefully, a few milliseconds of sleep will be large enough
|
|
Packit Service |
b3514a |
// for the kernel log buffer to be flushed.
|
|
Packit Service |
b3514a |
msleep(4);
|
|
Packit Service |
b3514a |
}
|