[PATCH weston 2/3] modules: Drop module_init as a shared init function

Quentin Glidic sardemff7+wayland at sardemff7.net
Mon Jul 4 13:58:08 UTC 2016


From: Quentin Glidic <sardemff7+git at sardemff7.net>

Use different functions so we cannot load a libweston module in weston
or the other way around.

Also properly namespace backend_init and use a different name for weston
shells.

Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---
 compositor/cms-colord.c             |  5 +++--
 compositor/cms-static.c             |  4 ++--
 compositor/main.c                   | 45 ++++++++++++++++++++++++++++++-------
 compositor/screen-share.c           |  4 ++--
 compositor/weston.h                 | 13 ++++++++++-
 desktop-shell/shell.c               |  4 ++--
 fullscreen-shell/fullscreen-shell.c |  5 +++--
 ivi-shell/ivi-layout.c              |  4 +++-
 ivi-shell/ivi-shell.c               |  4 ++--
 libweston/compositor-drm.c          |  4 ++--
 libweston/compositor-fbdev.c        |  4 ++--
 libweston/compositor-headless.c     |  4 ++--
 libweston/compositor-rdp.c          |  4 ++--
 libweston/compositor-wayland.c      |  4 ++--
 libweston/compositor-x11.c          |  4 ++--
 libweston/compositor.c              | 23 ++++++++++++-------
 libweston/compositor.h              |  7 +++---
 tests/plugin-registry-test.c        |  4 +++-
 tests/surface-global-test.c         |  4 +++-
 tests/surface-screenshot.c          |  5 +++--
 tests/surface-test.c                |  4 +++-
 tests/weston-test.c                 |  4 ++--
 xwayland/launcher.c                 |  3 +--
 23 files changed, 111 insertions(+), 55 deletions(-)

diff --git a/compositor/cms-colord.c b/compositor/cms-colord.c
index b9bc9e3..b9938b9 100644
--- a/compositor/cms-colord.c
+++ b/compositor/cms-colord.c
@@ -33,6 +33,7 @@
 #include <colord.h>
 
 #include "compositor.h"
+#include "weston.h"
 #include "cms-helper.h"
 #include "shared/helpers.h"
 
