]> code.delx.au - pulseaudio/blobdiff - src/modules/module-volume-restore.c
* add new function pa_check_in_group()
[pulseaudio] / src / modules / module-volume-restore.c
index b379e53cfbb1bcd2de60e86c69d93caa1c66190b..d095650971ac8952690c1697e6f28dd2f1991d4c 100644 (file)
@@ -1,20 +1,20 @@
 /* $Id$ */
 
 /***
-  This file is part of polypaudio.
+  This file is part of PulseAudio.
  
-  polypaudio is free software; you can redistribute it and/or modify
+  PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2 of the License,
   or (at your option) any later version.
  
-  polypaudio is distributed in the hope that it will be useful, but
+  PulseAudio is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
  
   You should have received a copy of the GNU Lesser General Public License
-  along with polypaudio; if not, write to the Free Software
+  along with PulseAudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
 #include <stdlib.h>
 #include <ctype.h>
 
-#include <polypcore/module.h>
-#include <polypcore/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 <polyp/volume.h>
+#include <pulse/xmalloc.h>
+
+#include <pulsecore/core-error.h>
+#include <pulsecore/module.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/modargs.h>
+#include <pulsecore/log.h>
+#include <pulsecore/core-subscribe.h>
+#include <pulsecore/sink-input.h>
+#include <pulsecore/core-util.h>
+#include <pulse/volume.h>
 
 #include "module-volume-restore-symdef.h"
 
@@ -50,7 +53,7 @@ PA_MODULE_VERSION(PACKAGE_VERSION)
 
 #define WHITESPACE "\n\r \t"
 
-#define DEFAULT_VOLUME_TABLE_FILE ".polypaudio/volume.table"
+#define DEFAULT_VOLUME_TABLE_FILE "volume.table"
 
 static const char* const valid_modargs[] = {
     "table",
@@ -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_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;
         
@@ -210,8 +219,10 @@ static int save_rules(struct userdata *u) {
     ret = 0;
     
 finish:
-    if (f)
+    if (f) {
+        pa_lock_fd(fileno(f), 0);
         fclose(f);
+    }
 
     return ret;
 }