Exemple #1
0
void
tracker_log_shutdown (void)
{
	if (!initialized) {
		return;
	}

	g_message ("Stopping %s %s", g_get_application_name (), PACKAGE_VERSION);

	/* Reset default log handler */
	g_log_set_default_handler (g_log_default_handler, NULL);

	if (log_handler_id) {
		g_log_remove_handler (G_LOG_DOMAIN, log_handler_id);
		log_handler_id = 0;
	}

	if (libmediaart_log_handler_id) {
		g_log_remove_handler ("libmediaart", libmediaart_log_handler_id);
		libmediaart_log_handler_id = 0;
	}

	if (use_log_files && fd != NULL) {
		fclose (fd);
	}

	g_mutex_clear (&mutex);

	initialized = FALSE;
}
Exemple #2
0
void wm_debug_shutdown(void)
{
	g_log_remove_handler("lboxwm_render", rr_handler_id);
	g_log_remove_handler("lboxwm_toolkit", t_handler_id);
	g_log_remove_handler("lboxwm", lboxwm_handler_id);
	if(log_file) {
		fclose(log_file);
		log_file = NULL;
	}
}
Exemple #3
0
void ob_debug_shutdown(void)
{
    g_log_remove_handler("ObRender", rr_handler_id);
    g_log_remove_handler("Obt", obt_handler_id);
    g_log_remove_handler("Openbox", ob_handler_id);
    g_log_remove_handler("Openbox", ob_handler_prompt_id);

    if (log_file) {
        fclose(log_file);
        log_file = NULL;
    }
}
Exemple #4
0
gboolean Logger::remove_log_handler(const gchar* log_domain) {
  auto it = handler_ids_.find(log_domain);
  if (handler_ids_.end() == it) return FALSE;

  g_log_remove_handler(log_domain, handler_ids_[log_domain]);
  return TRUE;
}
Exemple #5
0
static void
VMToolsResetLogging(gboolean hard)
{
   gLogEnabled = FALSE;
   g_log_set_default_handler(g_log_default_handler, NULL);

   CLEAR_LOG_HANDLER(gErrorData);
   gErrorData = NULL;

   if (gDomains != NULL) {
      guint i;
      for (i = 0; i < gDomains->len; i++) {
         LogHandler *data = g_ptr_array_index(gDomains, i);
         g_log_remove_handler(data->domain, data->handlerId);
         data->handlerId = 0;
         if (hard) {
            CLEAR_LOG_HANDLER(data);
         }
      }
      if (hard) {
         g_ptr_array_free(gDomains, TRUE);
         gDomains = NULL;
      }
   }

   if (hard) {
      CLEAR_LOG_HANDLER(gDefaultData);
      gDefaultData = NULL;
   }

   if (gLogDomain != NULL) {
      g_free(gLogDomain);
      gLogDomain = NULL;
   }
}
Exemple #6
0
PyObject *
py_set_debug_log_handler(G_GNUC_UNUSED PyObject *self, PyObject *args)
{
    PyObject *cb, *cb_data = NULL;

    if (!PyArg_ParseTuple(args, "O|O:py_set_debug_log_handler", &cb, &cb_data))
        return NULL;

    if (cb == Py_None)
        cb = NULL;

    if (cb && !PyCallable_Check(cb)) {
        PyErr_SetString(PyExc_TypeError, "parameter must be callable");
        return NULL;
    }

    Py_XDECREF(debug_cb);
    Py_XDECREF(debug_cb_data);

    debug_cb      = cb;
    debug_cb_data = cb_data;

    Py_XINCREF(debug_cb);
    Py_XINCREF(debug_cb_data);

    if (debug_cb) {
        debug_handler_id = g_log_set_handler("librepo", G_LOG_LEVEL_DEBUG,
                                             py_debug_cb, NULL);
        global_logger = 1;
    } else if (debug_handler_id != -1) {
        g_log_remove_handler("librepo", debug_handler_id);
    }

    Py_RETURN_NONE;
}
PHP_METHOD(midgard_connection, __destruct)
{
	if (MGDG(midgard_memory_debug)) {
		php_printf("[%p] midgard_connection::__destruct()\n", getThis());
	}

	MidgardConnection *mgd = __midgard_connection_get_ptr(getThis());
	int loghandler = midgard_connection_get_loghandler(mgd);

	if (loghandler) {
		if (MGDG(midgard_memory_debug)) {
			php_printf("[%p] ---> g_log_remove_handler(..., %d)\n", getThis(), loghandler);
		}

		g_log_remove_handler(G_LOG_DOMAIN, loghandler);

		if (global_loghandler != loghandler && MGDG(midgard_memory_debug)) {
			php_printf("[%p] ---> (?) global_loghandler != connection's handler\n", getThis());
		}

		// still just null it, as it is not valid anyway
		global_loghandler = 0;
		midgard_connection_set_loghandler (mgd, 0);
	}

	MGDG(connection_established) = FALSE;

	if (MGDG(midgard_memory_debug)) {
		php_printf("[%p] <= midgard_connection::__destruct()\n", getThis());
	}
}
static PHP_METHOD(midgard_connection, open)
{
	RETVAL_FALSE;
	char *cnf_name;
	int cnf_name_length;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cnf_name, &cnf_name_length) == FAILURE)
		return;

	MidgardConnection *mgd = __midgard_connection_get_ptr(getThis());
	gboolean rv = midgard_connection_open(mgd, (const gchar *)cnf_name, NULL);

	if (rv) {
		guint loghandler = midgard_connection_get_loghandler(mgd);

		if (loghandler)
			g_log_remove_handler(G_LOG_DOMAIN, loghandler);

		global_loghandler = g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK, php_midgard_log_errors, (gpointer)mgd);
		midgard_connection_set_loghandler(mgd, global_loghandler);

		if (MGDG(midgard_memory_debug)) {
			php_printf("---> global_loghandler = %d\n", global_loghandler);
		}
	}

	RETURN_BOOL(rv);
}
static void
test_num_print_info (gnc_numeric n, GNCPrintAmountInfo print_info, int line)
{
    gnc_numeric n_parsed = gnc_numeric_zero();
    const char *s;
    gboolean ok, print_ok;

    auto msg = "[PrintAmountInternal()] Bad numeric from rounding: GNC_ERROR_OVERFLOW.";
    auto log_domain = "gnc.gui";
    auto loglevel = static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING);
    auto check = test_error_struct_new (log_domain, loglevel, msg);

    /* Throws overflows during rounding step in xaccPrintAmount when the "fraction" is high. See bug 665707. */
    auto hdlr = g_log_set_handler (log_domain, loglevel,
                              (GLogFunc)test_checked_handler, &check);
    s = xaccPrintAmount (n, print_info);
    print_ok = (s && s[0] != '\0');
    if (!print_ok)
        return;

    ok = xaccParseAmount (s, print_info.monetary, &n_parsed, NULL);
    g_log_remove_handler (log_domain, hdlr);


    do_test_args (ok, "parsing failure", __FILE__, __LINE__,
                  "num: %s, string %s (line %d)", gnc_numeric_to_string (n), s, line);

    ok = gnc_numeric_equal (n, n_parsed);
    do_test_args (ok, "not equal", __FILE__, __LINE__,
                  "start: %s, string %s, finish: %s (line %d)",
                  gnc_numeric_to_string (n), s,
                  gnc_numeric_to_string (n_parsed), line);
    test_error_struct_free (check);

}
Exemple #10
0
/* Given a synthetic session, use the same logic as
 * QofSession::save_as to save it to a specified sql url, then load it
 * back and compare. */
