Skip to content

Commit 862ba9c

Browse files
committed
alsactl: add support for new log handler (alsa-lib 1.2.15)
Signed-off-by: Jaroslav Kysela <[email protected]>
1 parent 8957eb2 commit 862ba9c

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

alsactl/alsactl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,11 @@ int main(int argc, char *argv[])
441441
syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon started");
442442
}
443443

444+
#if SND_LIB_VER(1, 2, 15) < SND_LIB_VERSION
444445
snd_lib_error_set_handler(error_handler);
446+
#else
447+
snd_lib_log_set_handler(log_handler);
448+
#endif
445449

446450
if (!strcmp(cmd, "init")) {
447451
res = init(cfgdir, initfile, initflags | FLAG_UCM_FBOOT | FLAG_UCM_BOOT, cardname);

alsactl/alsactl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ void info_(const char *fcn, long line, const char *fmt, ...);
2424
void error_(const char *fcn, long line, const char *fmt, ...);
2525
void cerror_(const char *fcn, long line, int cond, const char *fmt, ...);
2626
void dbg_(const char *fcn, long line, const char *fmt, ...);
27-
void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...);
27+
void error_handler(const char *file, int line, const char *function, int errcode, const char *fmt, ...);
28+
void log_handler(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg);
2829

2930
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
3031
#define info(...) do { info_(__func__, __LINE__, __VA_ARGS__); } while (0)

alsactl/utils.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void dbg_(const char *fcn, long line, const char *fmt, ...)
177177
va_end(ap);
178178
}
179179

180-
void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...)
180+
void error_handler(const char *file, int line, const char *function, int errcode, const char *fmt, ...)
181181
{
182182
char buf[2048];
183183
va_list arg;
@@ -187,12 +187,36 @@ void error_handler(const char *file, int line, const char *function, int err, co
187187
va_end(arg);
188188
if (use_syslog)
189189
syslog(LOG_ERR, "alsa-lib %s:%i:(%s) %s%s%s\n", file, line, function,
190-
buf, err ? ": " : "", err ? snd_strerror(err) : "");
190+
buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
191191
else
192192
fprintf(stderr, "alsa-lib %s:%i:(%s) %s%s%s\n", file, line, function,
193-
buf, err ? ": " : "", err ? snd_strerror(err) : "");
193+
buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
194194
}
195195

196+
#if SND_LIB_VER(1, 2, 15) >= SND_LIB_VERSION
197+
void log_handler(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg)
198+
{
199+
char buf[2048], level[50] = "";
200+
const char *text1, *text2;
201+
202+
if (!snd_lib_log_filter(prio, interface, NULL))
203+
return;
204+
205+
text1 = snd_lib_log_priority(prio);
206+
text2 = snd_lib_log_interface(interface);
207+
if (text1 || text2)
208+
snprintf(level, sizeof(level), "[%s.%s] ", text1 ? text1 : "", text2 ? text2 : "");
209+
210+
vsnprintf(buf, sizeof(buf), fmt, arg);
211+
if (use_syslog)
212+
syslog(LOG_ERR, "alsa-lib %s:%i:(%s) %s%s%s%s\n", file, line, function, level,
213+
buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
214+
else
215+
fprintf(stderr, "alsa-lib %s:%i:(%s) %s%s%s%s\n", file, line, function, level,
216+
buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
217+
}
218+
#endif
219+
196220
int load_configuration(const char *file, snd_config_t **top, int *open_failed)
197221
{
198222
snd_config_t *config;

aplay/aplay.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,13 @@ static void set_params(void)
14641464
chunk_size, buffer_size);
14651465
prg_exit(EXIT_FAILURE);
14661466
}
1467+
if (dump_hw_params) {
1468+
fprintf(stderr, _("HW Params of device \"%s\":\n"),
1469+
snd_pcm_name(handle));
1470+
fprintf(stderr, "--------------------\n");
1471+
snd_pcm_hw_params_dump(params, log);
1472+
fprintf(stderr, "--------------------\n");
1473+
}
14671474
err = snd_pcm_sw_params_current(handle, swparams);
14681475
if (err < 0) {
14691476
error(_("Unable to get current sw params."));

0 commit comments

Comments
 (0)