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) #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
#define cerror(cond, ...) do {\ #define cerror(cond, ...) do {\
if (cond) { \ if (cond || debugflag) { \
fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, __VA_ARGS__); \
putc('\n', stderr); \ putc('\n', stderr); \
} \ } \
} while (0) } while (0)
#else #else
#define cerror(cond, args...) do {\ #define cerror(cond, args...) do {\
if (cond) { \ if (cond || debugflag) { \
fprintf(stderr, "%s: %s:%d: ", command, __FUNCTION__, __LINE__); \ fprintf(stderr, "%s%s: %s:%d: ", debugflag ? "WARNING: " : "", command, __FUNCTION__, __LINE__); \
fprintf(stderr, ##args); \ fprintf(stderr, ##args); \
putc('\n', stderr); \ putc('\n', stderr); \
} \ } \
@ -78,7 +78,7 @@ int generate_names(const char *cfgfile);
int file_map(const char *filename, char **buf, size_t *bufsize); int file_map(const char *filename, char **buf, size_t *bufsize);
void file_unmap(void *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); 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) 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); err = init(initfile, cardname1);
if (err < 0) { if (err < 0) {
finalerr = err; finalerr = err;
initfailed(card, "init"); initfailed(card, "init", err);
} }
initfailed(card, "restore"); initfailed(card, "restore", -ENOENT);
} }
if (first) if (first)
finalerr = 0; /* no cards, no error code */ 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); sprintf(cardname1, "%i", card);
err = init(initfile, cardname1); err = init(initfile, cardname1);
if (err < 0) { if (err < 0) {
initfailed(card, "init"); initfailed(card, "init", err);
finalerr = err; finalerr = err;
} }
} }
if ((err = set_controls(card, config, 1))) { if ((err = set_controls(card, config, 1))) {
if (!force_restore) if (!force_restore)
finalerr = err; finalerr = err;
initfailed(card, "restore"); initfailed(card, "restore", err);
} }
} }
} else { } 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)) { if (do_init && set_controls(cardno, config, 0)) {
err = init(initfile, cardname); err = init(initfile, cardname);
if (err < 0) { if (err < 0) {
initfailed(cardno, "init"); initfailed(cardno, "init", err);
return err; finalerr = err;
} }
} }
if ((err = set_controls(cardno, config, 1))) { if ((err = set_controls(cardno, config, 1))) {
initfailed(cardno, "restore"); initfailed(cardno, "restore", err);
if (!force_restore) if (!force_restore)
return err; return err;
} }

View file

@ -79,19 +79,23 @@ size_t line_width(const char *buf, size_t bufsize, size_t pos)
return count - pos; return count - pos;
} }
void initfailed(int cardnumber, const char *reason) void initfailed(int cardnumber, const char *reason, int exitcode)
{ {
int fp; int fp;
char *str; char *str;
char sexitcode[16];
if (statefile == NULL) if (statefile == NULL)
return; return;
if (snd_card_get_name(cardnumber, &str) < 0) if (snd_card_get_name(cardnumber, &str) < 0)
return; return;
sprintf(sexitcode, "%i", exitcode);
fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644); fp = open(statefile, O_WRONLY|O_CREAT|O_APPEND, 0644);
write(fp, str, strlen(str)); write(fp, str, strlen(str));
write(fp, ":", 1); write(fp, ":", 1);
write(fp, reason, strlen(reason)); write(fp, reason, strlen(reason));
write(fp, ":", 1);
write(fp, sexitcode, strlen(sexitcode));
write(fp, "\n", 1); write(fp, "\n", 1);
close(fp); close(fp);
free(str); free(str);