Use weston_compositor_add_destroy_listener_once() in plugins
This introduces a new convention of checking through the compositor destroy listener if the plugin is already initialized. If the plugin is already initialized, then the plugin entry function succeeds as a no-op. This makes it safe to load the same plugin multiple times in a running compositor. Currently module loading functions return failure if a plugin is already loaded, but that will change in the future. Therefore we need this other method of ensuring we do not double-initialize a plugin which would lead to list corruptions the very least. All plugins are converted to use the new helper, except: - those that do not have a destroy listener already, and - hmi-controller which does the same open-coded as the common code pattern did not fit there. Plugins should always have a compositor destroy listener registered since they very least allocate a struct to hold their data. Hence omissions are highlighted in code. Backends do not need this because weston_compositor_load_backend() already protects against double-init. GL-renderer does not export a standard module init function so cannot be initialized the usual way and therefore is not vulnerable to double-init. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
committed by
Daniel Stone
parent
5caef6d355
commit
6ffbba3ac1
@@ -528,6 +528,14 @@ wet_module_init(struct weston_compositor *ec,
|
||||
if (cms == NULL)
|
||||
return -1;
|
||||
cms->ec = ec;
|
||||
|
||||
if (!weston_compositor_add_destroy_listener_once(ec,
|
||||
&cms->destroy_listener,
|
||||
colord_notifier_destroy)) {
|
||||
free(cms);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,36,0)
|
||||
g_type_init();
|
||||
#endif
|
||||
@@ -543,10 +551,6 @@ wet_module_init(struct weston_compositor *ec,
|
||||
cms->devices = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||
g_free, colord_cms_output_destroy);
|
||||
|
||||
/* destroy */
|
||||
cms->destroy_listener.notify = colord_notifier_destroy;
|
||||
wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
|
||||
|
||||
/* devices added */
|
||||
cms->output_created_listener.notify = colord_notifier_output_created;
|
||||
wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
|
||||
|
||||
@@ -105,8 +105,13 @@ wet_module_init(struct weston_compositor *ec,
|
||||
return -1;
|
||||
|
||||
cms->ec = ec;
|
||||
cms->destroy_listener.notify = cms_notifier_destroy;
|
||||
wl_signal_add(&ec->destroy_signal, &cms->destroy_listener);
|
||||
|
||||
if (!weston_compositor_add_destroy_listener_once(ec,
|
||||
&cms->destroy_listener,
|
||||
cms_notifier_destroy)) {
|
||||
free(cms);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cms->output_created_listener.notify = cms_notifier_output_created;
|
||||
wl_signal_add(&ec->output_created_signal, &cms->output_created_listener);
|
||||
|
||||
@@ -114,6 +114,9 @@ struct ss_shm_buffer {
|
||||
|
||||
struct screen_share {
|
||||
struct weston_compositor *compositor;
|
||||
/* XXX: missing compositor destroy listener
|
||||
* https://gitlab.freedesktop.org/wayland/weston/issues/298
|
||||
*/
|
||||
char *command;
|
||||
};
|
||||
|
||||
|
||||
@@ -127,10 +127,12 @@ wet_module_init(struct weston_compositor *compositor,
|
||||
if (notifier == NULL)
|
||||
return -1;
|
||||
|
||||
notifier->compositor_destroy_listener.notify =
|
||||
weston_compositor_destroy_listener;
|
||||
wl_signal_add(&compositor->destroy_signal,
|
||||
¬ifier->compositor_destroy_listener);
|
||||
if (!weston_compositor_add_destroy_listener_once(compositor,
|
||||
¬ifier->compositor_destroy_listener,
|
||||
weston_compositor_destroy_listener)) {
|
||||
free(notifier);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (add_systemd_sockets(compositor) < 0)
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user