void
test_dbi_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url )
{
    QofSession* session_2;
    QofSession* session_3;

    gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
    gchar *log_domain = "gnc.backend.dbi";
    guint loglevel = G_LOG_LEVEL_WARNING, hdlr;
    TestErrorStruct check = { loglevel, log_domain, msg };

    g_test_message ( "Testing %s\n", driver );

    // Save the session data
    session_2 = qof_session_new();
    hdlr = g_log_set_handler (log_domain, loglevel,
			       (GLogFunc)test_checked_handler, &check);
    qof_session_begin( session_2, url, FALSE, TRUE, TRUE );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(session_2), qof_session_get_error_message(session_2));
        do_test( FALSE, "First DB Session Creation Failed");
        return;
    }
    qof_session_swap_data( session_1, session_2 );
    qof_session_save( session_2, NULL );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_2));
        do_test( FALSE, "First DB Session Save Failed");
        return;
    }

    // Reload the session data
    session_3 = qof_session_new();
    qof_session_begin( session_3, url, TRUE, FALSE, FALSE );
    if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_3));
        do_test( FALSE, "Second DB Session Creation Failed");
        return;
    }
    qof_session_load( session_3, NULL );
    if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_3));
        do_test( FALSE, "Second DBI Session Load Failed");
        return;
    }
    // Compare with the original data
    compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
    qof_session_end( session_1 );
    qof_session_destroy( session_1 );
    qof_session_end( session_2 );
    qof_session_destroy( session_2 );
    qof_session_end( session_3 );
    qof_session_destroy( session_3 );
    g_log_remove_handler (log_domain, hdlr);
}
Exemple #11
0
void
ibus_unset_log_handler (void)
{
    if (ibus_log_handler_id != 0) {
        g_log_remove_handler (G_LOG_DOMAIN, ibus_log_handler_id);
        ibus_log_handler_id = 0;
    }
}
Exemple #12
0
void
msg_deinit(void)
{
  evt_ctx_free(evt_context);
  evt_context = NULL;
  log_stderr = TRUE;

  if (g_log_handler_id)
    {
      g_log_remove_handler(G_LOG_DOMAIN, g_log_handler_id);
      g_log_handler_id = 0;
    }
  if (glib_handler_id)
    {
      g_log_remove_handler("GLib", glib_handler_id);
      glib_handler_id = 0;
    }
}
Exemple #13
0
    //_________________________________________________________
    LogHandler::~LogHandler( void )
    {

        if( _gtkLogId > 0 )
        {

            g_log_remove_handler( "Gtk", _gtkLogId );
            g_log_set_handler( "Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, 0L );

        }

        if( _glibLogId > 0 )
        {

            g_log_remove_handler( "GLib-GObject", _glibLogId );
            g_log_set_handler( "GLib-GObject", G_LOG_LEVEL_CRITICAL, g_log_default_handler, 0L );

        }

    }
Exemple #14
0
void Messages::releaseLogMessages()
{
    if ( handlerDefault ) {
        g_log_remove_handler(NULL, handlerDefault);
        handlerDefault = 0;
    }
    if ( handlerGlibmm ) {
        g_log_remove_handler("glibmm", handlerGlibmm);
        handlerGlibmm = 0;
    }
    if ( handlerAtkmm ) {
        g_log_remove_handler("atkmm", handlerAtkmm);
        handlerAtkmm = 0;
    }
    if ( handlerPangomm ) {
        g_log_remove_handler("pangomm", handlerPangomm);
        handlerPangomm = 0;
    }
    if ( handlerGdkmm ) {
        g_log_remove_handler("gdkmm", handlerGdkmm);
        handlerGdkmm = 0;
    }
    if ( handlerGtkmm ) {
        g_log_remove_handler("gtkmm", handlerGtkmm);
        handlerGtkmm = 0;
    }
    message(_("Log capture stopped."));
}
Exemple #15
0
void DebugDialogImpl::releaseLogMessages()
{
    if ( handlerDefault ) {
        g_log_remove_handler(NULL, handlerDefault);
        handlerDefault = 0;
    }
    if ( handlerGlibmm ) {
        g_log_remove_handler("glibmm", handlerGlibmm);
        handlerGlibmm = 0;
    }
    if ( handlerAtkmm ) {
        g_log_remove_handler("atkmm", handlerAtkmm);
        handlerAtkmm = 0;
    }
    if ( handlerPangomm ) {
        g_log_remove_handler("pangomm", handlerPangomm);
        handlerPangomm = 0;
    }
    if ( handlerGdkmm ) {
        g_log_remove_handler("gdkmm", handlerGdkmm);
        handlerGdkmm = 0;
    }
    if ( handlerGtkmm ) {
        g_log_remove_handler("gtkmm", handlerGtkmm);
        handlerGtkmm = 0;
    }
    message("log capture discontinued");
}
/* Object constructor */
PHP_METHOD(midgard_connection, __construct)
{
	MidgardConnection *mgd = NULL;

	if (MGDG(midgard_memory_debug)) {
		php_printf("[%p] midgard_connection::__construct()\n", getThis());
	}

	if (zend_parse_parameters_none() == FAILURE)
		return;

	if (MGDG(midgard_http)) {
		/* trying to reuse saved connection */
		mgd = php_midgard_handle_lookup(&MGDG(midgard_global_holder), MGDG(all_configs) TSRMLS_CC);

		if (mgd == NULL) {
			/* @todo throw exception, instead */
			php_error(E_ERROR, "Midgard handle-lookup failed (could not connect to database)");
			return;
		}
	} else {
		mgd = midgard_connection_new();
		if (mgd == NULL) {
			/* @todo throw exception, instead */
			php_error(E_ERROR, "Failed to create underlying GObject instance");
			return;
		}
	}

	if (global_loghandler) {
		if (MGDG(midgard_memory_debug)) {
			php_printf("---> g_log_remove_handler(..., %d)\n", global_loghandler);
		}
		g_log_remove_handler(G_LOG_DOMAIN, global_loghandler);
	}

	// midgard_connection_set_loglevel(mgd, "warning", NULL);
	global_loghandler = midgard_connection_get_loghandler(mgd);
	if (MGDG(midgard_memory_debug)) {
		php_printf("---> global_loghandler = %d\n", global_loghandler);
	}

	/* storing midgard_connection in object's store-structure */
	MGD_PHP_SET_GOBJECT(getThis(), mgd);

	// explicitly enable replication (to stay compatible with mjölnir)
	midgard_connection_enable_replication(mgd, TRUE);

	if (MGDG(midgard_memory_debug)) {
		php_printf("[%p] <= midgard_connection::__construct()\n", getThis());
	}
}
void
cockpit_polkit_agent_unregister (gpointer handle)
{
  guint handler = 0;

  /* Everything is shutting down at this point, prevent polkit from complaining */
  handler = g_log_set_handler (NULL, G_LOG_LEVEL_WARNING, cockpit_null_log_handler, NULL);

  if (handle)
    polkit_agent_listener_unregister (handle);

  g_log_remove_handler (NULL, handler);
}
Exemple #18
0
void
ibus_set_log_handler (gboolean verbose)
{
    if (ibus_log_handler_id != 0) {
        g_log_remove_handler (G_LOG_DOMAIN, ibus_log_handler_id);
    }

    ibus_log_handler_is_verbose = verbose;
    ibus_log_handler_id = g_log_set_handler (G_LOG_DOMAIN,
                                             G_LOG_LEVEL_MASK,
                                             ibus_log_handler,
                                             NULL);
}
Exemple #19
0
gint display_properties_dbox(const char *filename)
{
	GtkBuilder *builder;
	GtkWidget *dbox;
	GtkWidget *text;
	GError* error = NULL;
	gint result;
	guint hid;

	builder = gtk_builder_new();
	if (!gtk_builder_add_from_file (builder, tilp_paths_build_builder("manpage.ui"), &error))
	{
		g_warning (_("Couldn't load builder file: %s\n"), error->message);
		g_error_free (error);
		return NULL; // THIS RETURNS !
	}
	gtk_builder_connect_signals(builder, NULL);

	dbox = gtk_builder_get_object(builder, "manpage_dbox");
	text = gtk_builder_get_object(builder, "textview1");
	txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));

	hid = g_log_set_handler("tifiles", G_LOG_LEVEL_INFO, new_log_handler, NULL);
	tifiles_file_display(filename);	
	g_log_remove_handler("tifiles", hid);

	{
		PangoFontDescription *font_desc;
		GtkWidget *view = text;

		font_desc = pango_font_description_from_string ("Courier");
		gtk_widget_modify_font (view, font_desc);
		pango_font_description_free (font_desc);
	}

	gtk_window_set_title(GTK_WINDOW(dbox), g_basename(filename));
	gtk_widget_show(dbox);

	result = gtk_dialog_run(GTK_DIALOG(dbox));
	switch (result) 
	{
	case GTK_RESPONSE_OK:
		break;
	default:
		break;
	}

	gtk_widget_destroy(dbox);

	return 0;
}
Exemple #20
0
bool Logger::init() {
  if (installed_) {
    g_warning("Only one logger instance is possible, cannot create");
    return false;
  } else {
    installed_ = true;
    i_am_the_one_ = true;
  }

  guint quiet_handler_id =
      g_log_set_handler("GLib-GObject", G_LOG_LEVEL_MASK, quiet_log_handler, nullptr);

  // handler must be installed after custom property creation
  handler_ids_["switcher"] = g_log_set_handler("switcher", G_LOG_LEVEL_MASK, log_handler, this);

  g_log_remove_handler("GLib-GObject", quiet_handler_id);

  install_method(
      "Install Log Handler",
      "install_log_handler",
      "make the logger managing the log domain",
      "success or fail",
      Method::make_arg_description("LogDomain",
                                   "log domain",
                                   "the glib log domain (e.g. shmdata, Glib or GStreamer)",
                                   nullptr),
      (Method::method_ptr)&install_log_handler_wrapped,
      G_TYPE_BOOLEAN,
      Method::make_arg_type_description(G_TYPE_STRING, nullptr),
      this);

  install_method(
      "Remove Log Handler",
      "remove_log_handler",
      "make the logger stop managing the log domain",
      "success or fail",
      Method::make_arg_description("Log Domain",
                                   "log domain",
                                   "the glib log domain (e.g. shmdata, Glib or GStreamer)",
                                   nullptr),
      (Method::method_ptr)&remove_log_handler_wrapped,
      G_TYPE_BOOLEAN,
      Method::make_arg_type_description(G_TYPE_STRING, nullptr),
      this);

  return true;
}
void
milter_manager_quit (void)
{
    if (!initialized)
        return;

    if (the_manager) {
        g_object_unref(the_manager);
        the_manager = NULL;
    }

    _milter_manager_configuration_quit();

    g_log_remove_handler("milter-manager", milter_manager_log_handler_id);
    milter_server_quit();
    milter_client_quit();
    milter_quit();
}
Exemple #22
0
static gboolean
test_case_destroy (TestCase *test,
                   GError  **error)
{
  /* Failures when cleaning up the test case aren't recoverable, since we'll
   * pollute the subsequent test cases, so we just return the error, and
   * skip the rest of the cleanup.
   */
  GHashTableIter iter;
  gpointer key, value;

  g_hash_table_iter_init (&iter, test->clients);
  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      if (!test_client_do (value, error, "destroy_all", NULL))
        return FALSE;

    }

  if (!test_case_wait (test, error))
    return FALSE;

  if (!test_case_assert_stacking (test, NULL, 0, error))
    return FALSE;

  if (!test_case_check_warnings (test, error))
    return FALSE;

  g_hash_table_iter_init (&iter, test->clients);
  while (g_hash_table_iter_next (&iter, &key, &value))
    test_client_destroy (value);

  async_waiter_destroy (test->waiter);

  meta_display_set_alarm_filter (meta_get_display (), NULL, NULL);

  g_hash_table_destroy (test->clients);
  g_free (test);

  g_log_remove_handler ("mutter", test->log_handler_id);

  return TRUE;
}
static void _midgard_connection_finalize(GObject *object)
{
	g_assert(object != NULL);
	MidgardConnection *self = (MidgardConnection *) object;

	if (self->err != NULL)
		g_clear_error(&self->err);

	if (self->errstr != NULL) {
		g_free(self->errstr);
		self->errstr = NULL;
	}

	if (self->priv->authstack) {
		g_slist_free(self->priv->authstack);
		self->priv->authstack = NULL;
	}

	g_free ((gchar *)self->priv->cnc_str);
	self->priv->cnc_str = NULL;

	g_timer_stop(self->priv->timer);
	//gdouble bench = g_timer_elapsed(self->priv->timer, NULL);

	if (self->priv->loghandler) {
		/* uptime message disable for a while */
		/* g_message("MidgardConnection uptime %.04f seconds", bench); */
		g_log_remove_handler(G_LOG_DOMAIN, self->priv->loghandler);
	}

	g_timer_destroy(self->priv->timer);

	if (!self->priv->inherited) {
		if (self->priv->config && G_IS_OBJECT (self->priv->config)) {
			g_object_unref(self->priv->config);
			self->priv->config = NULL;
		}
	}

	g_free(self->priv);
	self->priv = NULL;
}
void
test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url )
{
    QofSession* session_2;
    QofSession* session_3;

    gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
    gchar *log_domain = "gnc.backend.dbi";
    guint loglevel = G_LOG_LEVEL_WARNING, hdlr;
    TestErrorStruct check = { loglevel, log_domain, msg };

    g_test_message ( "Testing %s\n", driver );

    // Save the session data
    session_2 = qof_session_new();
    qof_session_begin( session_2, url, FALSE, TRUE, TRUE );
    qof_session_swap_data( session_1, session_2 );
    qof_session_save( session_2, NULL );

    // Reload the session data
    session_3 = qof_session_new();
    qof_session_begin( session_3, url, TRUE, FALSE, FALSE );
    qof_session_load( session_3, NULL );

    // Compare with the original data
    compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
    qof_session_end( session_1 );
    qof_session_destroy( session_1 );
    qof_session_end( session_2 );
    qof_session_destroy( session_2 );

    hdlr = g_log_set_handler (log_domain, loglevel,
			      (GLogFunc)test_checked_handler, &check);
    qof_session_end( session_3 );
    g_log_remove_handler (log_domain, hdlr);
    qof_session_destroy( session_3 );
}
/**
 * midgard_connection_set_loglevel:
 * @self: #MidgardConnection instance
 * @level: Loglevel string
 * @log_func: log handler function
 *
 * Sets log level of the given MidgardConnection.
 * Overwrites internal #MidgardConnection's log level defined in configuration file. 
 * By default MidgardConnection holds loglevel which is associated with ( and duplicated 
 * from ) #MidgardConfig. 
 * #MidgardConfig object's log level isn't changed by this function
 *
 * This method is a shortcut which sets correctly loghandler,loglevel
   and GLib's log function. Default log function will be used if %NULL 
 * is defined. Core's default function is #midgard_error_default_log.
 * 
 * Available levels: error, warn, warning, info, message, debug.
 * warn is default loglevel, SQL queries are logged with debug level.
 * With info level, function names ( and classes' names ) are ( at least should be) logged in language bindings
 *
 * Returns: %TRUE if debug level is set, %FALSE otherwise
 */
gboolean midgard_connection_set_loglevel(
		MidgardConnection *self, const gchar *level, GLogFunc log_func)
{
	g_assert(self != NULL);

	GLogFunc _func = log_func;
	if(_func == NULL)
		_func = midgard_error_default_log;

	gint loglevel = 
		midgard_error_parse_loglevel(level);

	if(loglevel > -1)
		self->priv->loglevel = loglevel;
	else
		return FALSE;

	MGD_CNC_DEBUG (self) = FALSE;

	if (loglevel > G_LOG_LEVEL_DEBUG)
		MGD_CNC_DEBUG (self) = TRUE;

	guint loghandler = midgard_connection_get_loghandler(self);
	if(loghandler)
		g_log_remove_handler(G_LOG_DOMAIN, loghandler);

	loghandler = g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK,
			_func, (gpointer)self);
	
	if(loghandler == 0)
		return FALSE;

	midgard_connection_set_loghandler(self, loghandler);

	return TRUE;
}
Exemple #26
0
/* Given an already-created url (yeah, bad testing practice: Should
 * start fresh from a synthetic session) load and safe-save it, then
 * load it again into a new session and compare the two. Since
 * safe-save is a more-or-less atomic function call, there's no way to
 * be sure that it's actually doing what it's supposed to without
 * running this test in a debugger and stopping in the middle of the
 * safe-save and inspecting the database. */
void
test_dbi_safe_save( const gchar* driver,  const gchar* url )
{
    QofSession *session_1 = NULL, *session_2 = NULL;

    gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
    gchar *log_domain = "gnc.backend.dbi";
    guint loglevel = G_LOG_LEVEL_WARNING, hdlr;
    TestErrorStruct check = { loglevel, log_domain, msg };

    g_test_message ( "Testing safe save %s\n", driver );

    // Load the session data
    session_1 = qof_session_new();
    qof_session_begin( session_1, url, TRUE, FALSE, FALSE );
    if (session_1 && qof_session_get_error(session_1) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(session_1),
                  qof_session_get_error_message(session_1));
        do_test( FALSE, "DB Session Creation Failed");
        goto cleanup;
    }
    qof_session_load( session_1, NULL );
    /* Do a safe save */
    qof_session_safe_save( session_1, NULL );
    if (session_1 && qof_session_get_error(session_1) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_1));
        do_test( FALSE, "DB Session Safe Save Failed");
        goto cleanup;
    }
    /* Destroy the session and reload it */

    session_2 = qof_session_new();
    qof_session_begin( session_2, url, TRUE, FALSE, FALSE );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(session_2),
                  qof_session_get_error_message(session_2));
        do_test( FALSE, "DB Session re-creation Failed");
        goto cleanup;
    }
    qof_session_load( session_2, NULL );
    compare_books( qof_session_get_book( session_1 ),
                   qof_session_get_book( session_2 ) );

cleanup:
    hdlr = g_log_set_handler (log_domain, loglevel,
			       (GLogFunc)test_checked_handler, &check);
    if (session_2 != NULL)
    {
        qof_session_end( session_2 );
        qof_session_destroy( session_2 );
    }
    if (session_1 != NULL)
    {
        qof_session_end( session_1 );
        qof_session_destroy( session_1 );
    }
    g_log_remove_handler (log_domain, hdlr);
    return;
}
gpointer
cockpit_polkit_agent_register (CockpitTransport *transport,
                               GCancellable *cancellable)
{
  PolkitAgentListener *listener = NULL;
  PolkitAuthority *authority = NULL;
  PolkitSubject *subject = NULL;
  GVariant *options;
  GLogLevelFlags fatal;
  GError *error = NULL;
  gpointer handle = NULL;
  guint handler = 0;
  gchar *string;

  authority = polkit_authority_get_sync (cancellable, &error);
  if (authority == NULL)
    {
      g_message ("couldn't get polkit authority: %s", error->message);
      goto out;
    }

  subject = polkit_unix_session_new_for_process_sync (getpid (), cancellable, &error);
  if (subject == NULL)
    {
      /*
       * This can happen if there's a race between the polkit request and closing of
       * Cockpit. So it's not unheard of. We can complain, but not too loudly.
       */
      g_message ("couldn't create polkit session subject: %s", error->message);
      goto out;
    }

  listener = g_object_new (COCKPIT_TYPE_POLKIT_AGENT,
                           "transport", transport,
                           NULL);
  options = NULL;

  /*
   * HACK: Work around polkitagent warning:
   *
   * https://bugs.freedesktop.org/show_bug.cgi?id=78193
   */

  fatal = g_log_set_always_fatal (0);
  handler = g_log_set_handler (NULL, G_LOG_LEVEL_WARNING, cockpit_null_log_handler, NULL);

  handle = polkit_agent_listener_register_with_options (listener,
                                                        POLKIT_AGENT_REGISTER_FLAGS_NONE,
                                                        subject, NULL, options, cancellable, &error);

  g_log_set_always_fatal (fatal);
  g_log_remove_handler (NULL, handler);

  if (error != NULL)
    {
      if ((g_error_matches (error, POLKIT_ERROR, POLKIT_ERROR_FAILED) &&
           error->message && strstr (error->message, "already exists")) ||
          g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN))
        {
          g_debug ("couldn't register polkit agent: %s", error->message);
        }
      else
        {
          g_dbus_error_strip_remote_error (error);
          g_message ("couldn't register polkit authentication agent: %s", error->message);
        }
      goto out;
    }

  string = polkit_subject_to_string (subject);

  g_debug ("registered polkit authentication agent for subject: %s", string);
  g_free (string);

out:
  if (subject)
    g_object_unref (subject);
  if (authority)
    g_object_unref (authority);
  if (listener)
    g_object_unref (listener);
  g_clear_error (&error);
  return handle;
}
Exemple #28
0
Logger::~Logger() {
  if (i_am_the_one_) {
    for (auto& it : handler_ids_) g_log_remove_handler(it.first.c_str(), it.second);
    installed_ = false;
  }
}
Exemple #29
0
void
debug_logger_remove_domain(DebugLogger *logger,
                           const gchar *domain_name)
{
    GSList *entry;
    gint i, num_pages;

    g_return_if_fail(IS_DEBUG_LOGGER(logger));

    if(!domain_name)
        return;

    for(entry = logger->priv->domains; entry != NULL; entry = g_slist_next(entry))
    {
        DomainHandler *handler = entry->data;

        if(strcmp( domain_name, handler->name ) == 0)
        {
            g_log_remove_handler(
                    (handler->default_domain) ? NULL : handler->name,
                    handler->handler_id);

            if(logger->ui_enabled)
            {
                num_pages = gtk_notebook_get_n_pages(logger->priv->notebook);
                for(i = 0; i < num_pages; ++i)
                {
                    GtkWidget *current_page =
                        gtk_notebook_get_nth_page(logger->priv->notebook, i);
                    GtkWidget *box = gtk_notebook_get_tab_label(logger->priv->notebook,
                            current_page);
                    GList *list = gtk_container_get_children(GTK_CONTAINER(box));
                    GtkLabel *label = GTK_LABEL(list->next->data);

                    g_list_free(list);

                    if( strcmp(domain_name, gtk_label_get_text(label)) == 0)
                    {
                        gtk_notebook_remove_page(logger->priv->notebook, i);
                        break;
                    }
                }
            }

            if(handler->name)
                g_free(handler->name);

            if(handler)
                g_free(handler);

            logger->priv->domains = g_slist_remove(logger->priv->domains, handler);
        }
    }

    if(logger->ui_enabled)
    {
        if(gtk_notebook_get_n_pages(logger->priv->notebook) == 0)
        {
            gtk_widget_set_sensitive(logger->priv->toolbar_save, FALSE);
            gtk_widget_set_sensitive(logger->priv->toolbar_copy, FALSE);
            gtk_widget_set_sensitive(logger->priv->toolbar_select, FALSE);
            gtk_widget_set_sensitive(logger->priv->toolbar_clear, FALSE);
        }
    }
}
gint
tracker_control_general_run (void)
{
	GError *error = NULL;
	GSList *pids;
	GSList *l;
	gchar *str;
	gpointer verbosity_type_enum_class_pointer = NULL;
	TrackerVerbosity set_log_verbosity_value = TRACKER_VERBOSITY_ERRORS;

	/* Constraints */

	if (kill_option != TERM_NONE && terminate_option != TERM_NONE) {
		g_printerr ("%s\n",
		            _("You can not use the --kill and --terminate arguments together"));
		return EXIT_FAILURE;
	}

	if ((hard_reset || soft_reset) && terminate_option != TERM_NONE) {
		g_printerr ("%s\n",
		            _("You can not use the --terminate with --hard-reset or --soft-reset, --kill is implied"));
		return EXIT_FAILURE;
	}

	if (hard_reset && soft_reset) {
		g_printerr ("%s\n",
		            _("You can not use the --hard-reset and --soft-reset arguments together"));
		return EXIT_FAILURE;
	}

	if (get_log_verbosity && set_log_verbosity) {
		g_printerr ("%s\n",
		            _("You can not use the --get-logging and --set-logging arguments together"));
		return EXIT_FAILURE;
	}

	if (set_log_verbosity) {
		if (g_ascii_strcasecmp (set_log_verbosity, "debug") == 0) {
			set_log_verbosity_value = TRACKER_VERBOSITY_DEBUG;
		} else if (g_ascii_strcasecmp (set_log_verbosity, "detailed") == 0) {
			set_log_verbosity_value = TRACKER_VERBOSITY_DETAILED;
		} else if (g_ascii_strcasecmp (set_log_verbosity, "minimal") == 0) {
			set_log_verbosity_value = TRACKER_VERBOSITY_MINIMAL;
		} else if (g_ascii_strcasecmp (set_log_verbosity, "errors") == 0) {
			set_log_verbosity_value = TRACKER_VERBOSITY_ERRORS;
		} else {
			g_printerr ("%s\n",
			            _("Invalid log verbosity, try 'debug', 'detailed', 'minimal' or 'errors'"));
			return EXIT_FAILURE;
		}
	}

	if (hard_reset || soft_reset) {
		/* Imply --kill */
		kill_option = TERM_ALL;
	}

	if (get_log_verbosity || set_log_verbosity) {
		GType etype;

		/* Since we don't reference this enum anywhere, we do
		 * it here to make sure it exists when we call
		 * g_type_class_peek(). This wouldn't be necessary if
		 * it was a param in a GObject for example.
		 *
		 * This does mean that we are leaking by 1 reference
		 * here and should clean it up, but it doesn't grow so
		 * this is acceptable.
		 */
		etype = tracker_verbosity_get_type ();
		verbosity_type_enum_class_pointer = g_type_class_ref (etype);
	}

	/* Unless we are stopping processes or listing processes,
	 * don't iterate them.
	 */
	if (kill_option != TERM_NONE ||
	    terminate_option != TERM_NONE ||
	    list_processes) {
		guint32 own_pid;
		guint32 own_uid;
		gchar *own_pid_str;

		pids = get_pids ();
		str = g_strdup_printf (g_dngettext (NULL,
		                                    "Found %d PID…",
		                                    "Found %d PIDs…",
		                                    g_slist_length (pids)),
		                       g_slist_length (pids));
		g_print ("%s\n", str);
		g_free (str);

		/* Establish own uid/pid */
		own_pid = (guint32) getpid ();
		own_pid_str = g_strdup_printf ("%d", own_pid);
		own_uid = get_uid_for_pid (own_pid_str, NULL);
		g_free (own_pid_str);

		for (l = pids; l; l = l->next) {
			GError *error = NULL;
			gchar *filename;
			gchar *contents = NULL;
			gchar **strv;
			guint uid;

			uid = get_uid_for_pid (l->data, &filename);

			/* Stat the file and make sure current user == file owner */
			if (uid != own_uid) {
				continue;
			}

			/* Get contents to determine basename */
			if (!g_file_get_contents (filename, &contents, NULL, &error)) {
				str = g_strdup_printf (_("Could not open '%s'"), filename);
				g_printerr ("%s, %s\n",
				            str,
				            error ? error->message : _("no error given"));
				g_free (str);
				g_clear_error (&error);
				g_free (contents);
				g_free (filename);

				continue;
			}

			strv = g_strsplit (contents, "^@", 2);
			if (strv && strv[0]) {
				gchar *basename;

				basename = g_path_get_basename (strv[0]);

				if ((g_str_has_prefix (basename, "tracker") == TRUE ||
				     g_str_has_prefix (basename, "lt-tracker") == TRUE) &&
				    g_str_has_suffix (basename, "-control") == FALSE &&
				    g_str_has_suffix (basename, "-status-icon") == FALSE) {
					pid_t pid;

					pid = atoi (l->data);
					str = g_strdup_printf (_("Found process ID %d for '%s'"), pid, basename);
					g_print ("%s\n", str);
					g_free (str);

					if (terminate_option != TERM_NONE) {
						if ((terminate_option == TERM_STORE &&
						     !g_str_has_suffix (basename, "tracker-store")) ||
						    (terminate_option == TERM_MINERS &&
						     !strstr (basename, "tracker-miner"))) {
							continue;
						}

						if (kill (pid, SIGTERM) == -1) {
							const gchar *errstr = g_strerror (errno);

							str = g_strdup_printf (_("Could not terminate process %d"), pid);
							g_printerr ("  %s, %s\n",
							            str,
							            errstr ? errstr : _("no error given"));
							g_free (str);
						} else {
							str = g_strdup_printf (_("Terminated process %d"), pid);
							g_print ("  %s\n", str);
							g_free (str);
						}
					} else if (kill_option != TERM_NONE) {
						if ((kill_option == TERM_STORE &&
						     !g_str_has_suffix (basename, "tracker-store")) ||
						    (kill_option == TERM_MINERS &&
						     !strstr (basename, "tracker-miner"))) {
							continue;
						}

						if (kill (pid, SIGKILL) == -1) {
							const gchar *errstr = g_strerror (errno);

							str = g_strdup_printf (_("Could not kill process %d"), pid);
							g_printerr ("  %s, %s\n",
							            str,
							            errstr ? errstr : _("no error given"));
							g_free (str);
						} else {
							str = g_strdup_printf (_("Killed process %d"), pid);
							g_print ("  %s\n", str);
							g_free (str);
						}
					}
				}

				g_free (basename);
			}

			g_strfreev (strv);
			g_free (contents);
			g_free (filename);
		}

		g_slist_foreach (pids, (GFunc) g_free, NULL);
		g_slist_free (pids);

		/* If we just wanted to list processes, all done */
		if (list_processes &&
		    terminate_option == TERM_NONE &&
		    kill_option == TERM_NONE) {
			return EXIT_SUCCESS;
		}
	}

	if (hard_reset || soft_reset) {
		guint log_handler_id;
#ifndef DISABLE_JOURNAL
		gchar *rotate_to;
		TrackerDBConfig *db_config;
		gsize chunk_size;
		gint chunk_size_mb;
#endif /* DISABLE_JOURNAL */

		/* Set log handler for library messages */
		log_handler_id = g_log_set_handler (NULL,
		                                    G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL,
		                                    log_handler,
		                                    NULL);

		g_log_set_default_handler (log_handler, NULL);

#ifndef DISABLE_JOURNAL
		db_config = tracker_db_config_new ();

		chunk_size_mb = tracker_db_config_get_journal_chunk_size (db_config);
		chunk_size = (gsize) ((gsize) chunk_size_mb * (gsize) 1024 * (gsize) 1024);
		rotate_to = tracker_db_config_get_journal_rotate_destination (db_config);

		/* This call is needed to set the journal's filename */
		tracker_db_journal_set_rotating ((chunk_size_mb != -1),
		                                 chunk_size, rotate_to);

		g_free (rotate_to);
		g_object_unref (db_config);

#endif /* DISABLE_JOURNAL */

		/* Clean up (select_cache_size and update_cache_size don't matter here) */
		if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL,
		                              NULL,
		                              FALSE,
		                              FALSE,
		                              100,
		                              100,
		                              NULL,
		                              NULL,
		                              NULL,
		                              &error)) {

			g_message ("Error initializing database: %s", error->message);
			g_free (error);

			return EXIT_FAILURE;
		}
#ifndef DISABLE_JOURNAL
		tracker_db_journal_init (NULL, FALSE, NULL);
#endif /* DISABLE_JOURNAL */

		tracker_db_manager_remove_all (hard_reset);
		tracker_db_manager_shutdown ();
#ifndef DISABLE_JOURNAL
		tracker_db_journal_shutdown (NULL);
#endif /* DISABLE_JOURNAL */

		/* Unset log handler */
		g_log_remove_handler (NULL, log_handler_id);
	}

	if (remove_config) {
		GMainLoop *main_loop;
		GFile *file;
		TrackerCrawler *crawler;
		const gchar *suffix = ".cfg";
		const gchar *home_conf_dir;
		gchar *path;
		GSList *all, *l;

		crawler = tracker_crawler_new ();
		main_loop = g_main_loop_new (NULL, FALSE);

		g_signal_connect (crawler, "check-file",
		                  G_CALLBACK (crawler_check_file_cb),
		                  &suffix);
		g_signal_connect (crawler, "finished",
		                  G_CALLBACK (crawler_finished_cb),
		                  main_loop);

		/* Go through service files */

		/* Check the default XDG_DATA_HOME location */
		home_conf_dir = g_getenv ("XDG_CONFIG_HOME");

		if (home_conf_dir && tracker_path_has_write_access_or_was_created (home_conf_dir)) {
			path = g_build_path (G_DIR_SEPARATOR_S, home_conf_dir, "tracker", NULL);
		} else {
			home_conf_dir = g_getenv ("HOME");

			if (!home_conf_dir || !tracker_path_has_write_access_or_was_created (home_conf_dir)) {
				home_conf_dir = g_get_home_dir ();
			}
			path = g_build_path (G_DIR_SEPARATOR_S, home_conf_dir, ".config", "tracker", NULL);
		}

		file = g_file_new_for_path (path);
		g_free (path);

		g_print ("%s\n", _("Removing configuration files…"));

		tracker_crawler_start (crawler, file, FALSE);
		g_object_unref (file);

		g_main_loop_run (main_loop);
		g_object_unref (crawler);

		g_print ("%s\n", _("Resetting existing configuration…"));

		all = tracker_gsettings_get_all (NULL);

		if (!all) {
			return EXIT_FAILURE;
		}

		for (l = all; l; l = l->next) {
			ComponentGSettings *c = l->data;
			gchar **keys, **p;

			if (!c) {
				continue;
			}

			g_print ("  %s\n", c->name);

			keys = g_settings_list_keys (c->settings);
			for (p = keys; p && *p; p++) {
				g_print ("    %s\n", *p);
				g_settings_reset (c->settings, *p);
			}

			if (keys) {
				g_strfreev (keys);
			}

			g_settings_apply (c->settings);
		}

		tracker_gsettings_free (all);
	}

	/* Deal with logging changes AFTER the config may have been
	 * reset, this way users can actually use --remove-config with
	 * the --set-logging switch.
	 */
	if (get_log_verbosity) {
		GSList *all;
		gint longest = 0;

		all = tracker_gsettings_get_all (&longest);

		if (!all) {
			return EXIT_FAILURE;
		}

		g_print ("%s:\n", _("Components"));
		tracker_gsettings_print_verbosity (all, longest, TRUE);
		g_print ("\n");

		/* Miners */
		g_print ("%s (%s):\n",
		         _("Miners"),
		         _("Only those with config listed"));
		tracker_gsettings_print_verbosity (all, longest, FALSE);
		g_print ("\n");

		tracker_gsettings_free (all);
	}

	if (set_log_verbosity) {
		GSList *all;
		gchar *str;
		gint longest = 0;

		all = tracker_gsettings_get_all (&longest);

		if (!all) {
			return EXIT_FAILURE;
		}

		str = g_strdup_printf (_("Setting log verbosity for all components to '%s'…"), set_log_verbosity);
		g_print ("%s\n", str);
		g_print ("\n");
		g_free (str);

		tracker_gsettings_set_all (all, set_log_verbosity_value);
		tracker_gsettings_free (all);

		/* We free to make sure we get new settings and that
		 * they're saved properly.
		 */
		all = tracker_gsettings_get_all (&longest);

		if (!all) {
			return EXIT_FAILURE;
		}

		g_print ("%s:\n", _("Components"));
		tracker_gsettings_print_verbosity (all, longest, TRUE);
		g_print ("\n");

		/* Miners */
		g_print ("%s (%s):\n",
		         _("Miners"),
		         _("Only those with config listed"));
		tracker_gsettings_print_verbosity (all, longest, FALSE);
		g_print ("\n");

		tracker_gsettings_free (all);
	}

	if (verbosity_type_enum_class_pointer) {
		g_type_class_unref (verbosity_type_enum_class_pointer);
	}

	if (start) {
		TrackerMinerManager *manager;
		GSList *miners, *l;

		if (hard_reset || soft_reset) {
			g_print ("%s\n", _("Waiting one second before starting miners…"));

			/* Give a second's grace to avoid race conditions */
			g_usleep (G_USEC_PER_SEC);
		}

		g_print ("%s\n", _("Starting miners…"));


		/* Auto-start the miners here */
		manager = tracker_miner_manager_new_full (TRUE, &error);
		if (!manager) {
			g_printerr (_("Could not start miners, manager could not be created, %s"),
			            error ? error->message : "unknown error");
			g_printerr ("\n");
			g_clear_error (&error);
			return EXIT_FAILURE;
		}

		miners = tracker_miner_manager_get_available (manager);

		/* Get the status of all miners, this will start all
		 * miners not already running.
		 */
		for (l = miners; l; l = l->next) {
			const gchar *display_name;
			gdouble progress = 0.0;

			display_name = tracker_miner_manager_get_display_name (manager, l->data);

			if (!tracker_miner_manager_get_status (manager,
			                                       l->data,
			                                       NULL,
			                                       &progress,
			                                       NULL)) {
				g_printerr ("  ✗ %s (%s)\n",
				            display_name,
				            _("perhaps a disabled plugin?"));
			} else {
				g_print ("  ✓ %s\n",
				         display_name);
			}

			g_free (l->data);
		}

		g_slist_free (miners);
		g_object_unref (manager);
	}

	if (backup) {
		GDBusConnection *connection;
		GDBusProxy *proxy;
		GError *error = NULL;
		GVariant *v;
		gchar *uri;

		uri = get_uri_from_arg (backup);

		g_print ("%s\n", _("Backing up database"));
		g_print ("  %s\n", uri);

		connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);

		if (!connection) {
			g_critical ("Could not connect to the D-Bus session bus, %s",
			            error ? error->message : "no error given.");
			g_clear_error (&error);
			g_free (uri);

			return EXIT_FAILURE;
		}

		proxy = g_dbus_proxy_new_sync (connection,
		                               G_DBUS_PROXY_FLAGS_NONE,
		                               NULL,
		                               "org.freedesktop.Tracker1",
		                               "/org/freedesktop/Tracker1/Backup",
		                               "org.freedesktop.Tracker1.Backup",
		                               NULL,
		                               &error);

		if (error) {
			g_critical ("Could not create proxy on the D-Bus session bus, %s",
			            error ? error->message : "no error given.");
			g_clear_error (&error);
			g_free (uri);

			return EXIT_FAILURE;
		}

		/* Backup/Restore can take some time */
		g_dbus_proxy_set_default_timeout (proxy, G_MAXINT);

		v = g_dbus_proxy_call_sync (proxy,
		                            "Save",
		                            g_variant_new ("(s)", uri),
		                            G_DBUS_CALL_FLAGS_NONE,
		                            -1,
		                            NULL,
		                            &error);

		if (proxy) {
			g_object_unref (proxy);
		}

		if (error) {
			g_critical ("Could not backup database, %s",
			            error ? error->message : "no error given.");
			g_clear_error (&error);
			g_free (uri);

			return EXIT_FAILURE;
		}

		if (v) {
			g_variant_unref (v);
		}

		g_free (uri);
	}

	if (restore) {
		GDBusConnection *connection;
		GDBusProxy *proxy;
		GError *error = NULL;
		GVariant *v;
		gchar *uri;

		uri = get_uri_from_arg (restore);

		g_print ("%s\n", _("Restoring database from backup"));
		g_print ("  %s\n", uri);

		connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);

		if (!connection) {
			g_critical ("Could not connect to the D-Bus session bus, %s",
			            error ? error->message : "no error given.");
			g_clear_error (&error);
			g_free (uri);

			return EXIT_FAILURE;
		}

		proxy = g_dbus_proxy_new_sync (connection,
		                               G_DBUS_PROXY_FLAGS_NONE,
		                               NULL,
		                               "org.freedesktop.Tracker1",
		                               "/org/freedesktop/Tracker1/Backup",
		                               "org.freedesktop.Tracker1.Backup",
		                               NULL,
		                               &error);

		if (error) {
			g_critical ("Could not create proxy on the D-Bus session bus, %s",
			            error ? error->message : "no error given.");
			g_clear_error (&error);
			g_free (uri);

			return EXIT_FAILURE;
		}

		/* Backup/Restore can take some time */
		g_dbus_proxy_set_default_timeout (proxy, G_MAXINT);

		v = g_dbus_proxy_call_sync (proxy,
		                            "Restore",
		                            g_variant_new ("(s)", uri),
		                            G_DBUS_CALL_FLAGS_NONE,
		                            -1,
		                            NULL,
		                            &error);

		if (proxy) {
			g_object_unref (proxy);
		}

		if (error) {
			g_critical ("Could not restore database, %s",
			            error ? error->message : "no error given.");
			g_clear_error (&error);
			g_free (uri);

			return EXIT_FAILURE;
		}

		if (v) {
			g_variant_unref (v);
		}

		g_free (uri);
	}

	return EXIT_SUCCESS;
}