diff options
author | Lennart Poettering <lennart@poettering.net> | 2006-05-17 15:21:08 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2006-05-17 15:21:08 +0000 |
commit | e0bf4a32f3ca7b9cf472a37c31be4a6202d39fa8 (patch) | |
tree | 288e05eb5f8c408e1537a0a5a2ce607ec44bbf36 /src | |
parent | 1267285257aaa60630b59f0f5c62c4c7f4a8d8df (diff) |
add proper locking when accessing the file volume.table
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@905 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/module-volume-restore.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/modules/module-volume-restore.c b/src/modules/module-volume-restore.c index b379e53c..f9e7d013 100644 --- a/src/modules/module-volume-restore.c +++ b/src/modules/module-volume-restore.c @@ -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 @@ 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."); @@ -127,6 +128,8 @@ static int load_rules(struct userdata *u) { goto finish; } + pa_lock_fd(fileno(f), 1); + while (!feof(f)) { struct rule *rule; pa_cvolume v; @@ -175,8 +178,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; } @@ -196,6 +201,8 @@ static int save_rules(struct userdata *u) { goto finish; } + pa_lock_fd(fileno(f), 1); + while ((rule = pa_hashmap_iterate(u->hashmap, &state, NULL))) { unsigned i; @@ -210,8 +217,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; } |