Commit 08539a08 authored by Simon Morlat's avatar Simon Morlat

atomically sync the lpconfig on disk

parent a7d81a11
...@@ -77,6 +77,7 @@ struct _LpConfig{ ...@@ -77,6 +77,7 @@ struct _LpConfig{
int refcnt; int refcnt;
FILE *file; FILE *file;
char *filename; char *filename;
char *tmpfilename;
MSList *sections; MSList *sections;
int modified; int modified;
int readonly; int readonly;
...@@ -349,6 +350,7 @@ LpConfig *lp_config_new_with_factory(const char *config_filename, const char *fa ...@@ -349,6 +350,7 @@ LpConfig *lp_config_new_with_factory(const char *config_filename, const char *fa
if (config_filename!=NULL){ if (config_filename!=NULL){
ms_message("Using (r/w) config information from %s", config_filename); ms_message("Using (r/w) config information from %s", config_filename);
lpconfig->filename=ortp_strdup(config_filename); lpconfig->filename=ortp_strdup(config_filename);
lpconfig->tmpfilename=ortp_strdup_printf("%s.tmp",config_filename);
lpconfig->file=fopen(config_filename,"r+"); lpconfig->file=fopen(config_filename,"r+");
if (lpconfig->file!=NULL){ if (lpconfig->file!=NULL){
lp_config_parse(lpconfig,lpconfig->file); lp_config_parse(lpconfig,lpconfig->file);
...@@ -583,7 +585,7 @@ int lp_config_sync(LpConfig *lpconfig){ ...@@ -583,7 +585,7 @@ int lp_config_sync(LpConfig *lpconfig){
/* don't create group/world-accessible files */ /* don't create group/world-accessible files */
(void) umask(S_IRWXG | S_IRWXO); (void) umask(S_IRWXG | S_IRWXO);
#endif #endif
file=fopen(lpconfig->filename,"w"); file=fopen(lpconfig->tmpfilename,"w");
if (file==NULL){ if (file==NULL){
ms_warning("Could not write %s ! Maybe it is read-only. Configuration will not be saved.",lpconfig->filename); ms_warning("Could not write %s ! Maybe it is read-only. Configuration will not be saved.",lpconfig->filename);
lpconfig->readonly=1; lpconfig->readonly=1;
...@@ -591,6 +593,9 @@ int lp_config_sync(LpConfig *lpconfig){ ...@@ -591,6 +593,9 @@ int lp_config_sync(LpConfig *lpconfig){
} }
ms_list_for_each2(lpconfig->sections,(void (*)(void *,void*))lp_section_write,(void *)file); ms_list_for_each2(lpconfig->sections,(void (*)(void *,void*))lp_section_write,(void *)file);
fclose(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; lpconfig->modified=0;
return 0; return 0;
} }
......
...@@ -966,6 +966,8 @@ unsigned int linphone_core_get_audio_features(LinphoneCore *lc){ ...@@ -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")==0) ret|=AUDIO_STREAM_FEATURE_DTMF;
else if (strcasecmp(name,"DTMF_ECHO")==0) ret|=AUDIO_STREAM_FEATURE_DTMF_ECHO; 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,"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,"ALL")==0) ret|=AUDIO_STREAM_FEATURE_ALL;
else if (strcasecmp(name,"NONE")==0) ret=0; else if (strcasecmp(name,"NONE")==0) ret=0;
else ms_error("Unsupported audio feature %s requested in config file.",name); else ms_error("Unsupported audio feature %s requested in config file.",name);
......
mediastreamer2 @ 2054fd60
Subproject commit c45dca7bedea220fe3bc718b89bd36a21c97fa2f Subproject commit 2054fd60911b585458b62d52092894a5d1b59503
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