compositor: Use weston_load_module
Except the module dir path, they're one and the same. This change warrants a libweston version bump, if it hasn't been done already. Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
parent
21deaee6a9
commit
eaf2de3441
@ -883,53 +883,6 @@ weston_create_listening_socket(struct wl_display *display, const char *socket_na
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void *
|
|
||||||
wet_load_module_entrypoint(const char *name, const char *entrypoint)
|
|
||||||
{
|
|
||||||
char path[PATH_MAX];
|
|
||||||
void *module, *init;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (name == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (name[0] != '/') {
|
|
||||||
len = weston_module_path_from_env(name, path, sizeof path);
|
|
||||||
if (len == 0)
|
|
||||||
len = snprintf(path, sizeof path, "%s/%s", MODULEDIR,
|
|
||||||
name);
|
|
||||||
} else {
|
|
||||||
len = snprintf(path, sizeof path, "%s", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* snprintf returns the length of the string it would've written,
|
|
||||||
* _excluding_ the NUL byte. So even being equal to the size of
|
|
||||||
* our buffer is an error here. */
|
|
||||||
if (len >= sizeof path)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
|
|
||||||
if (module) {
|
|
||||||
weston_log("Module '%s' already loaded\n", path);
|
|
||||||
} else {
|
|
||||||
weston_log("Loading module '%s'\n", path);
|
|
||||||
module = dlopen(path, RTLD_NOW);
|
|
||||||
if (!module) {
|
|
||||||
weston_log("Failed to load module: %s\n", dlerror());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init = dlsym(module, entrypoint);
|
|
||||||
if (!init) {
|
|
||||||
weston_log("Failed to lookup init function: %s\n", dlerror());
|
|
||||||
dlclose(module);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return init;
|
|
||||||
}
|
|
||||||
|
|
||||||
WL_EXPORT int
|
WL_EXPORT int
|
||||||
wet_load_module(struct weston_compositor *compositor,
|
wet_load_module(struct weston_compositor *compositor,
|
||||||
const char *name, int *argc, char *argv[])
|
const char *name, int *argc, char *argv[])
|
||||||
@ -937,7 +890,7 @@ wet_load_module(struct weston_compositor *compositor,
|
|||||||
int (*module_init)(struct weston_compositor *ec,
|
int (*module_init)(struct weston_compositor *ec,
|
||||||
int *argc, char *argv[]);
|
int *argc, char *argv[]);
|
||||||
|
|
||||||
module_init = wet_load_module_entrypoint(name, "wet_module_init");
|
module_init = weston_load_module(name, "wet_module_init", MODULEDIR);
|
||||||
if (!module_init)
|
if (!module_init)
|
||||||
return -1;
|
return -1;
|
||||||
if (module_init(compositor, argc, argv) < 0)
|
if (module_init(compositor, argc, argv) < 0)
|
||||||
@ -952,7 +905,7 @@ wet_load_shell(struct weston_compositor *compositor,
|
|||||||
int (*shell_init)(struct weston_compositor *ec,
|
int (*shell_init)(struct weston_compositor *ec,
|
||||||
int *argc, char *argv[]);
|
int *argc, char *argv[]);
|
||||||
|
|
||||||
shell_init = wet_load_module_entrypoint(name, "wet_shell_init");
|
shell_init = weston_load_module(name, "wet_shell_init", MODULEDIR);
|
||||||
if (!shell_init)
|
if (!shell_init)
|
||||||
return -1;
|
return -1;
|
||||||
if (shell_init(compositor, argc, argv) < 0)
|
if (shell_init(compositor, argc, argv) < 0)
|
||||||
@ -2729,7 +2682,8 @@ load_remoting(struct weston_compositor *c, struct weston_config *wc)
|
|||||||
&module_name,
|
&module_name,
|
||||||
"remoting-plugin.so");
|
"remoting-plugin.so");
|
||||||
module_init = weston_load_module(module_name,
|
module_init = weston_load_module(module_name,
|
||||||
"weston_module_init");
|
"weston_module_init",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
free(module_name);
|
free(module_name);
|
||||||
if (!module_init) {
|
if (!module_init) {
|
||||||
weston_log("Can't load remoting-plugin\n");
|
weston_log("Can't load remoting-plugin\n");
|
||||||
@ -2859,7 +2813,8 @@ load_pipewire(struct weston_compositor *c, struct weston_config *wc)
|
|||||||
&module_name,
|
&module_name,
|
||||||
"pipewire-plugin.so");
|
"pipewire-plugin.so");
|
||||||
module_init = weston_load_module(module_name,
|
module_init = weston_load_module(module_name,
|
||||||
"weston_module_init");
|
"weston_module_init",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
free(module_name);
|
free(module_name);
|
||||||
if (!module_init) {
|
if (!module_init) {
|
||||||
weston_log("Can't load pipewire-plugin\n");
|
weston_log("Can't load pipewire-plugin\n");
|
||||||
|
@ -62,9 +62,6 @@ wet_watch_process(struct weston_compositor *compositor,
|
|||||||
struct weston_config *
|
struct weston_config *
|
||||||
wet_get_config(struct weston_compositor *compositor);
|
wet_get_config(struct weston_compositor *compositor);
|
||||||
|
|
||||||
void *
|
|
||||||
wet_load_module_entrypoint(const char *name, const char *entrypoint);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
wet_shell_init(struct weston_compositor *ec,
|
wet_shell_init(struct weston_compositor *ec,
|
||||||
int *argc, char *argv[]);
|
int *argc, char *argv[]);
|
||||||
|
@ -2156,7 +2156,7 @@ int
|
|||||||
weston_module_init(struct weston_compositor *compositor);
|
weston_module_init(struct weston_compositor *compositor);
|
||||||
|
|
||||||
void *
|
void *
|
||||||
weston_load_module(const char *name, const char *entrypoint);
|
weston_load_module(const char *name, const char *entrypoint, const char *module_dir);
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
weston_module_path_from_env(const char *name, char *path, size_t path_len);
|
weston_module_path_from_env(const char *name, char *path, size_t path_len);
|
||||||
|
@ -52,7 +52,8 @@ create_gbm_device(int fd)
|
|||||||
struct gbm_device *gbm;
|
struct gbm_device *gbm;
|
||||||
|
|
||||||
gl_renderer = weston_load_module("gl-renderer.so",
|
gl_renderer = weston_load_module("gl-renderer.so",
|
||||||
"gl_renderer_interface");
|
"gl_renderer_interface",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
if (!gl_renderer)
|
if (!gl_renderer)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -440,7 +440,9 @@ headless_gl_renderer_init(struct headless_backend *b)
|
|||||||
.drm_formats_count = ARRAY_LENGTH(headless_formats),
|
.drm_formats_count = ARRAY_LENGTH(headless_formats),
|
||||||
};
|
};
|
||||||
|
|
||||||
b->glri = weston_load_module("gl-renderer.so", "gl_renderer_interface");
|
b->glri = weston_load_module("gl-renderer.so",
|
||||||
|
"gl_renderer_interface",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
if (!b->glri)
|
if (!b->glri)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -2857,7 +2857,8 @@ wayland_backend_create(struct weston_compositor *compositor,
|
|||||||
|
|
||||||
if (!b->use_pixman) {
|
if (!b->use_pixman) {
|
||||||
gl_renderer = weston_load_module("gl-renderer.so",
|
gl_renderer = weston_load_module("gl-renderer.so",
|
||||||
"gl_renderer_interface");
|
"gl_renderer_interface",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
if (!gl_renderer)
|
if (!gl_renderer)
|
||||||
b->use_pixman = true;
|
b->use_pixman = true;
|
||||||
}
|
}
|
||||||
|
@ -1853,7 +1853,8 @@ init_gl_renderer(struct x11_backend *b)
|
|||||||
};
|
};
|
||||||
|
|
||||||
gl_renderer = weston_load_module("gl-renderer.so",
|
gl_renderer = weston_load_module("gl-renderer.so",
|
||||||
"gl_renderer_interface");
|
"gl_renderer_interface",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
if (!gl_renderer)
|
if (!gl_renderer)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -8512,8 +8512,23 @@ weston_module_path_from_env(const char *name, char *path, size_t path_len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A wrapper function to open and return the entry point of a shared library
|
||||||
|
* module
|
||||||
|
*
|
||||||
|
* This function loads the module and provides the caller with the entry point
|
||||||
|
* address which can be later used to execute shared library code. It can be
|
||||||
|
* used to load-up libweston modules but also other modules, specific to the
|
||||||
|
* compositor (i.e., weston).
|
||||||
|
*
|
||||||
|
* \param name the name of the shared library
|
||||||
|
* \param entrypoint the entry point of the shared library
|
||||||
|
* \param module_dir the path where to look for the shared library module
|
||||||
|
* \return the address of the module specified the entry point, or NULL otherwise
|
||||||
|
*
|
||||||
|
*/
|
||||||
WL_EXPORT void *
|
WL_EXPORT void *
|
||||||
weston_load_module(const char *name, const char *entrypoint)
|
weston_load_module(const char *name, const char *entrypoint,
|
||||||
|
const char *module_dir)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
void *module, *init;
|
void *module, *init;
|
||||||
@ -8526,7 +8541,7 @@ weston_load_module(const char *name, const char *entrypoint)
|
|||||||
len = weston_module_path_from_env(name, path, sizeof path);
|
len = weston_module_path_from_env(name, path, sizeof path);
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
len = snprintf(path, sizeof path, "%s/%s",
|
len = snprintf(path, sizeof path, "%s/%s",
|
||||||
LIBWESTON_MODULEDIR, name);
|
module_dir, name);
|
||||||
} else {
|
} else {
|
||||||
len = snprintf(path, sizeof path, "%s", name);
|
len = snprintf(path, sizeof path, "%s", name);
|
||||||
}
|
}
|
||||||
@ -8708,7 +8723,9 @@ weston_compositor_load_backend(struct weston_compositor *compositor,
|
|||||||
if (backend >= ARRAY_LENGTH(backend_map))
|
if (backend >= ARRAY_LENGTH(backend_map))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
backend_init = weston_load_module(backend_map[backend], "weston_backend_init");
|
backend_init = weston_load_module(backend_map[backend],
|
||||||
|
"weston_backend_init",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
if (!backend_init)
|
if (!backend_init)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -8741,7 +8758,9 @@ weston_compositor_load_xwayland(struct weston_compositor *compositor)
|
|||||||
{
|
{
|
||||||
int (*module_init)(struct weston_compositor *ec);
|
int (*module_init)(struct weston_compositor *ec);
|
||||||
|
|
||||||
module_init = weston_load_module("xwayland.so", "weston_module_init");
|
module_init = weston_load_module("xwayland.so",
|
||||||
|
"weston_module_init",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
if (!module_init)
|
if (!module_init)
|
||||||
return -1;
|
return -1;
|
||||||
if (module_init(compositor) < 0)
|
if (module_init(compositor) < 0)
|
||||||
@ -8769,7 +8788,9 @@ weston_compositor_load_color_manager(struct weston_compositor *compositor)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cm_create = weston_load_module("color-lcms.so", "weston_color_manager_create");
|
cm_create = weston_load_module("color-lcms.so",
|
||||||
|
"weston_color_manager_create",
|
||||||
|
LIBWESTON_MODULEDIR);
|
||||||
if (!cm_create) {
|
if (!cm_create) {
|
||||||
weston_log("Error: Could not load color-lcms.so.\n");
|
weston_log("Error: Could not load color-lcms.so.\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user