[vlc-commits] Override the plugins path with an environment variable...

Rémi Denis-Courmont git at videolan.org
Sat Feb 12 10:06:28 CET 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb 12 11:00:03 2011 +0200| [549ce2cad17e4cae5125ae0d7f2b23cbff34b8d9] | committer: Rémi Denis-Courmont

Override the plugins path with an environment variable...

...rather than with a command line option. This enables extending the
set of plugins paths globally, for all LibVLC applications.

Using an environment variable seems more logical than a command line
option considering that the module bank is shared by all VLC instances
in the process. In other words, it did not belong as a parameter to
libvlc_new().

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=549ce2cad17e4cae5125ae0d7f2b23cbff34b8d9
---

 bin/cachegen.c                    |    7 ++-----
 bin/vlc.c                         |    9 +++++----
 extras/analyser/zsh_completion.sh |    9 ++++++---
 src/libvlc.c                      |    3 +--
 src/modules/modules.c             |    8 ++++++--
 test/libvlc/test.h                |    2 +-
 6 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/bin/cachegen.c b/bin/cachegen.c
index e73e4a5..6fef55d 100644
--- a/bin/cachegen.c
+++ b/bin/cachegen.c
@@ -91,25 +91,22 @@ int main (int argc, char *argv[])
     {
         /* Note that FromLocale() can be used before libvlc is initialized */
         const char *path = FromLocale (argv[i]);
-        char *arg;
 
-        if (asprintf (&arg, "--plugin-path=%s", path) == -1)
+        if (setenv ("VLC_PLUGIN_PATH", path, 1))
             abort ();
 
-        const char *vlc_argv[5];
+        const char *vlc_argv[4];
         int vlc_argc = 0;
 
         vlc_argv[vlc_argc++] = "--quiet";
         if (force)
             vlc_argv[vlc_argc++] = "--reset-plugins-cache";
-        vlc_argv[vlc_argc++] = arg;
         vlc_argv[vlc_argc++] = "--"; /* end of options */
         vlc_argv[vlc_argc] = NULL;
 
         libvlc_instance_t *vlc = libvlc_new (vlc_argc, vlc_argv);
         if (vlc != NULL)
             libvlc_release (vlc);
-        free (arg);
         if (vlc == NULL)
             fprintf (stderr, "No plugins in %s\n", path);
         LocaleFree (path);
diff --git a/bin/vlc.c b/bin/vlc.c
index 3a49287..4299bdf 100644
--- a/bin/vlc.c
+++ b/bin/vlc.c
@@ -100,6 +100,10 @@ int main( int i_argc, const char *ppsz_argv[] )
     setenv ("GNOME_DISABLE_CRASH_DIALOG", "1", 1);
 # endif
 
+# ifdef TOP_BUILDDIR
+    setenv ("VLC_PLUGIN_PATH", TOP_BUILDDIR"/modules", 1);
+# endif
+
     /* Clear the X.Org startup notification ID. Otherwise the UI might try to
      * change the environment while the process is multi-threaded. That could
      * crash. Screw you X.Org. Next time write a thread-safe specification. */
@@ -174,14 +178,11 @@ int main( int i_argc, const char *ppsz_argv[] )
     pthread_sigmask (SIG_SETMASK, &set, NULL);
 
     /* Note that FromLocale() can be used before libvlc is initialized */
-    const char *argv[i_argc + 4];
+    const char *argv[i_argc + 3];
     int argc = 0;
 
     argv[argc++] = "--no-ignore-config";
     argv[argc++] = "--media-library";
-#ifdef TOP_BUILDDIR
-    argv[argc++] = FromLocale ("--plugin-path="TOP_BUILDDIR"/modules");
-#endif
 #ifdef TOP_SRCDIR
     argv[argc++] = FromLocale ("--data-path="TOP_SRCDIR"/share");
 #endif
diff --git a/extras/analyser/zsh_completion.sh b/extras/analyser/zsh_completion.sh
index d901b1c..f10f4bf 100755
--- a/extras/analyser/zsh_completion.sh
+++ b/extras/analyser/zsh_completion.sh
@@ -22,6 +22,9 @@ esac
 #Distributors can run BUILDDIR=XXX ./zsh_completion.sh
 [ -z "$BUILDDIR" ] && BUILDDIR=../../
 
+VLC_PLUGIN_PATH="$BUILDDIR"
+export VLC_PLUGIN_PATH
+
 function find_libvlc {
     [ -z "$SUFFIX" ] && return 0 # linking will fail if lib isn't found
     for i in $BUILDDIR/src/.libs/libvlc.$SUFFIX $BUILDDIR/src/libvlc.$SUFFIX; do
@@ -66,15 +69,15 @@ eval $ZSH_BUILD || exit 1
 
 printf "Generating zsh completion in _vlc ... "
 
-if ! ./zsh_gen --plugin-path=$BUILDDIR >_vlc 2>/dev/null; then
+if ! ./zsh_gen >_vlc 2>/dev/null; then
     echo "
 ERROR: the generation failed.... :(
 Please press enter to verify that all the VLC modules are shown"
     read i
-    ./zsh_gen --plugin-path=$BUILDDIR -vv --list
+    ./zsh_gen -vv --list
     echo "
 If they are shown, press enter to see if you can debug the problem
-It will be reproduced by running \"./zsh_gen --plugin-path=$BUILDDIR -vvv\""
+It will be reproduced by running \"./zsh_gen -vvv\""
     read i
     ./zsh_gen --plugin-path=$BUILDDIR -vv
     exit 1
diff --git a/src/libvlc.c b/src/libvlc.c
index f0cec42..53775ce 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -473,8 +473,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 
     if( module_count <= 1 )
     {
-        msg_Err( p_libvlc, "No modules were found, refusing to start. Check "
-                "that you properly gave a module path with --plugin-path.");
+        msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
         b_exit = true;
         i_ret = VLC_ENOITEM;
     }
diff --git a/src/modules/modules.c b/src/modules/modules.c
index d9d19de..aa758d7 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -853,10 +853,14 @@ static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
     }
 
     /* If the user provided a plugin path, we add it to the list */
-    paths = var_InheritString( p_this, "plugin-path" );
+    paths = getenv( "VLC_PLUGIN_PATH" );
     if( paths == NULL )
         return;
 
+    paths = strdup( paths ); /* don't harm the environment ! :) */
+    if( unlikely(paths == NULL) )
+        return;
+
     for( char *buf, *path = strtok_r( paths, PATH_SEP, &buf );
          path != NULL;
          path = strtok_r( NULL, PATH_SEP, &buf ) )
@@ -966,7 +970,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
         p_module = p_cache_entry->p_module;
         p_module->b_loaded = false;
 
-        /* If plugin-path contains duplicate entries... */
+        /* If VLC_PLUGIN_PATH contains duplicate entries... */
         if( p_module->next != NULL )
             return 0; /* already taken care of that one */
 
diff --git a/test/libvlc/test.h b/test/libvlc/test.h
index 2a6c84b..fc41f51 100644
--- a/test/libvlc/test.h
+++ b/test/libvlc/test.h
@@ -53,7 +53,6 @@ static const char * test_defaults_args[] = {
     "-I",
     "dummy",
     "--no-media-library",
-    "--plugin-path=../modules",
     "--vout=dummy",
     "--aout=dummy"
 };
@@ -75,6 +74,7 @@ static inline void test_init (void)
 {
     (void)test_default_sample; /* This one may not be used */
     alarm (10); /* Make sure "make check" does not get stuck */
+    setenv( "VLC_PLUGIN_PATH", "../modules", 1 );
 }
 
 #endif /* TEST_H */



More information about the vlc-commits mailing list