@@ -494,8 +495,8 @@ colord_cms_output_destroy(gpointer data)
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *ec,
-	    int *argc, char *argv[])
+wet_module_init(struct weston_compositor *ec,
+		int *argc, char *argv[])
 {
 	gboolean ret;
 	GError *error = NULL;
diff --git a/compositor/cms-static.c b/compositor/cms-static.c
index a6bbfd4..e24501b 100644
--- a/compositor/cms-static.c
+++ b/compositor/cms-static.c
@@ -91,8 +91,8 @@ cms_notifier_destroy(struct wl_listener *listener, void *data)
 
 
 WL_EXPORT int
-module_init(struct weston_compositor *ec,
-	    int *argc, char *argv[])
+wet_module_init(struct weston_compositor *ec,
+		int *argc, char *argv[])
 {
 	struct cms_static *cms;
 	struct weston_output *output;
diff --git a/compositor/main.c b/compositor/main.c
index 4e6b7ae..88f7911 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -704,7 +704,7 @@ weston_create_listening_socket(struct wl_display *display, const char *socket_na
 }
 
 WL_EXPORT void *
-wet_load_module(const char *name, const char *entrypoint)
+wet_load_module_entrypoint(const char *name, const char *entrypoint)
 {
 	const char *builddir = getenv("WESTON_BUILD_DIR");
 	char path[PATH_MAX];
@@ -746,14 +746,46 @@ wet_load_module(const char *name, const char *entrypoint)
 	return init;
 }
 
+static int
+wet_load_shell(struct weston_compositor *compositor,
+	       const char *name, int *argc, char *argv[])
+{
+	int (*shell_init)(struct weston_compositor *ec,
+			  int *argc, char *argv[]);
+
+	shell_init = wet_load_module_entrypoint(name, "wet_shell_init");
+	if (!shell_init)
+		shell_init = wet_load_module_entrypoint(name, "module_init");
+	if (!shell_init)
+		return -1;
+	if (shell_init(compositor, argc, argv) < 0)
+		return -1;
+	return 0;
+}
+
+WL_EXPORT int
+wet_load_module(struct weston_compositor *compositor,
+	        const char *name, int *argc, char *argv[])
+{
+	int (*module_init)(struct weston_compositor *ec,
+			   int *argc, char *argv[]);
+
+	module_init = wet_load_module_entrypoint(name, "wet_module_init");
+	if (!module_init)
+		module_init = wet_load_module_entrypoint(name, "module_init");
+	if (!module_init)
+		return -1;
+	if (module_init(compositor, argc, argv) < 0)
+		return -1;
+	return 0;
+}
+
 static int
 load_modules(struct weston_compositor *ec, const char *modules,
 	     int *argc, char *argv[])
 {
 	const char *p, *end;
 	char buffer[256];
-	int (*module_init)(struct weston_compositor *ec,
-			   int *argc, char *argv[]);
 
 	if (modules == NULL)
 		return 0;
@@ -763,10 +795,7 @@ load_modules(struct weston_compositor *ec, const char *modules,
 		end = strchrnul(p, ',');
 		snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
 
-		module_init = wet_load_module(buffer, "module_init");
-		if (!module_init)
-			return -1;
-		if (module_init(ec, argc, argv) < 0)
+		if (wet_load_module(ec, buffer, argc, argv) < 0)
 			return -1;
 		p = end;
 		while (*p == ',')
@@ -1714,7 +1743,7 @@ int main(int argc, char *argv[])
 			goto out;
 	}
 
-	if (load_modules(ec, shell, &argc, argv) < 0)
+	if (wet_load_shell(ec, shell, &argc, argv) < 0)
 		goto out;
 
 	weston_config_section_get_string(section, "modules", &modules, "");
diff --git a/compositor/screen-share.c b/compositor/screen-share.c
index c9e7436..ccf9f17 100644
--- a/compositor/screen-share.c
+++ b/compositor/screen-share.c
@@ -1105,8 +1105,8 @@ share_output_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t k
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *compositor,
-	    int *argc, char *argv[])
+wet_module_init(struct weston_compositor *compositor,
+		int *argc, char *argv[])
 {
 	struct screen_share *ss;
 	struct weston_config *config = wet_get_config(compositor);
diff --git a/compositor/weston.h b/compositor/weston.h
index bff5cc1..53d2c83 100644
--- a/compositor/weston.h
+++ b/compositor/weston.h
@@ -61,7 +61,18 @@ struct weston_config *
 wet_get_config(struct weston_compositor *compositor);
 
 void *
-wet_load_module(const char *name, const char *entrypoint);
+wet_load_module_entrypoint(const char *name, const char *entrypoint);
+
+int
+wet_shell_init(struct weston_compositor *ec,
+		int *argc, char *argv[]);
+
+int
+wet_module_init(struct weston_compositor *ec,
+		int *argc, char *argv[]);
+int
+wet_load_module(struct weston_compositor *compositor,
+	        const char *name, int *argc, char *argv[]);
 
 int
 wet_load_xwayland(struct weston_compositor *comp);
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index c72f801..2397291 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -6694,8 +6694,8 @@ handle_seat_created(struct wl_listener *listener, void *data)
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *ec,
-	    int *argc, char *argv[])
+wet_shell_init(struct weston_compositor *ec,
+	       int *argc, char *argv[])
 {
 	struct weston_seat *seat;
 	struct desktop_shell *shell;
diff --git a/fullscreen-shell/fullscreen-shell.c b/fullscreen-shell/fullscreen-shell.c
index 2ec2d02..f01346a 100644
--- a/fullscreen-shell/fullscreen-shell.c
+++ b/fullscreen-shell/fullscreen-shell.c
@@ -33,6 +33,7 @@
 #include <assert.h>
 
 #include "compositor.h"
+#include "compositor/weston.h"
 #include "fullscreen-shell-unstable-v1-server-protocol.h"
 #include "shared/helpers.h"
 
@@ -819,8 +820,8 @@ bind_fullscreen_shell(struct wl_client *client, void *data, uint32_t version,
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *compositor,
-	    int *argc, char *argv[])
+wet_shell_init(struct weston_compositor *compositor,
+	       int *argc, char *argv[])
 {
 	struct fullscreen_shell *shell;
 	struct weston_seat *seat;
diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index dec4936..1866321 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -2127,7 +2127,9 @@ load_controller_modules(struct weston_compositor *compositor, const char *module
 		end = strchrnul(p, ',');
 		snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
 
-		controller_module_init = wet_load_module(buffer, "controller_module_init");
+		controller_module_init =
+			wet_load_module_entrypoint(buffer,
+						   "controller_module_init");
 		if (!controller_module_init)
 			return -1;
 
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
index 090ee4d..6d15a67 100644
--- a/ivi-shell/ivi-shell.c
+++ b/ivi-shell/ivi-shell.c
@@ -491,8 +491,8 @@ shell_add_bindings(struct weston_compositor *compositor,
  * Initialization of ivi-shell.
  */
 WL_EXPORT int
-module_init(struct weston_compositor *compositor,
-	    int *argc, char *argv[])
+wet_shell_init(struct weston_compositor *compositor,
+	       int *argc, char *argv[])
 {
 	struct ivi_shell *shell;
 	struct ivi_shell_setting setting = { };
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index f903a3b..c6c975f 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -3261,8 +3261,8 @@ config_init_to_defaults(struct weston_drm_backend_config *config)
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor,
-	     struct weston_backend_config *config_base)
+weston_backend_init(struct weston_compositor *compositor,
+		    struct weston_backend_config *config_base)
 {
 	struct drm_backend *b;
 	struct weston_drm_backend_config config = {{ 0, }};
diff --git a/libweston/compositor-fbdev.c b/libweston/compositor-fbdev.c
index e21ceca..6d4eb9f 100644
--- a/libweston/compositor-fbdev.c
+++ b/libweston/compositor-fbdev.c
@@ -760,8 +760,8 @@ config_init_to_defaults(struct weston_fbdev_backend_config *config)
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor,
-	     struct weston_backend_config *config_base)
+weston_backend_init(struct weston_compositor *compositor,
+		    struct weston_backend_config *config_base)
 {
 	struct fbdev_backend *b;
 	struct weston_fbdev_backend_config config = {{ 0, }};
diff --git a/libweston/compositor-headless.c b/libweston/compositor-headless.c
index 6c22ee3..8a6f083 100644
--- a/libweston/compositor-headless.c
+++ b/libweston/compositor-headless.c
@@ -237,8 +237,8 @@ config_init_to_defaults(struct weston_headless_backend_config *config)
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor,
-	     struct weston_backend_config *config_base)
+weston_backend_init(struct weston_compositor *compositor,
+		    struct weston_backend_config *config_base)
 {
 	struct headless_backend *b;
 	struct weston_headless_backend_config config = {{ 0, }};
diff --git a/libweston/compositor-rdp.c b/libweston/compositor-rdp.c
index d74dd5e..961effb 100644
--- a/libweston/compositor-rdp.c
+++ b/libweston/compositor-rdp.c
@@ -1298,8 +1298,8 @@ config_init_to_defaults(struct weston_rdp_backend_config *config)
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor,
-	     struct weston_backend_config *config_base)
+weston_backend_init(struct weston_compositor *compositor,
+		    struct weston_backend_config *config_base)
 {
 	struct rdp_backend *b;
 	struct weston_rdp_backend_config config = {{ 0, }};
diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 1343e21..3a1f68b 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -2277,8 +2277,8 @@ config_init_to_defaults(struct weston_wayland_backend_config *config)
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor,
-	     struct weston_backend_config *config_base)
+weston_backend_init(struct weston_compositor *compositor,
+		    struct weston_backend_config *config_base)
 {
 	struct wayland_backend *b;
 	struct wayland_output *output;
diff --git a/libweston/compositor-x11.c b/libweston/compositor-x11.c
index e2e6110..27ab606 100644
--- a/libweston/compositor-x11.c
+++ b/libweston/compositor-x11.c
@@ -1706,8 +1706,8 @@ config_init_to_defaults(struct weston_x11_backend_config *config)
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor,
-	     struct weston_backend_config *config_base)
+weston_backend_init(struct weston_compositor *compositor,
+		    struct weston_backend_config *config_base)
 {
 	struct x11_backend *b;
 	struct weston_x11_backend_config config = {{ 0, }};
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 771f1c9..8f30b46 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -5023,7 +5023,9 @@ weston_compositor_load_backend(struct weston_compositor *compositor,
 	if (backend < 0 || backend >= ARRAY_LENGTH(backend_map))
 		return -1;
 
-	backend_init = weston_load_module(backend_map[backend], "backend_init");
+	backend_init = weston_load_module(backend_map[backend], "weston_backend_init");
+	if (!backend_init)
+		backend_init = weston_load_module(backend_map[backend], "backend_init");
 	if (!backend_init)
 		return -1;
 
@@ -5033,14 +5035,19 @@ weston_compositor_load_backend(struct weston_compositor *compositor,
 WL_EXPORT int
 weston_compositor_load_xwayland(struct weston_compositor *compositor)
 {
-	int (*module_init)(struct weston_compositor *ec,
-			   int *argc, char *argv[]);
-	int argc = 0;
+	int (*weston_module_init)(struct weston_compositor *ec);
 
-	module_init = weston_load_module("xwayland.so", "module_init");
-	if (!module_init)
-		return -1;
-	if (module_init(compositor, &argc, NULL) < 0)
+	weston_module_init = weston_load_module("xwayland.so", "weston_module_init");
+	if (!weston_module_init) {
+		int (*module_init)(struct weston_compositor *ec,
+				   int *argc, char *argv[]);
+		int argc = 0;
+
+		module_init = weston_load_module("xwayland.so", "module_init");
+		if (!module_init || module_init(compositor, &argc, NULL) < 0)
+			return -1;
+	} else if (weston_module_init(compositor) < 0) {
 		return -1;
+	}
 	return 0;
 }
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 557d2f5..3fa9b02 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -1676,11 +1676,10 @@ int
 noop_renderer_init(struct weston_compositor *ec);
 
 int
-backend_init(struct weston_compositor *c,
-	     struct weston_backend_config *config_base);
+weston_backend_init(struct weston_compositor *c,
+		    struct weston_backend_config *config_base);
 int
-module_init(struct weston_compositor *compositor,
-	    int *argc, char *argv[]);
+weston_module_init(struct weston_compositor *compositor);
 
 void
 weston_transformed_coord(int width, int height,
diff --git a/tests/plugin-registry-test.c b/tests/plugin-registry-test.c
index 7fc88f3..81e26cd 100644
--- a/tests/plugin-registry-test.c
+++ b/tests/plugin-registry-test.c
@@ -28,6 +28,7 @@
 #include <assert.h>
 
 #include "compositor.h"
+#include "compositor/weston.h"
 #include "plugin-registry.h"
 
 static void
@@ -88,7 +89,8 @@ runtime_tests(void *data)
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *compositor, int *argc, char *argv[])
+wet_module_init(struct weston_compositor *compositor,
+		int *argc, char *argv[])
 {
 	struct wl_event_loop *loop;
 
diff --git a/tests/surface-global-test.c b/tests/surface-global-test.c
index b0a1d1c..ab5efd1 100644
--- a/tests/surface-global-test.c
+++ b/tests/surface-global-test.c
@@ -28,6 +28,7 @@
 #include <assert.h>
 
 #include "compositor.h"
+#include "compositor/weston.h"
 
 static void
 surface_to_from_global(void *data)
@@ -78,7 +79,8 @@ surface_to_from_global(void *data)
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *compositor, int *argc, char *argv[])
+wet_module_init(struct weston_compositor *compositor,
+		int *argc, char *argv[])
 {
 	struct wl_event_loop *loop;
 
diff --git a/tests/surface-screenshot.c b/tests/surface-screenshot.c
index 703d48b..e5510e5 100644
--- a/tests/surface-screenshot.c
+++ b/tests/surface-screenshot.c
@@ -33,6 +33,7 @@
 #include <linux/input.h>
 
 #include "compositor.h"
+#include "compositor/weston.h"
 #include "file-util.h"
 
 static char *
@@ -212,8 +213,8 @@ out:
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *ec,
-	    int *argc, char *argv[])
+wet_module_init(struct weston_compositor *ec,
+		int *argc, char *argv[])
 {
 	weston_compositor_add_debug_binding(ec, KEY_H, trigger_binding, ec);
 
diff --git a/tests/surface-test.c b/tests/surface-test.c
index 243f8dc..28520aa 100644
--- a/tests/surface-test.c
+++ b/tests/surface-test.c
@@ -29,6 +29,7 @@
 #include <assert.h>
 
 #include "compositor.h"
+#include "compositor/weston.h"
 
 static void
 surface_transform(void *data)
@@ -60,7 +61,8 @@ surface_transform(void *data)
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *compositor, int *argc, char *argv[])
+wet_module_init(struct weston_compositor *compositor,
+		int *argc, char *argv[])
 {
 	struct wl_event_loop *loop;
 
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 09d8b5e..b4d75df 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -584,8 +584,8 @@ idle_launch_client(void *data)
 }
 
 WL_EXPORT int
-module_init(struct weston_compositor *ec,
-	    int *argc, char *argv[])
+wet_module_init(struct weston_compositor *ec,
+		int *argc, char *argv[])
 {
 	struct weston_test *test;
 	struct wl_event_loop *loop;
diff --git a/xwayland/launcher.c b/xwayland/launcher.c
index 614ef5b..3f8da49 100644
--- a/xwayland/launcher.c
+++ b/xwayland/launcher.c
@@ -342,8 +342,7 @@ const struct weston_xwayland_api api = {
 };
 
 WL_EXPORT int
-module_init(struct weston_compositor *compositor,
-	    int *argc, char *argv[])
+weston_module_init(struct weston_compositor *compositor)
 
 {
 	struct wl_display *display = compositor->wl_display;
-- 
2.9.0



More information about the wayland-devel mailing list