Skip to content

Commit

Permalink
Do not exit / disable plugins if builtin gconf keys are missing
Browse files Browse the repository at this point in the history
In general all configurable items have sane built-in defaults and
thus not having configuration keys available must not result in
termination of mce process or rejecting loaded plugins.

Since unwanted exits have been removed, mce_gconf_notifier_add()
can now return actual success/failure value - except for the
gconf disabled on purpose situation.

Also normalize places where mce_gconf_notifier_add() is used so that
initial value is read after installing change notifier callback.
  • Loading branch information
spiiroin committed Jun 16, 2014
1 parent 14bc236 commit bbd6c2b
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 85 deletions.
1 change: 1 addition & 0 deletions event-input.c
Expand Up @@ -2613,6 +2613,7 @@ gboolean mce_input_init(void)
MCE_GCONF_USE_FAKE_DOUBLETAP_PATH,
fake_doubletap_cb,
&fake_doubletap_id);

mce_gconf_get_bool(MCE_GCONF_USE_FAKE_DOUBLETAP_PATH,
&fake_doubletap_enabled);
#endif
Expand Down
18 changes: 9 additions & 9 deletions mce-gconf.c
Expand Up @@ -312,12 +312,13 @@ gboolean mce_gconf_notifier_add(const gchar *path, const gchar *key,
if( gconf_disabled ) {
mce_log(LL_DEBUG, "blocked %s notifier", key);

/* Returning failure would result in termination
/* Returning failure could 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 @@ -326,25 +327,24 @@ gboolean mce_gconf_notifier_add(const gchar *path, const gchar *key,
"Could not add %s to directories watched by "
"GConf client setting from GConf; %s",
path, error->message);
//goto EXIT;
goto EXIT;
}

g_clear_error(&error);

id = gconf_client_notify_add(gconf_client, key, callback,
NULL, NULL, &error);
if (error != NULL) {
mce_log(LL_WARN,
"Could not register notifier for %s; %s",
key, error->message);
//goto EXIT;
goto EXIT;
}

if( id )
gconf_notifiers = g_slist_prepend(gconf_notifiers,
GINT_TO_POINTER(id));
if( !id )
goto EXIT;

gconf_notifiers = g_slist_prepend(gconf_notifiers,
GINT_TO_POINTER(id));

// FIXME: fix the bogus success return
status = TRUE;

EXIT:
Expand Down
72 changes: 40 additions & 32 deletions modules/display.c
Expand Up @@ -7188,21 +7188,25 @@ static void mdy_gconf_init(void)
MCE_GCONF_DISPLAY_BRIGHTNESS_LEVEL_COUNT_PATH,
mdy_gconf_cb,
&mdy_brightness_step_count_gconf_id);

mce_gconf_get_int(MCE_GCONF_DISPLAY_BRIGHTNESS_LEVEL_COUNT_PATH,
&mdy_brightness_step_count);

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_BRIGHTNESS_LEVEL_SIZE_PATH,
mdy_gconf_cb,
&mdy_brightness_step_size_gconf_id);

mce_gconf_get_int(MCE_GCONF_DISPLAY_BRIGHTNESS_LEVEL_SIZE_PATH,
&mdy_brightness_step_size);

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_BRIGHTNESS_PATH,
mdy_gconf_cb,
&mdy_brightness_setting_gconf_id);

mce_gconf_get_int(MCE_GCONF_DISPLAY_BRIGHTNESS_PATH,
&mdy_brightness_setting);
mce_gconf_get_int(MCE_GCONF_DISPLAY_BRIGHTNESS_LEVEL_SIZE_PATH,
&mdy_brightness_step_size);
mce_gconf_get_int(MCE_GCONF_DISPLAY_BRIGHTNESS_LEVEL_COUNT_PATH,
&mdy_brightness_step_count);

/* Migrate ranges, update hw dim/on brightness levels */
mdy_gconf_sanitize_brightness_settings();
Expand All @@ -7220,35 +7224,36 @@ static void mdy_gconf_init(void)

/* Display blank
* Since we've set a default, error handling is unnecessary */
mce_gconf_get_int(MCE_GCONF_DISPLAY_BLANK_TIMEOUT_PATH,
&mdy_disp_blank_timeout);

mdy_disp_lpm_on_timeout = mdy_disp_blank_timeout;

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_BLANK_TIMEOUT_PATH,
mdy_gconf_cb,
&mdy_disp_blank_timeout_gconf_cb_id);

mce_gconf_get_int(MCE_GCONF_DISPLAY_BLANK_TIMEOUT_PATH,
&mdy_disp_blank_timeout);

mdy_disp_lpm_on_timeout = mdy_disp_blank_timeout;

/* Never blank
* Since we've set a default, error handling is unnecessary */
mce_gconf_get_int(MCE_GCONF_DISPLAY_NEVER_BLANK_PATH,
&mdy_disp_never_blank);
mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_NEVER_BLANK_PATH,
mdy_gconf_cb,
&mdy_disp_never_blank_gconf_cb_id);

