From 8fb4016a175f5e83c6ec363528c9ba6332a262ef Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 14 May 2020 19:09:45 +0200 Subject: alsactl: redirect alsa-lib errors Signed-off-by: Jaroslav Kysela --- alsactl/alsactl.c | 2 ++ alsactl/alsactl.h | 1 + alsactl/utils.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) (limited to 'alsactl') 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) : ""); +} -- cgit v1.2.1