From 862ba9c1f8dfcb5d0600a6562b53ae09bc8e02c1 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 7 Nov 2025 17:00:42 +0100 Subject: [PATCH] alsactl: add support for new log handler (alsa-lib 1.2.15) Signed-off-by: Jaroslav Kysela --- alsactl/alsactl.c | 4 ++++ alsactl/alsactl.h | 3 ++- alsactl/utils.c | 30 +++++++++++++++++++++++++++--- aplay/aplay.c | 7 +++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c index 8ad991a..5614ea7 100644 --- a/alsactl/alsactl.c +++ b/alsactl/alsactl.c @@ -441,7 +441,11 @@ int main(int argc, char *argv[]) syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon started"); } +#if SND_LIB_VER(1, 2, 15) < SND_LIB_VERSION snd_lib_error_set_handler(error_handler); +#else + snd_lib_log_set_handler(log_handler); +#endif if (!strcmp(cmd, "init")) { res = init(cfgdir, initfile, initflags | FLAG_UCM_FBOOT | FLAG_UCM_BOOT, cardname); diff --git a/alsactl/alsactl.h b/alsactl/alsactl.h index 6ae45e3..f86f8d9 100644 --- a/alsactl/alsactl.h +++ b/alsactl/alsactl.h @@ -24,7 +24,8 @@ 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, ...); +void error_handler(const char *file, int line, const char *function, int errcode, const char *fmt, ...); +void log_handler(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg); #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 d8cbf53..42e6eba 100644 --- a/alsactl/utils.c +++ b/alsactl/utils.c @@ -177,7 +177,7 @@ 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, ...) +void error_handler(const char *file, int line, const char *function, int errcode, const char *fmt, ...) { char buf[2048]; va_list arg; @@ -187,12 +187,36 @@ void error_handler(const char *file, int line, const char *function, int err, co 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) : ""); + buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : ""); else fprintf(stderr, "alsa-lib %s:%i:(%s) %s%s%s\n", file, line, function, - buf, err ? ": " : "", err ? snd_strerror(err) : ""); + buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : ""); } +#if SND_LIB_VER(1, 2, 15) >= SND_LIB_VERSION +void log_handler(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg) +{ + char buf[2048], level[50] = ""; + const char *text1, *text2; + + if (!snd_lib_log_filter(prio, interface, NULL)) + return; + + text1 = snd_lib_log_priority(prio); + text2 = snd_lib_log_interface(interface); + if (text1 || text2) + snprintf(level, sizeof(level), "[%s.%s] ", text1 ? text1 : "", text2 ? text2 : ""); + + vsnprintf(buf, sizeof(buf), fmt, arg); + if (use_syslog) + syslog(LOG_ERR, "alsa-lib %s:%i:(%s) %s%s%s%s\n", file, line, function, level, + buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : ""); + else + fprintf(stderr, "alsa-lib %s:%i:(%s) %s%s%s%s\n", file, line, function, level, + buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : ""); +} +#endif + int load_configuration(const char *file, snd_config_t **top, int *open_failed) { snd_config_t *config; diff --git a/aplay/aplay.c b/aplay/aplay.c index c58c2e9..bdc88c2 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -1464,6 +1464,13 @@ static void set_params(void) chunk_size, buffer_size); prg_exit(EXIT_FAILURE); } + if (dump_hw_params) { + fprintf(stderr, _("HW Params of device \"%s\":\n"), + snd_pcm_name(handle)); + fprintf(stderr, "--------------------\n"); + snd_pcm_hw_params_dump(params, log); + fprintf(stderr, "--------------------\n"); + } err = snd_pcm_sw_params_current(handle, swparams); if (err < 0) { error(_("Unable to get current sw params.")); -- 2.47.3