Commit 04cf3166 authored by Colin Walters's avatar Colin Walters
Browse files

Refactor _dbus_log_info, _dbus_log_security into _dbus_log_system

In preparation for a future patch which introduces a fatal logging level,
don't duplicate the API here.
parent e28c0ece
......@@ -869,10 +869,10 @@ bus_context_reload_config (BusContext *context,
}
ret = TRUE;
bus_context_log_info (context, "Reloaded configuration");
failed:
bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Reloaded configuration");
failed:
if (!ret)
bus_context_log_info (context, "Unable to reload configuration: %s", error->message);
bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Unable to reload configuration: %s", error->message);
if (parser != NULL)
bus_config_parser_unref (parser);
return ret;
......@@ -1154,27 +1154,14 @@ bus_context_get_reply_timeout (BusContext *context)
}
void
bus_context_log_info (BusContext *context, const char *msg, ...)
bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
{
va_list args;
va_start (args, msg);
if (context->syslog)
_dbus_log_info (msg, args);
va_end (args);
}
void
bus_context_log_security (BusContext *context, const char *msg, ...)
{
va_list args;
va_start (args, msg);
if (context->syslog)
_dbus_log_security (msg, args);
_dbus_system_log (severity, msg, args);
va_end (args);
}
......@@ -1418,8 +1405,8 @@ bus_context_check_security_policy (BusContext *context,
dest ? dest : DBUS_SERVICE_DBUS,
proposed_recipient_loginfo);
/* Needs to be duplicated to avoid calling malloc and having to handle OOM */
if (addressed_recipient == proposed_recipient)
bus_context_log_security (context, msg,
if (addressed_recipient == proposed_recipient)
bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
toggles,
dbus_message_type_to_string (dbus_message_get_type (message)),
sender_name ? sender_name : "(unset)",
......@@ -1438,7 +1425,7 @@ bus_context_check_security_policy (BusContext *context,
}
if (log)
bus_context_log_security (context,
bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY,
"Would reject message, %d matched rules; "
"type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))",
toggles,
......@@ -1482,8 +1469,8 @@ bus_context_check_security_policy (BusContext *context,
dest ? dest : DBUS_SERVICE_DBUS,
proposed_recipient_loginfo);
/* Needs to be duplicated to avoid calling malloc and having to handle OOM */
if (addressed_recipient == proposed_recipient)
bus_context_log_security (context, msg,
if (addressed_recipient == proposed_recipient)
bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, msg,
toggles,
dbus_message_type_to_string (dbus_message_get_type (message)),
sender_name ? sender_name : "(unset)",
......
......@@ -107,11 +107,9 @@ int bus_context_get_max_services_per_connection (BusContext
int bus_context_get_max_match_rules_per_connection (BusContext *context);
int bus_context_get_max_replies_per_connection (BusContext *context);
int bus_context_get_reply_timeout (BusContext *context);
void bus_context_log_info (BusContext *context,
const char *msg,
...);
void bus_context_log_security (BusContext *context,
const char *msg,
void bus_context_log (BusContext *context,
DBusSystemLogSeverity severity,
const char *msg,
...);
dbus_bool_t bus_context_check_security_policy (BusContext *context,
BusTransaction *transaction,
......
......@@ -370,31 +370,50 @@ _dbus_init_system_log (void)
{
openlog ("dbus", LOG_PID, LOG_DAEMON);
}
/**
* Log an informative message. Intended for use primarily by
* the system bus.
* Log a message to the system log file (e.g. syslog on Unix).
*
* @param severity a severity value
* @param msg a printf-style format string
* @param args arguments for the format string
*
*/
void
_dbus_log_info (const char *msg, va_list args)
void
_dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
{
vsyslog (LOG_DAEMON|LOG_NOTICE, msg, args);
va_list args;
va_start (args, msg);
_dbus_system_logv (severity, msg, args);
va_end (args);
}
/**
* Log a security-related message. Intended for use primarily by
* the system bus.
* Log a message to the system log file (e.g. syslog on Unix).
*
* @param severity a severity value
* @param msg a printf-style format string
* @param args arguments for the format string
*
*/
void
_dbus_log_security (const char *msg, va_list args)
void
_dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
{
vsyslog (LOG_AUTH|LOG_NOTICE, msg, args);
int flags;
switch (severity)
{
case DBUS_SYSTEM_LOG_INFO:
flags = LOG_DAEMON | LOG_NOTICE;
break;
case DBUS_SYSTEM_LOG_SECURITY:
flags = LOG_AUTH | LOG_NOTICE;
break;
default:
return;
}
vsyslog (flags, msg, args);
}
/** Installs a UNIX signal handler
......
......@@ -439,11 +439,17 @@ dbus_bool_t _dbus_user_at_console (const char *username,
DBusError *error);
void _dbus_init_system_log (void);
void _dbus_log_info (const char *msg, va_list args);
void _dbus_log_security (const char *msg, va_list args);
/* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
* config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
typedef enum {
DBUS_SYSTEM_LOG_INFO,
DBUS_SYSTEM_LOG_SECURITY
} DBusSystemLogSeverity;
void _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...);
void _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args);
/* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
* config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
*/
#if !defined (DBUS_VA_COPY)
# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment