Skip to content

Commit

Permalink
Block MCE from gconf unless we have $DBUS_SESSION_BUS_ADDRESS
Browse files Browse the repository at this point in the history
This stops repetitive error messages from gconf library code and
keeps us from trying to autolaunch session bus if $DISPLAY happens
to be set.

If the disabling happens, one error message gets logged when
mce_gconf_init() is called and debug level logging is done for
individual gconf get/set attempts that mce makes.

Additionally mce_gconf_notifier_add() fakes success because
otherwise mce process would exit before reaching mainloop.
  • Loading branch information
spiiroin committed Nov 16, 2012
1 parent 2eda5e4 commit 80dad85
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion mce-gconf.c
Expand Up @@ -23,13 +23,17 @@

#include <gconf/gconf-client.h>

#include <stdlib.h> /* getenv() */

#include "mce.h"
#include "mce-gconf.h"

#include "mce-log.h" /* mce_log(), LL_* */

/** Pointer to the GConf client */
static GConfClient *gconf_client = NULL;
/** Is GConf disabled on purpose */
static gboolean gconf_disabled = FALSE;
/** List of GConf notifiers */
static GSList *gconf_notifiers = NULL;

Expand All @@ -44,6 +48,11 @@ gboolean mce_gconf_set_int(const gchar *const key, const gint value)
{
gboolean status = FALSE;

if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s = %d", key, value);
goto EXIT;
}

if (gconf_client_set_int(gconf_client, key, value, NULL) == FALSE) {
mce_log(LL_WARN, "Failed to write %s to GConf", key);
goto EXIT;
Expand All @@ -69,6 +78,11 @@ gboolean mce_gconf_set_string(const gchar *const key, const gchar *const value)
{
gboolean status = FALSE;

if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s = \"%s\"", key, value);
goto EXIT;
}

if (gconf_client_set_string(gconf_client, key, value, NULL) == FALSE) {
mce_log(LL_WARN, "Failed to write %s to GConf", key);
goto EXIT;
Expand Down Expand Up @@ -96,6 +110,11 @@ gboolean mce_gconf_get_bool(const gchar *const key, gboolean *value)
GError *error = NULL;
GConfValue *gcv;

if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s query", key);
goto EXIT;
}

gcv = gconf_client_get(gconf_client, key, &error);

if (gcv == NULL) {
Expand Down Expand Up @@ -136,6 +155,11 @@ gboolean mce_gconf_get_int(const gchar *const key, gint *value)
GError *error = NULL;
GConfValue *gcv;

if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s query", key);
goto EXIT;
}

gcv = gconf_client_get(gconf_client, key, &error);

if (gcv == NULL) {
Expand Down Expand Up @@ -178,6 +202,11 @@ gboolean mce_gconf_get_int_list(const gchar *const key, GSList **values)
GSList *list;
gint i;

if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s query", key);
goto EXIT;
}

gcv = gconf_client_get(gconf_client, key, &error);

if (gcv == NULL) {
Expand Down Expand Up @@ -232,6 +261,11 @@ gboolean mce_gconf_get_string(const gchar *const key, gchar **value)
GError *error = NULL;
GConfValue *gcv;

if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s query", key);
goto EXIT;
}

gcv = gconf_client_get(gconf_client, key, &error);

if (gcv == NULL) {
Expand Down Expand Up @@ -275,6 +309,15 @@ gboolean mce_gconf_notifier_add(const gchar *path, const gchar *key,
GError *error = NULL;
gboolean status = FALSE;

if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s notifier", key);

/* Returning failure would result in termination
* of mce process -> return bogus success if we
* have disabled gconf on purpose. */
status = TRUE;
goto EXIT;
}
gconf_client_add_dir(gconf_client, path,
GCONF_CLIENT_PRELOAD_NONE, &error);

Expand All @@ -301,7 +344,7 @@ gboolean mce_gconf_notifier_add(const gchar *path, const gchar *key,
GINT_TO_POINTER(*cb_id));
status = TRUE;

//EXIT:
EXIT:
g_clear_error(&error);

return status;
Expand All @@ -317,8 +360,14 @@ void mce_gconf_notifier_remove(gpointer cb_id, gpointer user_data)
{
(void)user_data;

if( gconf_disabled )
goto EXIT;

gconf_client_notify_remove(gconf_client, GPOINTER_TO_INT(cb_id));
gconf_notifiers = g_slist_remove(gconf_notifiers, cb_id);

EXIT:
return;
}

/**
Expand All @@ -330,6 +379,16 @@ gboolean mce_gconf_init(void)
{
gboolean status = FALSE;

/* Trying to use gconf without already existing session
* bus can only yield problems -> disable gconf access
*/
if( !getenv("DBUS_SESSION_BUS_ADDRESS") ) {
mce_log(LL_ERR, "No session bus - disabling gconf accesss");
gconf_disabled = TRUE;
status = TRUE;
goto EXIT;
}

/* Get the default GConf client */
if ((gconf_client = gconf_client_get_default()) == FALSE) {
mce_log(LL_CRIT, "Could not get default GConf client");
Expand Down

0 comments on commit 80dad85

Please sign in to comment.