[PATCH weston v2 2/4] weston: Allow relative paths for modules

Pekka Paalanen ppaalanen at gmail.com
Fri Jun 7 06:43:09 PDT 2013


On Fri,  7 Jun 2013 10:46:42 +0200
Quentin Glidic <sardemff7+wayland at sardemff7.net> wrote:

> From: Quentin Glidic <sardemff7+git at sardemff7.net>
> 
> This is to be used by tests or when developping to load modules directly
> from the build tree
> 
> Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
> ---
>  man/weston.man   | 5 +++--
>  src/compositor.c | 9 ++++++---
>  2 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/man/weston.man b/man/weston.man
> index 39d854b..50c8ba1 100644
> --- a/man/weston.man
> +++ b/man/weston.man
> @@ -99,7 +99,8 @@ Load
>  .I backend.so
>  instead of the default backend. The file is searched for in
>  .IR "__weston_modules_dir__" ,
> -or you can pass an absolute path. The default backend is 
> +or you can pass a path (absolute, .-relative or ..-relative). The default 
> +backend is

"or you can pass a path starting with /, ./, or ../." with the
appropriate font effects. Would that be more clear?

>  .I __weston_native_backend__
>  unless the environment suggests otherwise, see
>  .IR DISPLAY " and " WAYLAND_DISPLAY .
> @@ -128,7 +129,7 @@ instead of writing them to stderr.
>  Load the comma-separated list of modules. Only used by the test
>  suite. The file is searched for in
>  .IR "__weston_modules_dir__" ,
> -or you can pass an absolute path.
> +or you can pass a path (absolute, .-relative or ..-relative).
>  .TP
>  \fB\-\^S\fR\fIname\fR, \fB\-\-socket\fR=\fIname\fR
>  Weston will listen in the Wayland socket called
> diff --git a/src/compositor.c b/src/compositor.c
> index 099600d..1096d81 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -3019,10 +3019,13 @@ load_module(const char *name, const char *entrypoint)
>  	char path[PATH_MAX];
>  	void *module, *init;
>  
> -	if (name[0] != '/')
> -		snprintf(path, sizeof path, "%s/%s", MODULEDIR, name);
> +	if (name[0] == '/' || /* If the path is absolute or .. */
> +	    (name[0] == '.' && /* ... relative to ... */
> +	     (name[1] == '/' || /* ... current dir or ... */
> +	      (name[1] == '.' && name[2] == '/')))) /* ... parent dir ... */
> +		snprintf(path, sizeof path, "%s", name); /* ... load the exact specified module */
>  	else
> -		snprintf(path, sizeof path, "%s", name);
> +		snprintf(path, sizeof path, "%s/%s", MODULEDIR, name);
>  
>  	module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
>  	if (module) {

Hi Quentin,

do we expect to load modules from subdirs under MODULEDIR ever?

If not, I think this could be simplified to just scan the name for a
'/', and if there is one use the name as is, and if there is not then
prepend MODULEDIR.

That would make the documentation a bit more easy to read, too.

Anyway, this looks like it would work, too.


Thanks,
pq


More information about the wayland-devel mailing list