Commit b8247ace authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Make the config file lock per process rather than per instance

parent 2085be2a
...@@ -410,7 +410,6 @@ static int config_PrepareDir (vlc_object_t *obj) ...@@ -410,7 +410,6 @@ static int config_PrepareDir (vlc_object_t *obj)
static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
bool b_autosave ) bool b_autosave )
{ {
libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
module_t *p_parser; module_t *p_parser;
FILE *file = NULL; FILE *file = NULL;
char *permanent = NULL, *temporary = NULL; char *permanent = NULL, *temporary = NULL;
...@@ -420,9 +419,6 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -420,9 +419,6 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
bool b_backup; bool b_backup;
int i_index; int i_index;
/* Acquire config file lock */
vlc_mutex_lock( &priv->config_lock );
if( config_PrepareDir( p_this ) ) if( config_PrepareDir( p_this ) )
{ {
msg_Err( p_this, "no configuration directory" ); msg_Err( p_this, "no configuration directory" );
...@@ -521,9 +517,15 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -521,9 +517,15 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
goto error; goto error;
} }
/* The temporary configuration file is per-PID. Therefore SaveConfigFile()
* should be serialized against itself within a given process. */
static vlc_mutex_t lock = VLC_STATIC_MUTEX;
vlc_mutex_lock (&lock);
int fd = utf8_open (temporary, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR); int fd = utf8_open (temporary, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd == -1) if (fd == -1)
{ {
vlc_mutex_unlock (&lock);
module_list_free (list); module_list_free (list);
goto error; goto error;
} }
...@@ -531,6 +533,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -531,6 +533,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
if (file == NULL) if (file == NULL)
{ {
close (fd); close (fd);
vlc_mutex_unlock (&lock);
module_list_free (list); module_list_free (list);
goto error; goto error;
} }
...@@ -672,13 +675,14 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -672,13 +675,14 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
rename (temporary, permanent); rename (temporary, permanent);
/* (...then synchronize the directory, err, TODO...) */ /* (...then synchronize the directory, err, TODO...) */
/* ...and finally close the file */ /* ...and finally close the file */
vlc_mutex_unlock (&lock);
#endif #endif
vlc_mutex_unlock (&priv->config_lock);
fclose (file); fclose (file);
#ifdef WIN32 #ifdef WIN32
/* Windows cannot remove open files nor overwrite existing ones */ /* Windows cannot remove open files nor overwrite existing ones */
remove (permanent); remove (permanent);
rename (temporary, permanent); rename (temporary, permanent);
vlc_mutex_unlock (&lock);
#endif #endif
free (temporary); free (temporary);
...@@ -688,7 +692,6 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name, ...@@ -688,7 +692,6 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
error: error:
if( file ) if( file )
fclose( file ); fclose( file );
vlc_mutex_unlock( &priv->config_lock );
free (temporary); free (temporary);
free (permanent); free (permanent);
free( p_bigbuffer ); free( p_bigbuffer );
......
...@@ -282,7 +282,6 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -282,7 +282,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
/* Initialize mutexes */ /* Initialize mutexes */
vlc_mutex_init( &priv->timer_lock ); vlc_mutex_init( &priv->timer_lock );
vlc_mutex_init( &priv->config_lock );
vlc_cond_init( &priv->exiting ); vlc_cond_init( &priv->exiting );
return p_libvlc; return p_libvlc;
...@@ -1130,7 +1129,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) ...@@ -1130,7 +1129,6 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
/* Destroy mutexes */ /* Destroy mutexes */
vlc_cond_destroy( &priv->exiting ); vlc_cond_destroy( &priv->exiting );
vlc_mutex_destroy( &priv->config_lock );
vlc_mutex_destroy( &priv->timer_lock ); vlc_mutex_destroy( &priv->timer_lock );
#ifndef NDEBUG /* Hack to dump leaked objects tree */ #ifndef NDEBUG /* Hack to dump leaked objects tree */
......
...@@ -201,9 +201,6 @@ typedef struct libvlc_priv_t ...@@ -201,9 +201,6 @@ typedef struct libvlc_priv_t
libvlc_int_t public_data; libvlc_int_t public_data;
vlc_cond_t exiting; ///< signaled when VLC wants to exit vlc_cond_t exiting; ///< signaled when VLC wants to exit
/* Configuration */
vlc_mutex_t config_lock; ///< config file lock
int i_last_input_id ; ///< Last id of input item int i_last_input_id ; ///< Last id of input item
/* Messages */ /* Messages */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment