Skip to content

Commit

Permalink
Override the plugins path with an environment variable...
Browse files Browse the repository at this point in the history
...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().
  • Loading branch information
Rémi Denis-Courmont committed Feb 12, 2011
1 parent 06028f4 commit 549ce2c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
7 changes: 2 additions & 5 deletions bin/cachegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions bin/vlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions extras/analyser/zsh_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/libvlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions src/modules/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion test/libvlc/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ static const char * test_defaults_args[] = {
"-I",
"dummy",
"--no-media-library",
"--plugin-path=../modules",
"--vout=dummy",
"--aout=dummy"
};
Expand All @@ -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 */

0 comments on commit 549ce2c

Please sign in to comment.