summaryrefslogtreecommitdiff
path: root/alsactl/state.c
diff options
context:
space:
mode:
authorJaroslav Kysela <perex@perex.cz>2013-04-05 11:51:51 +0200
committerJaroslav Kysela <perex@perex.cz>2013-04-05 13:47:18 +0200
commitcc5c3357cff87bb805494e23620bd2d675bcccbd (patch)
tree5396c281f7e13bb85fb2d4443eec12d59fbb8d1f /alsactl/state.c
parentb95dd7ef468212c08434f6e7b9987f2936944b09 (diff)
downloadalsa-utils-cc5c3357cff87bb805494e23620bd2d675bcccbd.tar.gz
alsactl: add the daemon mode
For the plug-and-play hardware, like USB devices, it may be helpful to manage the sound state periodically, before the devices are removed. This change implements new commands 'daemon' and 'rdaemon' to save the sound state in defined intervals when the sound controls are changed. The udev rules can notify the daemon using the 'kill' or 'nrestore' commands to rescan available cards in the system. Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'alsactl/state.c')
-rw-r--r--alsactl/state.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/alsactl/state.c b/alsactl/state.c
index 8b309ba..bd53d21 100644
--- a/alsactl/state.c
+++ b/alsactl/state.c
@@ -1562,6 +1562,8 @@ int save_state(const char *file, const char *cardname)
}
strcpy(nfile, file);
strcat(nfile, ".new");
+ if (state_lock(file, 1, 10) != 0)
+ goto out;
}
if (!stdio && (err = snd_input_stdio_open(&in, file, "r")) >= 0) {
err = snd_config_load(config, in);
@@ -1628,12 +1630,13 @@ int save_state(const char *file, const char *cardname)
if (err < 0) {
error("snd_config_save: %s", snd_strerror(err));
} else {
- //unlink(file);
err = rename(nfile, file);
if (err < 0)
error("rename failed: %s (%s)", strerror(-err), file);
}
out:
+ if (!stdio)
+ state_lock(file, 0, 10);
free(nfile);
snd_config_delete(config);
snd_config_update_free_global();
@@ -1646,7 +1649,7 @@ int load_state(const char *file, const char *initfile, const char *cardname,
int err, finalerr = 0;
snd_config_t *config;
snd_input_t *in;
- int stdio;
+ int stdio, locked = 0;
err = snd_config_top(&config);
if (err < 0) {
@@ -1654,13 +1657,18 @@ int load_state(const char *file, const char *initfile, const char *cardname,
return err;
}
stdio = !strcmp(file, "-");
- if (stdio)
+ if (stdio) {
err = snd_input_stdio_attach(&in, stdin, 0);
- else
- err = snd_input_stdio_open(&in, file, "r");
+ } else {
+ err = state_lock(file, 1, 10);
+ locked = err >= 0;
+ err = err >= 0 ? snd_input_stdio_open(&in, file, "r") : err;
+ }
if (err >= 0) {
err = snd_config_load(config, in);
snd_input_close(in);
+ if (locked)
+ state_lock(file, 0, 10);
if (err < 0) {
error("snd_config_load error: %s", snd_strerror(err));
goto out;