Re: [PATCH] Fix incorrect fprintf usage in log_error FRONTEND path

From: Bryan Green <dbryan(dot)green(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Fix incorrect fprintf usage in log_error FRONTEND path
Date: 2025-10-13 18:24:06
Message-ID: c57ec206-c62b-4779-958d-44ce58f1c3ba@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 10/13/25 13:16, Bryan Green wrote:
> On 10/13/25 13:01, Tom Lane wrote:
>> Bryan Green <dbryan(dot)green(at)gmail(dot)com> writes:
>>> On 10/13/25 10:48, Tom Lane wrote:
>>>> Huh, that certainly appears broken, but isn't the non-FRONTEND
>>>> case equally broken?  write_stderr() doesn't expect a va_list
>>>> either.  I wonder if this code is ever reached at all.
>>
>>> I found two instances of write_stderr(), one in elog.c and another in
>>> pg_ctl.c.
>>> They both use functions that correctly handle the va_list-- either
>>> vsnprintf or vfprintf.
>>
>> It's the one in elog.c that the non-FRONTEND case is going to invoke.
>> But I think you're mistaken that it'll "just work".  write_stderr()
>> is creating its own va_list.
>>
>> We probably need to invent vwrite_stderr().
>>
>>             regards, tom lane
> Oh, yes, I see it now.  I will create the vwrite_stderr()-- probably
> something like below, and then create a new patch.
>
> void
> vwrite_stderr(const char *fmt, va_list ap)
> {
> #ifdef WIN32
>     char        errbuf[2048];
> #endif
>     fmt = _(fmt);
>
> #ifndef WIN32
>     vfprintf(stderr, fmt, ap);
>     fflush(stderr);
> #else
>     vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
>     if (pgwin32_is_service())
>         write_eventlog(ERROR, errbuf, strlen(errbuf));
>     else
>     {
>         write_console(errbuf, strlen(errbuf));
>         fflush(stderr);
>     }
> #endif
> }
>
> Thanks,
> Bryan Green
I mistakenly just hit reply instead of reply all. Apologies for the
clutter.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexey Makhmutov 2025-10-13 18:34:39 Re: Adding basic NUMA awareness
Previous Message Jeff Davis 2025-10-13 18:16:36 Re: Clarification on Role Access Rights to Table Indexes