]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsactl: redirect alsa-lib errors
authorJaroslav Kysela <perex@perex.cz>
Thu, 14 May 2020 17:09:45 +0000 (19:09 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 14 May 2020 17:09:53 +0000 (19:09 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
alsactl/alsactl.c
alsactl/alsactl.h
alsactl/utils.c

index 60d39459dedfc545d067f49285c6578dbcb76e57..92ce2702dd7f73bbfcf755b98c4b45ff2e00a295 100644 (file)
@@ -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();
index 6e96e78b0cd315c7409d0e400edbc7aa53c34eb9..853a70125aef5f13949c55f180104cf6b7fb0fe4 100644 (file)
@@ -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)
index a8c3a84ab93a797e9b7b21bba028013469e17f78..fb59e0e5c8f3a0f2fa1615c09dc12180895193d6 100644 (file)
@@ -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) : "");
+}