+ if (amanda_log_handlers) {
+ GSList *iter = amanda_log_handlers;
+ while (iter) {
+ amanda_log_handler_t *hdlr = (amanda_log_handler_t *)iter->data;
+ hdlr(maxlevel, message);
+ iter = g_slist_next(iter);
+ }
+ } else {
+ /* call the appropriate handlers, based on the context */
+ amanda_log_stderr(maxlevel, message);
+ if (context == CONTEXT_DAEMON)
+ amanda_log_syslog(maxlevel, message);
+ }
+
+ /* error and critical levels have special handling */
+ if (log_level & (G_LOG_LEVEL_ERROR|G_LOG_LEVEL_CRITICAL)) {
+#ifdef HAVE_GLIBC_BACKTRACE
+ /* try logging a traceback to the debug log */
+ if (!do_suppress_error_traceback && db_fd != -1) {
+ void *stack[32];
+ int naddrs;
+ naddrs = backtrace(stack, sizeof(stack)/sizeof(*stack));
+ backtrace_symbols_fd(stack, naddrs, db_fd);
+ }
+#endif
+
+ /* we're done */
+ if (log_level & G_LOG_LEVEL_CRITICAL)
+ exit(error_exit_status);
+ else
+ abort();
+ g_assert_not_reached();
+ }
+}
+
+/* Install our handler into the glib log handling system.
+ */
+static void
+debug_setup_logging(void)
+{
+ /* g_error and g_critical should be fatal, although the log handler
+ * takes care of this anyway */
+ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
+
+ /* set up handler (g_log_set_default_handler is new in glib-2.6, and
+ * hence not useable here) */
+ g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
+ debug_logging_handler, NULL);
+}
+
+void
+add_amanda_log_handler(amanda_log_handler_t *hdlr)
+{
+ amanda_log_handlers = g_slist_append(amanda_log_handlers, (gpointer)hdlr);
+}
+
+void
+amanda_log_syslog(GLogLevelFlags log_level, const gchar *message)
+{
+ int priority = LOG_ERR;
+ switch (log_level) {
+ case G_LOG_LEVEL_ERROR:
+ case G_LOG_LEVEL_CRITICAL:
+ priority = LOG_ERR;
+ break;
+
+ case G_LOG_LEVEL_WARNING:
+#ifdef LOG_WARNING
+ priority = LOG_WARNING;
+#endif
+ break;
+
+ default:
+ return;
+ }
+
+#ifdef LOG_DAEMON
+ openlog(get_pname(), LOG_PID, LOG_DAEMON);
+#else
+ openlog(get_pname(), LOG_PID, 0);
+#endif
+ syslog(priority, "%s", message);
+ closelog();
+
+}
+
+void
+amanda_log_stderr(GLogLevelFlags log_level, const gchar *message)
+{
+ switch (log_level) {
+ case G_LOG_LEVEL_ERROR:
+ case G_LOG_LEVEL_CRITICAL:
+ g_fprintf(stderr, "%s: %s\n", get_pname(), message);
+ break;
+
+ default:
+ return;
+ }
+}
+
+void
+amanda_log_null(GLogLevelFlags log_level G_GNUC_UNUSED, const gchar *message G_GNUC_UNUSED)
+{
+}
+
+/* Set the global dbgdir according to 'config' and 'subdir'
+ *
+ * The global open_time is set to the current time, and used to delete
+ * old files.
+ *
+ * @param config: configuration or NULL
+ * @param subdir: subdirectory (server, client, etc.) or NULL
+ */
+static void
+debug_setup_1(char *config, char *subdir)
+{
+ char *sane_config = NULL;