From 1797b2c2907630b0b8d5374fb382edf40d02387c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 13 Nov 2008 09:28:43 +0100 Subject: [PATCH] Add -I option to alsactl Add -I option to alsactl to take back the old restore behavior without initialization. Signed-off-by: Takashi Iwai --- alsactl/alsactl.1 | 9 +++++++++ alsactl/alsactl.c | 9 ++++++++- alsactl/alsactl.h | 3 ++- alsactl/state.c | 11 +++++++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/alsactl/alsactl.1 b/alsactl/alsactl.1 index b038a82..eb3cbd1 100644 --- a/alsactl/alsactl.1 +++ b/alsactl/alsactl.1 @@ -60,6 +60,15 @@ and do not set an error exit code when soundcards are not installed. Used with restore command. Don't restore mismatching control elements. This option was the old default behavior. +.TP +\fI\-I, \-\-no\-init\-fallback\fP +Don't initialize cards if restore fails. Since version 1.0.18, +\fBalsactl\fP tries to initialize the card with the restore operation +as default. But this can cause incompatibility with the older version. +The caller may expect that the state won't be touched if no state file +exists. This option takes the restore behavior back to the older +version by suppressing the initialization. + .TP \fI\-r, \-\-runstate\fP Save restore and init state to this file. The file will contain only errors. diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c index f846316..c1e09bb 100644 --- a/alsactl/alsactl.c +++ b/alsactl/alsactl.c @@ -51,6 +51,8 @@ static void help(void) printf(" (default mode)\n"); printf(" -g,--ignore ignore 'No soundcards found' error\n"); printf(" -P,--pedantic do not restore mismatching controls (old default)\n"); + printf(" -I,--no-init-fallback\n" + " don't initialize even if restore fails\n"); printf(" -r,--runstate # save restore and init state to this file (only errors)\n"); printf(" default settings is 'no file set'\n"); printf(" -R,--remove remove runstate file at first, otherwise append errors\n"); @@ -76,6 +78,7 @@ int main(int argc, char *argv[]) {"file", 1, NULL, 'f'}, {"env", 1, NULL, 'E'}, {"initfile", 1, NULL, 'i'}, + {"no-init-fallback", 0, NULL, 'I'}, {"force", 0, NULL, 'F'}, {"ignore", 0, NULL, 'g'}, {"pedantic", 0, NULL, 'P'}, @@ -96,6 +99,7 @@ int main(int argc, char *argv[]) char *initfile = DATADIR "/init/00main"; char *cardname, **tmp, ncardname[16]; int removestate = 0; + int init_fallback = 1; /* new default behavior */ int res; command = argv[0]; @@ -126,6 +130,9 @@ int main(int argc, char *argv[]) case 'i': initfile = optarg; break; + case 'I': + init_fallback = 0; + break; case 'r': statefile = optarg; break; @@ -173,7 +180,7 @@ int main(int argc, char *argv[]) } else if (!strcmp(argv[optind], "restore")) { if (removestate) remove(statefile); - res = load_state(cfgfile, initfile, cardname); + res = load_state(cfgfile, initfile, cardname, init_fallback); } else { fprintf(stderr, "alsactl: Unknown command '%s'...\n", argv[optind]); diff --git a/alsactl/alsactl.h b/alsactl/alsactl.h index 44d27f1..89ad295 100644 --- a/alsactl/alsactl.h +++ b/alsactl/alsactl.h @@ -68,7 +68,8 @@ extern char *statefile; int init(const char *file, const char *cardname); int save_state(const char *file, const char *cardname); -int load_state(const char *file, const char *initfile, const char *cardname); +int load_state(const char *file, const char *initfile, const char *cardname, + int do_init); int power(const char *argv[], int argc); int generate_names(const char *cfgfile); diff --git a/alsactl/state.c b/alsactl/state.c index 576721a..86b64f4 100644 --- a/alsactl/state.c +++ b/alsactl/state.c @@ -1548,7 +1548,8 @@ int save_state(const char *file, const char *cardname) return 0; } -int load_state(const char *file, const char *initfile, const char *cardname) +int load_state(const char *file, const char *initfile, const char *cardname, + int do_init) { int err, finalerr = 0; snd_config_t *config; @@ -1586,6 +1587,8 @@ int load_state(const char *file, const char *initfile, const char *cardname) if (card < 0) break; first = 0; + if (!do_init) + break; sprintf(cardname1, "%i", card); err = init(initfile, cardname1); if (err < 0) { @@ -1594,7 +1597,7 @@ int load_state(const char *file, const char *initfile, const char *cardname) } initfailed(card, "restore"); } - if (!first) + if (first) finalerr = 0; /* no cards, no error code */ return finalerr; } @@ -1621,7 +1624,7 @@ int load_state(const char *file, const char *initfile, const char *cardname) } first = 0; /* do a check if controls matches state file */ - if (set_controls(card, config, 0)) { + if (do_init && set_controls(card, config, 0)) { sprintf(cardname1, "%i", card); err = init(initfile, cardname1); if (err < 0) { @@ -1644,7 +1647,7 @@ int load_state(const char *file, const char *initfile, const char *cardname) return -ENODEV; } /* do a check if controls matches state file */ - if (set_controls(cardno, config, 0)) { + if (do_init && set_controls(cardno, config, 0)) { err = init(initfile, cardname); if (err < 0) { initfailed(cardno, "init");