summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-03-15 13:50:48 -0400
committerColin Walters <walters@verbum.org>2010-03-16 15:57:05 -0400
commit04cf3166002a86b9a22851be4e243c87b5b3048d (patch)
tree842b2605eb8ff92acd98da7bb991bdcbc42b3467
parente28c0ece17f0cfac1d18527604a67bcba7c3d2cc (diff)
downloaddbus-04cf3166002a86b9a22851be4e243c87b5b3048d.tar.gz
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.
-rw-r--r--bus/bus.c33
-rw-r--r--bus/bus.h8
-rw-r--r--dbus/dbus-sysdeps-util-unix.c41
-rw-r--r--dbus/dbus-sysdeps.h14
4 files changed, 53 insertions, 43 deletions
diff --git a/bus/bus.c b/bus/bus.c
index 6495ae7f..c2e24a89 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -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)",
diff --git a/bus/bus.h b/bus/bus.h
index 62649fd9..8a04daa1 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -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,
diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c
index 74e8d88f..42693817 100644
--- a/dbus/dbus-sysdeps-util-unix.c
+++ b/dbus/dbus-sysdeps-util-unix.c
@@ -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
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 80f0ba26..4011cab4 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -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))