[polypaudio-commits] r905 - /trunk/src/modules/module-volume-restore.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed May 17 08:21:08 PDT 2006


Author: lennart
Date: Wed May 17 17:21:08 2006
New Revision: 905

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=905&root=polypaudio&view=rev
Log:
add proper locking when accessing the file volume.table 

Modified:
    trunk/src/modules/module-volume-restore.c

Modified: trunk/src/modules/module-volume-restore.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-volume-restore.c?rev=905&root=polypaudio&r1=904&r2=905&view=diff
==============================================================================
--- trunk/src/modules/module-volume-restore.c (original)
+++ trunk/src/modules/module-volume-restore.c Wed May 17 17:21:08 2006
@@ -39,6 +39,7 @@
 #include <polypcore/core-subscribe.h>
 #include <polypcore/xmalloc.h>
 #include <polypcore/sink-input.h>
+#include <polypcore/util.h>
 #include <polyp/volume.h>
 
 #include "module-volume-restore-symdef.h"
@@ -116,7 +117,7 @@
     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_info(__FILE__": starting with empty ruleset.");
@@ -127,6 +128,8 @@
         goto finish;
     }
 
+    pa_lock_fd(fileno(f), 1);
+    
     while (!feof(f)) {
         struct rule *rule;
         pa_cvolume v;
@@ -175,8 +178,10 @@
     ret = 0;
     
 finish:
-    if (f)
+    if (f) {
+        pa_lock_fd(fileno(f), 0);
         fclose(f);
+    }
 
     return ret;
 }
@@ -196,6 +201,8 @@
         goto finish;
     }
 
+    pa_lock_fd(fileno(f), 1);
+
     while ((rule = pa_hashmap_iterate(u->hashmap, &state, NULL))) {
         unsigned i;
         
@@ -210,8 +217,10 @@
     ret = 0;
     
 finish:
-    if (f)
+    if (f) {
+        pa_lock_fd(fileno(f), 0);
         fclose(f);
+    }
 
     return ret;
 }




More information about the pulseaudio-commits mailing list