mce_gconf_get_int(MCE_GCONF_DISPLAY_NEVER_BLANK_PATH,
&mdy_disp_never_blank);

/* Use adaptive display dim timeout
* Since we've set a default, error handling is unnecessary */
mce_gconf_get_bool(MCE_GCONF_DISPLAY_ADAPTIVE_DIMMING_PATH,
&mdy_adaptive_dimming_enabled);

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_ADAPTIVE_DIMMING_PATH,
mdy_gconf_cb,
&mdy_adaptive_dimming_enabled_gconf_cb_id);

mce_gconf_get_bool(MCE_GCONF_DISPLAY_ADAPTIVE_DIMMING_PATH,
&mdy_adaptive_dimming_enabled);

/* Possible dim timeouts */
if( !mce_gconf_get_int_list(MCE_GCONF_DISPLAY_DIM_TIMEOUT_LIST_PATH,
&mdy_possible_dim_timeouts) ) {
Expand All @@ -7258,27 +7263,27 @@ static void mdy_gconf_init(void)

/* Adaptive display dimming threshold
* Since we've set a default, error handling is unnecessary */
mce_gconf_get_int(MCE_GCONF_DISPLAY_ADAPTIVE_DIM_THRESHOLD_PATH,
&mdy_adaptive_dimming_threshold);

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_ADAPTIVE_DIM_THRESHOLD_PATH,
mdy_gconf_cb,
&mdy_adaptive_dimming_threshold_gconf_cb_id);

mce_gconf_get_int(MCE_GCONF_DISPLAY_ADAPTIVE_DIM_THRESHOLD_PATH,
&mdy_adaptive_dimming_threshold);

/* Display dim
* Since we've set a default, error handling is unnecessary */
mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_DIM_TIMEOUT_PATH,
mdy_gconf_cb,
&mdy_disp_dim_timeout_gconf_cb_id);

mce_gconf_get_int(MCE_GCONF_DISPLAY_DIM_TIMEOUT_PATH,
&mdy_disp_dim_timeout);

mdy_dim_timeout_index = mdy_blanking_find_dim_timeout_index(mdy_disp_dim_timeout);
mdy_adaptive_dimming_index = 0;

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_DISPLAY_DIM_TIMEOUT_PATH,
mdy_gconf_cb,
&mdy_disp_dim_timeout_gconf_cb_id);

/* Update inactivity timeout */
execute_datapipe(&inactivity_timeout_pipe,
GINT_TO_POINTER(mdy_disp_dim_timeout +
Expand All @@ -7288,29 +7293,30 @@ static void mdy_gconf_init(void)

/* Use low power mode?
* Since we've set a default, error handling is unnecessary */
mce_gconf_get_bool(MCE_GCONF_USE_LOW_POWER_MODE_PATH,
&mdy_use_low_power_mode);

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_USE_LOW_POWER_MODE_PATH,
mdy_gconf_cb,
&mdy_use_low_power_mode_gconf_cb_id);

mce_gconf_get_bool(MCE_GCONF_USE_LOW_POWER_MODE_PATH,
&mdy_use_low_power_mode);

/* Don't blank on charger
* Since we've set a default, error handling is unnecessary */
mce_gconf_get_int(MCE_GCONF_BLANKING_INHIBIT_MODE_PATH,
&mdy_blanking_inhibit_mode);

mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_BLANKING_INHIBIT_MODE_PATH,
mdy_gconf_cb,
&mdy_blanking_inhibit_mode_gconf_cb_id);

