diff options
author | Jaroslav Kysela <perex@perex.cz> | 2020-05-14 19:09:45 +0200 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2020-05-14 19:09:53 +0200 |
commit | 8fb4016a175f5e83c6ec363528c9ba6332a262ef (patch) | |
tree | cff8b23b0380cb9edbc0526e76e2fb2203feb00d /alsactl | |
parent | 4bea8fe3a73cd2df8dcad1c8a14c35bab7b21073 (diff) | |
download | alsa-utils-8fb4016a175f5e83c6ec363528c9ba6332a262ef.tar.gz |
alsactl: redirect alsa-lib errors
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'alsactl')
-rw-r--r-- | alsactl/alsactl.c | 2 | ||||
-rw-r--r-- | alsactl/alsactl.h | 1 | ||||
-rw-r--r-- | alsactl/utils.c | 16 |
3 files changed, 19 insertions, 0 deletions
diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c index 60d3945..92ce270 100644 --- a/alsactl/alsactl.c +++ b/alsactl/alsactl.c @@ -354,6 +354,8 @@ int main(int argc, char *argv[]) syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon started"); } + snd_lib_error_set_handler(error_handler); + if (!strcmp(cmd, "init")) { res = init(initfile, cardname); snd_config_update_free_global(); diff --git a/alsactl/alsactl.h b/alsactl/alsactl.h index 6e96e78..853a701 100644 --- a/alsactl/alsactl.h +++ b/alsactl/alsactl.h @@ -11,6 +11,7 @@ void info_(const char *fcn, long line, const char *fmt, ...); void error_(const char *fcn, long line, const char *fmt, ...); void cerror_(const char *fcn, long line, int cond, const char *fmt, ...); void dbg_(const char *fcn, long line, const char *fmt, ...); +void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...); #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) #define info(...) do { info_(__func__, __LINE__, __VA_ARGS__); } while (0) diff --git a/alsactl/utils.c b/alsactl/utils.c index a8c3a84..fb59e0e 100644 --- a/alsactl/utils.c +++ b/alsactl/utils.c @@ -177,3 +177,19 @@ void dbg_(const char *fcn, long line, const char *fmt, ...) } va_end(ap); } + +void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...) +{ + char buf[2048]; + va_list arg; + + va_start(arg, fmt); + vsnprintf(buf, sizeof(buf), fmt, arg); + va_end(arg); + if (use_syslog) + syslog(LOG_ERR, "alsa-lib %s:%i:(%s) %s%s%s\n", file, line, function, + buf, err ? ": " : "", err ? snd_strerror(err) : ""); + else + fprintf(stderr, "alsa-lib %s:%i:(%s) %s%s%s\n", file, line, function, + buf, err ? ": " : "", err ? snd_strerror(err) : ""); +} |