elm_config: fix elm_config_save not to wake idle processes up

there is a eio_monitor which is tracking on config directory.
and that is the reason why idle processes get waken up once some process call elm_config_save().
this patch fix the function not to wake idle processes up as it was before.

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D7354
This commit is contained in:
Wonki Kim 2018-11-27 04:49:27 +00:00 committed by Cedric BAIL
parent 43b18dc890
commit 8b0b9ed281
3 changed files with 174 additions and 86 deletions

View File

@ -1485,6 +1485,7 @@ _elm_win_profile_update(Efl_Ui_Win_Data *sd)
_config_profile_lock = EINA_TRUE;
_elm_config_profile_set(sd->profile.name);
_config_profile_lock = EINA_FALSE;
/* update sub ee */
Ecore_Evas *ee2;

View File

@ -5,6 +5,8 @@
#include <Elementary.h>
#include "elm_priv.h"
#include <pwd.h>
#include <fcntl.h>
#include "efl_config_global.eo.h"
@ -34,8 +36,7 @@ static void _elm_config_key_binding_hash(void);
Eina_Bool _config_profile_lock = EINA_FALSE;
static Ecore_Timer *_config_change_delay_timer = NULL;
static Ecore_Timer *_config_profile_change_delay_timer = NULL;
static Ecore_Event_Handler *_monitor_file_created_handler = NULL;
static Ecore_Event_Handler *_monitor_directory_created_handler = NULL;
static Ecore_Event_Handler *_monitor_file_modified_handler = NULL;
static Eio_Monitor *_eio_config_monitor = NULL;
static Eio_Monitor *_eio_profile_monitor = NULL;
@ -188,6 +189,7 @@ static void _config_sub_apply(void);
static void _config_update(void);
static void _env_get(void);
static void _color_overlays_cancel(void);
static Eina_Bool _file_touch(const char *file);
#define ELM_CONFIG_VAL(edd, type, member, dtype) \
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
@ -1617,20 +1619,19 @@ _elm_recache(void)
}
static Elm_Config *
_config_user_load(void)
_config_user_load(Eina_Bool on_flush)
{
Elm_Config *cfg = NULL;
Eet_File *ef;
char buf[PATH_MAX];
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s",
_elm_profile);
ecore_file_mkpath(buf);
if (_eio_config_monitor) eio_monitor_del(_eio_config_monitor);
_eio_config_monitor = eio_monitor_add(buf);
if (on_flush)
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg",
_elm_profile);
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
_elm_profile);
if (!ecore_file_exists(buf) || !on_flush)
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
_elm_profile);
ef = eet_open(buf, EET_FILE_MODE_READ);
if (ef)
@ -1683,7 +1684,7 @@ _efl_config_obj_del(Eo *obj EINA_UNUSED)
}
static void
_config_load(void)
_config_load(Eina_Bool on_flush)
{
if (_efl_config_obj)
{
@ -1702,7 +1703,7 @@ _config_load(void)
efl_del_intercept_set(_efl_config_obj, _efl_config_obj_del);
if (!_use_build_config)
{
_elm_config = _config_user_load();
_elm_config = _config_user_load(on_flush);
if (_elm_config)
{
if ((_elm_config->config_version >> ELM_CONFIG_VERSION_EPOCH_OFFSET) < ELM_CONFIG_EPOCH)
@ -1871,13 +1872,13 @@ _config_load(void)
}
static void
_elm_config_reload_do(void)
_elm_config_reload_do(Eina_Bool on_flush)
{
Elm_Config *prev_config;
prev_config = _elm_config;
_elm_config = NULL;
_config_load();
_config_load(on_flush);
if ((prev_config) && (_elm_config))
{
#define KEEP_VAL(xxx) \
@ -2096,7 +2097,7 @@ _config_flush_get(void)
_elm_config_font_overlays_cancel();
_color_overlays_cancel();
_elm_config_reload_do();
_elm_config_reload_do(EINA_TRUE);
/* restore prev value which is not part of the EET file */
_elm_config->is_mirrored = is_mirrored;
@ -2180,6 +2181,35 @@ _elm_config_eet_close_error_get(Eet_File *ef,
return NULL;
}
static char *
_elm_config_profile_name_get()
{
char buf[PATH_MAX], *p, *s;
Eet_File *ef = NULL;
int len = 0, i;
char *rst = NULL;
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
ef = eet_open(buf, EET_FILE_MODE_READ);
if (ef)
{
p = eet_read(ef, "config", &len);
if (p)
{
rst = calloc(1, len+1);
memcpy(rst, p, len);
rst[len] = '\0';
}
eet_close(ef);
}
if (rst)
return rst;
else
return strdup("default");
}
static Eina_Bool
_elm_config_profile_save(const char *profile)
{
@ -2189,43 +2219,50 @@ _elm_config_profile_save(const char *profile)
const char *err, *s;
Eet_File *ef;
size_t len;
char *_file_profile = NULL;
if ((s = getenv("ELM_PROFILE_NOSAVE")) && atoi(s))
return EINA_TRUE;
len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
if (len + 1 >= sizeof(buf))
return EINA_FALSE;
_file_profile = _elm_config_profile_name_get();
len = _elm_config_user_dir_snprintf(buf2, sizeof(buf2),
"config/profile.cfg.tmp");
if (len + 1 >= sizeof(buf2))
return EINA_FALSE;
ef = eet_open(buf2, EET_FILE_MODE_WRITE);
if (!ef)
return EINA_FALSE;
ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
if (!ok)
goto err;
err = _elm_config_eet_close_error_get(ef, buf2);
if (err)
if (!_file_profile || strcmp(_elm_profile, _file_profile))
{
ERR("%s", err);
free((void *)err);
goto err;
}
len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
if (len + 1 >= sizeof(buf))
return EINA_FALSE;
ret = ecore_file_cp(buf2, buf);
if (!ret)
{
ERR("Error saving Elementary's configuration profile file");
goto err;
}
len = _elm_config_user_dir_snprintf(buf2, sizeof(buf2),
"config/profile.cfg.tmp");
if (len + 1 >= sizeof(buf2))
return EINA_FALSE;
ecore_file_unlink(buf2);
ef = eet_open(buf2, EET_FILE_MODE_WRITE);
if (!ef)
return EINA_FALSE;
ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
if (!ok)
goto err;
err = _elm_config_eet_close_error_get(ef, buf2);
if (err)
{
ERR("%s", err);
free((void *)err);
goto err;
}
ret = ecore_file_cp(buf2, buf);
if (!ret)
{
ERR("Error saving Elementary's configuration profile file");
goto err;
}
ecore_file_unlink(buf2);
}
free(_file_profile);
derived = _elm_config_derived_load(profile ? profile : _elm_profile);
if (derived)
@ -3051,7 +3088,7 @@ elm_config_save(void)
EAPI void
elm_config_reload(void)
{
_elm_config_reload();
_elm_config_reload(EINA_FALSE);
}
EAPI const char *
@ -4190,9 +4227,10 @@ elm_config_popup_scrollable_set(Eina_Bool scrollable)
EAPI void
elm_config_all_flush(void)
{
char buf[PATH_MAX];
char buf[PATH_MAX], buf2[PATH_MAX];
int ok = 0;
size_t len;
Eet_File *ef = NULL;
len = _elm_config_user_dir_snprintf(buf, sizeof(buf), "themes/");
if (len + 1 >= sizeof(buf))
@ -4224,6 +4262,27 @@ elm_config_all_flush(void)
return;
}
_elm_config_user_dir_snprintf(buf, sizeof(buf),
"config/%s/.base.flush.cfg.tmp", _elm_profile);
_elm_config_user_dir_snprintf(buf2, sizeof(buf2),
"config/%s/.base.flush.cfg", _elm_profile);
ef = eet_open(buf, EET_FILE_MODE_WRITE);
if (ef)
{
ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
if (!ok)
{
eet_close(ef);
ERR("Failed to save config");
return;
}
eet_close(ef);
ecore_file_cp(buf, buf2);
}
ecore_file_unlink(buf);
elm_config_save();
return;
}
@ -4269,7 +4328,7 @@ _elm_config_init(void)
_desc_init();
_elm_config_profile_derived_init();
_profile_fetch_from_conf();
_config_load();
_config_load(EINA_FALSE);
if (_elm_config) _env_get();
ELM_SAFE_FREE(_elm_accel_preference, eina_stringshare_del);
ELM_SAFE_FREE(_elm_gl_preference, eina_stringshare_del);
@ -4297,17 +4356,27 @@ _elm_config_sub_shutdown(void)
ELM_SAFE_FREE(_eio_profile_monitor, eio_monitor_del);
ELM_SAFE_FREE(_config_change_delay_timer, ecore_timer_del);
ELM_SAFE_FREE(_config_profile_change_delay_timer, ecore_timer_del);
ELM_SAFE_FREE(_monitor_file_created_handler, ecore_event_handler_del);
ELM_SAFE_FREE(_monitor_directory_created_handler, ecore_event_handler_del);
ELM_SAFE_FREE(_monitor_file_modified_handler, ecore_event_handler_del);
}
static Eina_Bool
_config_profile_change_delay_cb(void *data EINA_UNUSED)
{
char *pprof = NULL;
char buf[PATH_MAX];
if (_elm_profile) pprof = strdup(_elm_profile);
_profile_fetch_from_conf();
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg", _elm_profile);
if(!ecore_file_exists(buf)) _file_touch(buf);
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg", _elm_profile);
if(!ecore_file_exists(buf)) _file_touch(buf);
ELM_SAFE_FREE(_eio_config_monitor, eio_monitor_del);
_eio_config_monitor = eio_monitor_add(buf);
if ((!pprof) || (!(!strcmp(pprof, _elm_profile))))
{
_config_flush_get();
@ -4320,7 +4389,7 @@ _config_profile_change_delay_cb(void *data EINA_UNUSED)
static Eina_Bool
_config_change_delay_cb(void *data EINA_UNUSED)
{
_elm_config_reload();
_elm_config_reload(EINA_TRUE);
_config_change_delay_timer = NULL;
return ECORE_CALLBACK_CANCEL;
@ -4337,40 +4406,21 @@ _elm_config_file_monitor_cb(void *data EINA_UNUSED,
if (ev->monitor == _eio_config_monitor)
{
if (type == EIO_MONITOR_FILE_CREATED)
if (!strcmp(file, ".base.flush.cfg"))
{
if (!strcmp(file, "base.cfg"))
{
if (_config_change_delay_timer)
ecore_timer_del(_config_change_delay_timer);
_config_change_delay_timer = ecore_timer_add(0.1, _config_change_delay_cb, NULL);
}
if (_config_change_delay_timer)
ecore_timer_del(_config_change_delay_timer);
_config_change_delay_timer = ecore_timer_add(0.1, _config_change_delay_cb, NULL);
}
}
if (ev->monitor == _eio_profile_monitor)
{
if (type == EIO_MONITOR_FILE_CREATED)
if (!strcmp(file, "profile.cfg"))
{
if ((!_config_profile_lock) && (!strcmp(file, "profile.cfg")))
{
if (_config_profile_change_delay_timer)
ecore_timer_del(_config_profile_change_delay_timer);
_config_profile_change_delay_timer = ecore_timer_add(0.1, _config_profile_change_delay_cb, NULL);
}
}
else if (type == EIO_MONITOR_DIRECTORY_CREATED)
{
if (!_eio_config_monitor)
{
_eio_config_monitor = eio_monitor_add(ev->filename);
snprintf(buf, sizeof(buf), "%s/base.cfg", ev->filename);
if (ecore_file_exists(buf))
{
if (_config_change_delay_timer)
ecore_timer_del(_config_change_delay_timer);
_config_change_delay_timer = ecore_timer_add(0.1, _config_change_delay_cb, NULL);
}
}
if (_config_profile_change_delay_timer)
ecore_timer_del(_config_profile_change_delay_timer);
_config_profile_change_delay_timer = ecore_timer_add(0.1, _config_profile_change_delay_cb, NULL);
}
}
@ -4397,18 +4447,29 @@ _elm_config_sub_init(void)
buf);
goto end;
}
_elm_config_profile_save(NULL);
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
if(!ecore_file_exists(buf)) _file_touch(buf);
_eio_profile_monitor = eio_monitor_add(buf);
_monitor_file_created_handler = ecore_event_handler_add
(EIO_MONITOR_FILE_CREATED, _elm_config_file_monitor_cb, NULL);
_monitor_directory_created_handler = ecore_event_handler_add
(EIO_MONITOR_DIRECTORY_CREATED, _elm_config_file_monitor_cb, NULL);
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg", _elm_profile);
if(!ecore_file_exists(buf)) _file_touch(buf);
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg", _elm_profile);
if(!ecore_file_exists(buf)) _file_touch(buf);
_eio_config_monitor = eio_monitor_add(buf);
_monitor_file_modified_handler = ecore_event_handler_add
(EIO_MONITOR_FILE_MODIFIED, _elm_config_file_monitor_cb, NULL);
end:
_config_sub_apply();
}
void
_elm_config_reload(void)
_elm_config_reload(Eina_Bool on_flush)
{
Eina_Bool is_mirrored;
Eina_Bool translate;
@ -4442,7 +4503,7 @@ _elm_config_reload(void)
is_mirrored = _elm_config->is_mirrored;
translate = _elm_config->translate;
_elm_config_reload_do();
_elm_config_reload_do(on_flush);
/* restore prev value which is not part of the EET file */
_elm_config->is_mirrored = is_mirrored;
@ -4728,6 +4789,7 @@ _elm_config_profile_set(const char *profile)
Eina_Bool translate;
is_mirrored = _elm_config->is_mirrored;
translate = _elm_config->translate;
char buf[PATH_MAX];
if (!profile) return;
@ -4741,9 +4803,15 @@ _elm_config_profile_set(const char *profile)
_elm_profile = strdup(profile);
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg", _elm_profile);
if(!ecore_file_exists(buf)) _file_touch(buf);
_elm_config_user_dir_snprintf(buf, sizeof(buf), "config/%s/.base.flush.cfg", _elm_profile);
if(!ecore_file_exists(buf)) _file_touch(buf);
_color_overlays_cancel();
_elm_config_reload_do();
_elm_config_reload_do(EINA_FALSE);
/* restore prev value which is not part of the EET file */
_elm_config->is_mirrored = is_mirrored;
@ -5307,6 +5375,25 @@ EOLIAN static void
_efl_config_global_profile_derived_del(Eo *obj EINA_UNUSED, void *_pd EINA_UNUSED, const char *profile)
{
elm_config_profile_derived_del(profile);
}
static Eina_Bool
_file_touch(const char *file)
{
if (!file) return EINA_FALSE;
const char *dir = ecore_file_dir_get(file);
if(!dir) return EINA_FALSE;
if(!ecore_file_mkpath(dir)) return EINA_FALSE;
Eo *f = efl_add_ref(EFL_IO_FILE_CLASS, NULL,
efl_file_set(efl_added, file, NULL),
efl_io_file_flags_set(efl_added, O_CREAT|O_RDWR),
efl_io_file_mode_set(efl_added, 0644));
if (!f) return EINA_FALSE;
efl_unref(f);
return EINA_TRUE;
}
#include "efl_config_global.eo.c"

View File

@ -630,7 +630,7 @@ void _elm_config_sub_init(void);
void _elm_config_shutdown(void);
void _elm_config_sub_shutdown(void);
Eina_Bool _elm_config_save(Elm_Config *cfg, const char *profile);
void _elm_config_reload(void);
void _elm_config_reload(Eina_Bool on_flush);
size_t _elm_config_user_dir_snprintf(char *dst, size_t size,
const char *fmt, ...)
EINA_PRINTF(3, 4);