alsactl: improve -d to get warnings and store exitcode to runstate file

Also, make the initialization & restore logic for one card similar to
multiple card initialization & restore.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2010-02-25 09:19:45 +01:00
parent c9b86f49a8
commit 5c35aa8b69
3 changed files with 17 additions and 13 deletions

View file

@ -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)
{

View file

@ -1582,9 +1582,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 */
@ -1617,14 +1617,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 {
@ -1639,12 +1639,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;
}

View file

@ -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);