[pulseaudio-discuss] [PATCH v2 3/6] log: Print systemd journal API failure cause

Tanu Kaskinen tanuk at iki.fi
Wed Apr 20 13:22:40 UTC 2016


On Mon, 2016-03-14 at 08:17 +0200, Ahmed S. Darwish wrote:
> @@ -386,7 +386,7 @@ void pa_log_levelv_meta(
>  
>      /* We don't use dynamic memory allocation here to minimize the hit
>       * in RT threads */
> -    char text[16*1024], location[128], timestamp[32];
> +    char text[16*1024], location[128], timestamp[32], logging_error[120];
>  
>      pa_assert(level < PA_LOG_LEVEL_MAX);
>      pa_assert(format);
> @@ -507,24 +507,29 @@ void pa_log_levelv_meta(
>  
>  #ifdef HAVE_SYSTEMD_JOURNAL
>              case PA_LOG_JOURNAL:
> -                if (sd_journal_send("MESSAGE=%s", t,
> +                if ((ret = sd_journal_send("MESSAGE=%s", t,
>                                  "PRIORITY=%i", level_to_journal[level],
>                                  "CODE_FILE=%s", file,
>                                  "CODE_FUNC=%s", func,
>                                  "CODE_LINE=%d", line,
>                                  "PULSE_BACKTRACE=%s", pa_strempty(bt),
> -                                NULL) < 0) {
> +                                NULL)) < 0) {
> +                    pa_log_target new_target = { .file = NULL, };
> +                    pa_snprintf(logging_error, sizeof(logging_error), "Error writing logs to journal. Reason: %s",
> +                                pa_cstrerror(ret));
>  #ifdef HAVE_SYSLOG_H
> -                    pa_log_target new_target = { .type = PA_LOG_SYSLOG, .file = NULL };
> +                    new_target.type = PA_LOG_SYSLOG;
>  
> -                    syslog(level_to_syslog[PA_LOG_ERROR], "%s%s%s", timestamp, __FILE__,
> -                           "Error writing logs to the journal. Redirect log messages to syslog.");
> +                    log_syslog(PA_LOG_ERROR, logging_error, timestamp, NULL, NULL);
> +                    log_syslog(PA_LOG_ERROR, (char *)"Redirecting log messages to syslog.", timestamp, NULL, NULL);

I think it would be better to change the log_syslog() prototype than to
cast "const char *" to "char *" here. There's no good reason why
log_syslog() needs to take a mutable string.

Also, I think it makes sense to pass __FILE__ as the location instead
of NULL, like the previous code did.

-- 
Tanu


More information about the pulseaudio-discuss mailing list