mce_gconf_get_int(MCE_GCONF_BLANKING_INHIBIT_MODE_PATH,
&mdy_blanking_inhibit_mode);

/* Delay for killing unresponsive compositor */
mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_LIPSTICK_CORE_DELAY_PATH,
mdy_gconf_cb,
&mdy_compositor_core_delay_gconf_cb_id);

mce_gconf_get_int(MCE_GCONF_LIPSTICK_CORE_DELAY_PATH,
&mdy_compositor_core_delay);
}
Expand Down Expand Up @@ -7408,26 +7414,28 @@ const gchar *g_module_check_init(GModule *module)
mdy_governor_interactive = mdy_governor_get_settings("Interactive");

/* Get cpu scaling governor configuration & track changes */
mce_gconf_get_int(MCE_GCONF_CPU_SCALING_GOVERNOR_PATH,
&mdy_governor_conf);
mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_CPU_SCALING_GOVERNOR_PATH,
mdy_governor_conf_cb,
&mdy_governor_conf_id);

mce_gconf_get_int(MCE_GCONF_CPU_SCALING_GOVERNOR_PATH,
&mdy_governor_conf);

/* Evaluate initial state */
mdy_governor_rethink();
#endif

#ifdef ENABLE_WAKELOCKS
/* Get autosuspend policy configuration & track changes */
mce_gconf_get_int(MCE_GCONF_USE_AUTOSUSPEND_PATH,
&mdy_suspend_policy);
mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH,
MCE_GCONF_USE_AUTOSUSPEND_PATH,
mdy_autosuspend_gconf_cb,
&mdy_suspend_policy_id);

mce_gconf_get_int(MCE_GCONF_USE_AUTOSUSPEND_PATH,
&mdy_suspend_policy);

/* Evaluate initial state */
mdy_stm_schedule_rethink();
#endif
Expand Down
1 change: 1 addition & 0 deletions modules/doubletap.c
Expand Up @@ -322,6 +322,7 @@ const gchar *g_module_check_init(GModule *module)
MCE_GCONF_DOUBLETAP_MODE,
dbltap_mode_gconf_cb,
&dbltap_mode_gconf_id);

gint mode = DBLTAP_ENABLE_DEFAULT;
mce_gconf_get_int(MCE_GCONF_DOUBLETAP_MODE, &mode);
dbltap_mode = mode;
Expand Down
1 change: 1 addition & 0 deletions modules/filter-brightness-als.c
Expand Up @@ -1153,6 +1153,7 @@ const gchar *g_module_check_init(GModule *module)
MCE_GCONF_DISPLAY_ALS_ENABLED_PATH,
use_als_gconf_cb,
&use_als_gconf_id);

mce_gconf_get_bool(MCE_GCONF_DISPLAY_ALS_ENABLED_PATH,
&use_als_flag);

Expand Down
11 changes: 5 additions & 6 deletions modules/led.c
Expand Up @@ -1824,13 +1824,10 @@ static gboolean pattern_get_enabled(const gchar *const patternname,
patternname);

/* Since we've set a default, error handling is unnecessary */
(void)mce_gconf_get_bool(path, &retval);
mce_gconf_notifier_add(MCE_GCONF_LED_PATH, path,
led_gconf_cb, gconf_cb_id);
mce_gconf_get_bool(path, &retval);

if (mce_gconf_notifier_add(MCE_GCONF_LED_PATH, path,
led_gconf_cb, gconf_cb_id) == FALSE)
goto EXIT;

EXIT:
g_free(path);

return retval;
Expand Down Expand Up @@ -2801,6 +2798,7 @@ static void sw_breathing_init(void)
"/system/osso/dsm/leds/sw_breath_enabled",
sw_breathing_gconf_cb,
&sw_breathing_enabled_gconf_id);

mce_gconf_get_bool("/system/osso/dsm/leds/sw_breath_enabled",
&sw_breathing_enabled);

Expand All @@ -2809,6 +2807,7 @@ static void sw_breathing_init(void)
"/system/osso/dsm/leds/sw_breath_battery_limit",
sw_breathing_gconf_cb,
&sw_breathing_battery_limit_gconf_id);

mce_gconf_get_int("/system/osso/dsm/leds/sw_breath_battery_limit",
&sw_breathing_battery_limit);
}
Expand Down
51 changes: 23 additions & 28 deletions modules/powersavemode.c
Expand Up @@ -284,46 +284,41 @@ const gchar *g_module_check_init(GModule *module)

/* Power saving mode setting */
/* Since we've set a default, error handling is unnecessary */
(void)mce_gconf_get_bool(MCE_GCONF_PSM_PATH,
&power_saving_mode);
mce_gconf_notifier_add(MCE_GCONF_EM_PATH,
MCE_GCONF_PSM_PATH,
psm_gconf_cb,
&psm_gconf_cb_id);

if (mce_gconf_notifier_add(MCE_GCONF_EM_PATH,
MCE_GCONF_PSM_PATH,
psm_gconf_cb,
&psm_gconf_cb_id) == FALSE)
goto EXIT;
mce_gconf_get_bool(MCE_GCONF_PSM_PATH,
&power_saving_mode);

/* Forced power saving mode setting */
/* Since we've set a default, error handling is unnecessary */
(void)mce_gconf_get_bool(MCE_GCONF_FORCED_PSM_PATH,
&force_psm);
mce_gconf_notifier_add(MCE_GCONF_EM_PATH,
MCE_GCONF_FORCED_PSM_PATH,
psm_gconf_cb,
&force_psm_gconf_cb_id);

if (mce_gconf_notifier_add(MCE_GCONF_EM_PATH,
MCE_GCONF_FORCED_PSM_PATH,
psm_gconf_cb,
&force_psm_gconf_cb_id) == FALSE)
goto EXIT;
mce_gconf_get_bool(MCE_GCONF_FORCED_PSM_PATH,
&force_psm);

/* Power saving mode threshold */
/* Since we've set a default, error handling is unnecessary */
(void)mce_gconf_get_int(MCE_GCONF_PSM_THRESHOLD_PATH,
&psm_threshold);
mce_gconf_notifier_add(MCE_GCONF_EM_PATH,
MCE_GCONF_PSM_THRESHOLD_PATH,
psm_gconf_cb,
&psm_threshold_gconf_cb_id);

if (mce_gconf_notifier_add(MCE_GCONF_EM_PATH,
MCE_GCONF_PSM_THRESHOLD_PATH,
psm_gconf_cb,
&psm_threshold_gconf_cb_id) == FALSE)
goto EXIT;
mce_gconf_get_int(MCE_GCONF_PSM_THRESHOLD_PATH,
&psm_threshold);

/* get_psm_state */
if (mce_dbus_handler_add(MCE_REQUEST_IF,
MCE_PSM_STATE_GET,
NULL,
DBUS_MESSAGE_TYPE_METHOD_CALL,
psm_state_get_dbus_cb) == NULL)
goto EXIT;
mce_dbus_handler_add(MCE_REQUEST_IF,
MCE_PSM_STATE_GET,
NULL,
DBUS_MESSAGE_TYPE_METHOD_CALL,
psm_state_get_dbus_cb);

EXIT:
return NULL;
}

Expand Down
1 change: 1 addition & 0 deletions modules/proximity.c
Expand Up @@ -1047,6 +1047,7 @@ const gchar *g_module_check_init(GModule *module)
MCE_GCONF_PROXIMITY_PS_ENABLED_PATH,
use_ps_conf_cb,
&use_ps_conf_id);

mce_gconf_get_bool(MCE_GCONF_PROXIMITY_PS_ENABLED_PATH,
&use_ps_conf_value);

Expand Down
1 change: 1 addition & 0 deletions powerkey.c
Expand Up @@ -166,6 +166,7 @@ static void powerkey_gconf_init(void)
MCE_GCONF_POWERKEY_MODE,
powerkey_gconf_cb,
&powerkey_action_mode_cb_id);

mce_gconf_get_int(MCE_GCONF_POWERKEY_MODE, &powerkey_action_mode);
}

Expand Down

0 comments on commit bbd6c2b

Please sign in to comment.