diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2010-05-26 10:37:58 +0200 |
---|---|---|
committer | Clemens Ladisch <clemens@ladisch.de> | 2010-05-26 10:37:58 +0200 |
commit | b4ff58b685fe9da25901cd3e395dd2f2d64532df (patch) | |
tree | a939f265f94827c95738b8ed21e67bb57a0a0f4b /alsactl | |
parent | bd15b1e5ea23d25fcb2ccccd1cf25350c60fe527 (diff) |
Revert wrong parts of "alsactl: use snd_config_imake* functions"
This reverts the parts of commit e509df69a5100df28921980362488f6947df0aae
that accidentally reverted a bunch of earlier commits.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Diffstat (limited to 'alsactl')
-rw-r--r-- | alsactl/alsactl.h | 10 | ||||
-rw-r--r-- | alsactl/state.c | 22 | ||||
-rw-r--r-- | alsactl/utils.c | 6 |
3 files changed, 22 insertions, 16 deletions
diff --git a/alsactl/alsactl.h b/alsactl/alsactl.h index 89ad295..be90efb 100644 --- a/alsactl/alsactl.h +++ b/alsactl/alsactl.h @@ -34,16 +34,16 @@ extern char *statefile; #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) #define cerror(cond, ...) do {\ - if (cond) { \ - fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ + if (cond || debugflag) { \ + fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \ fprintf(stderr, __VA_ARGS__); \ putc('\n', stderr); \ } \ } while (0) #else #define cerror(cond, args...) do {\ - if (cond) { \ - fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ + if (cond || debugflag) { \ + fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \ fprintf(stderr, ##args); \ putc('\n', stderr); \ } \ @@ -78,7 +78,7 @@ int generate_names(const char *cfgfile); int file_map(const char *filename, char **buf, size_t *bufsize); void file_unmap(void *buf, size_t bufsize); size_t line_width(const char *buf, size_t bufsize, size_t pos); -void initfailed(int cardnumber, const char *reason); +void initfailed(int cardnumber, const char *reason, int exitcode); static inline int hextodigit(int c) { diff --git a/alsactl/state.c b/alsactl/state.c index 01b1cd6..7eb107f 100644 --- a/alsactl/state.c +++ b/alsactl/state.c @@ -1131,7 +1131,6 @@ static int restore_config_value2(snd_ctl_t *handle, snd_ctl_elem_info_t *info, } snd_ctl_elem_value_set_byte(ctl, idx, val); return 1; - break; default: break; } @@ -1418,6 +1417,7 @@ static int set_controls(int card, snd_config_t *top, int doit) snd_ctl_card_info_alloca(&info); sprintf(name, "hw:%d", card); + dbg("device='%s', doit=%i", name, doit); err = snd_ctl_open(&handle, name, 0); if (err < 0) { error("snd_ctl_open error: %s", snd_strerror(err)); @@ -1429,6 +1429,7 @@ static int set_controls(int card, snd_config_t *top, int doit) goto _close; } id = snd_ctl_card_info_get_id(info); + dbg("card-info-id: '%s'", id); err = snd_config_searchv(top, &control, "state", id, "control", 0); if (err < 0) { if (force_restore) { @@ -1454,24 +1455,25 @@ static int set_controls(int card, snd_config_t *top, int doit) goto _close; } + dbg("maxnumid=%i", maxnumid); /* check if we have additional controls in driver */ /* in this case we should go through init procedure */ if (!doit && maxnumid >= 0) { - snd_ctl_elem_id_t *id; snd_ctl_elem_info_t *info; - snd_ctl_elem_id_alloca(&id); snd_ctl_elem_info_alloca(&info); snd_ctl_elem_info_set_numid(info, maxnumid+1); if (snd_ctl_elem_info(handle, info) == 0) { /* not very informative */ /* but value is used for check only */ err = -EAGAIN; + dbg("more controls than maxnumid?"); goto _close; } } _close: snd_ctl_close(handle); + dbg("result code: %i", err); return err; } @@ -1596,9 +1598,9 @@ int load_state(const char *file, const char *initfile, const char *cardname, err = init(initfile, cardname1); if (err < 0) { finalerr = err; - initfailed(card, "init"); + initfailed(card, "init", err); } - initfailed(card, "restore"); + initfailed(card, "restore", -ENOENT); } if (first) finalerr = 0; /* no cards, no error code */ @@ -1631,14 +1633,14 @@ int load_state(const char *file, const char *initfile, const char *cardname, sprintf(cardname1, "%i", card); err = init(initfile, cardname1); if (err < 0) { - initfailed(card, "init"); + initfailed(card, "init", err); finalerr = err; } } if ((err = set_controls(card, config, 1))) { if (!force_restore) finalerr = err; - initfailed(card, "restore"); + initfailed(card, "restore", err); } } } else { @@ -1653,12 +1655,12 @@ int load_state(const char *file, const char *initfile, const char *cardname, if (do_init && set_controls(cardno, config, 0)) { err = init(initfile, cardname); if (err < 0) { - initfailed(cardno, "init"); - return err; + initfailed(cardno, "init", err); + finalerr = err; } } if ((err = set_controls(cardno, config, 1))) { - initfailed(cardno, "restore"); + initfailed(cardno, "restore", err); if (!force_restore) return err; } diff --git a/alsactl/utils.c b/alsactl/utils.c index ab4dbd4..a27eb6e 100644 --- a/alsactl/utils.c +++ b/alsactl/utils.c @@ -79,19 +79,23 @@ size_t line_width(const char *buf, size_t bufsize, size_t pos) return count - pos; } -void initfailed(int cardnumber, const char *reason) +void initfailed(int cardnumber, const char *reason, int exitcode) { int fp; char *str; + char sexitcode[16]; if (statefile == NULL) return; if (snd_card_get_name(cardnumber, &str) < 0) return; + sprintf(sexitcode, "%i", exitcode); fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644); write(fp, str, strlen(str)); write(fp, ":", 1); write(fp, reason, strlen(reason)); + write(fp, ":", 1); + write(fp, sexitcode, strlen(sexitcode)); write(fp, "\n", 1); close(fp); free(str); |