From 08539a08958f2fdab6fbf01723d76db8dd4eddbe Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 15 Oct 2014 10:57:08 +0200 Subject: [PATCH] atomically sync the lpconfig on disk --- coreapi/lpconfig.c | 7 ++++++- coreapi/misc.c | 2 ++ mediastreamer2 | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index c1ffea0fc..5c556acc7 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -77,6 +77,7 @@ struct _LpConfig{ int refcnt; FILE *file; char *filename; + char *tmpfilename; MSList *sections; int modified; int readonly; @@ -349,6 +350,7 @@ LpConfig *lp_config_new_with_factory(const char *config_filename, const char *fa if (config_filename!=NULL){ ms_message("Using (r/w) config information from %s", config_filename); lpconfig->filename=ortp_strdup(config_filename); + lpconfig->tmpfilename=ortp_strdup_printf("%s.tmp",config_filename); lpconfig->file=fopen(config_filename,"r+"); if (lpconfig->file!=NULL){ lp_config_parse(lpconfig,lpconfig->file); @@ -583,7 +585,7 @@ int lp_config_sync(LpConfig *lpconfig){ /* don't create group/world-accessible files */ (void) umask(S_IRWXG | S_IRWXO); #endif - file=fopen(lpconfig->filename,"w"); + file=fopen(lpconfig->tmpfilename,"w"); if (file==NULL){ ms_warning("Could not write %s ! Maybe it is read-only. Configuration will not be saved.",lpconfig->filename); lpconfig->readonly=1; @@ -591,6 +593,9 @@ int lp_config_sync(LpConfig *lpconfig){ } ms_list_for_each2(lpconfig->sections,(void (*)(void *,void*))lp_section_write,(void *)file); fclose(file); + if (rename(lpconfig->tmpfilename,lpconfig->filename)!=0){ + ms_error("Cannot rename %s into %s: %s",lpconfig->tmpfilename,lpconfig->filename,strerror(errno)); + } lpconfig->modified=0; return 0; } diff --git a/coreapi/misc.c b/coreapi/misc.c index 30100a304..c89111333 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -966,6 +966,8 @@ unsigned int linphone_core_get_audio_features(LinphoneCore *lc){ else if (strcasecmp(name,"DTMF")==0) ret|=AUDIO_STREAM_FEATURE_DTMF; else if (strcasecmp(name,"DTMF_ECHO")==0) ret|=AUDIO_STREAM_FEATURE_DTMF_ECHO; else if (strcasecmp(name,"MIXED_RECORDING")==0) ret|=AUDIO_STREAM_FEATURE_MIXED_RECORDING; + else if (strcasecmp(name,"LOCAL_PLAYING")==0) ret|=AUDIO_STREAM_FEATURE_LOCAL_PLAYING; + else if (strcasecmp(name,"REMOTE_PLAYING")==0) ret|=AUDIO_STREAM_FEATURE_REMOTE_PLAYING; else if (strcasecmp(name,"ALL")==0) ret|=AUDIO_STREAM_FEATURE_ALL; else if (strcasecmp(name,"NONE")==0) ret=0; else ms_error("Unsupported audio feature %s requested in config file.",name); diff --git a/mediastreamer2 b/mediastreamer2 index c45dca7be..2054fd609 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit c45dca7bedea220fe3bc718b89bd36a21c97fa2f +Subproject commit 2054fd60911b585458b62d52092894a5d1b59503