]> code.delx.au - pulseaudio/blobdiff - src/modules/module-volume-restore.c
* split pa_cstrerror() into its own file polypcore/core-error.[ch]
[pulseaudio] / src / modules / module-volume-restore.c
index b4606bc3efb1f44d9479741c3e956128605ff1b0..435f0c9650d182e1f888a756bc6880ec2dbbf49e 100644 (file)
 #include <stdlib.h>
 #include <ctype.h>
 
+#include <polyp/xmalloc.h>
+
+#include <polypcore/core-error.h>
 #include <polypcore/module.h>
-#include <polypcore/util.h>
+#include <polypcore/core-util.h>
 #include <polypcore/modargs.h>
 #include <polypcore/log.h>
 #include <polypcore/core-subscribe.h>
-#include <polypcore/xmalloc.h>
 #include <polypcore/sink-input.h>
+#include <polypcore/core-util.h>
 #include <polyp/volume.h>
 
 #include "module-volume-restore-symdef.h"
@@ -116,17 +119,19 @@ static int load_rules(struct userdata *u) {
     f = u->table_file ?
         fopen(u->table_file, "r") :
         pa_open_config_file(NULL, DEFAULT_VOLUME_TABLE_FILE, NULL, &u->table_file, "r");
-    
+
     if (!f) {
         if (errno == ENOENT) {
-            pa_log(__FILE__": starting with empty ruleset.");
+            pa_log_info(__FILE__": starting with empty ruleset.");
             ret = 0;
         } else
-            pa_log(__FILE__": failed to open file '%s': %s", u->table_file, strerror(errno));
+            pa_log(__FILE__": failed to open file '%s': %s", u->table_file, pa_cstrerror(errno));
         
         goto finish;
     }
 
+    pa_lock_fd(fileno(f), 1);
+    
     while (!feof(f)) {
         struct rule *rule;
         pa_cvolume v;
@@ -175,8 +180,10 @@ static int load_rules(struct userdata *u) {
     ret = 0;
     
 finish:
-    if (f)
+    if (f) {
+        pa_lock_fd(fileno(f), 0);
         fclose(f);
+    }
 
     return ret;
 }
@@ -192,10 +199,12 @@ static int save_rules(struct userdata *u) {
         pa_open_config_file(NULL, DEFAULT_VOLUME_TABLE_FILE, NULL, &u->table_file, "w");
 
     if (!f) {
-        pa_log(__FILE__": failed to open file '%s': %s", u->table_file, strerror(errno));
+        pa_log(__FILE__": failed to open file '%s': %s", u->table_file, pa_cstrerror(errno));
         goto finish;
     }
 
+    pa_lock_fd(fileno(f), 1);
+
     while ((rule = pa_hashmap_iterate(u->hashmap, &state, NULL))) {
         unsigned i;
         
@@ -204,15 +213,16 @@ static int save_rules(struct userdata *u) {
         for (i = 0; i < rule->volume.channels; i++)
             fprintf(f, " %u", rule->volume.values[i]);
 
-
         fprintf(f, "\n");
     }
     
     ret = 0;
     
 finish:
-    if (f)
+    if (f) {
+        pa_lock_fd(fileno(f), 0);
         fclose(f);
+    }
 
     return ret;
 }