Re: Using the %m printf format more

From: Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Using the %m printf format more
Date: 2024-03-11 11:19:16
Message-ID: 87plw1j9sb.fsf@wibble.ilmari.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Michael Paquier <michael(at)paquier(dot)xyz> writes:

> On Wed, Mar 06, 2024 at 07:11:19PM +0000, Dagfinn Ilmari Mannsåker wrote:
>
>> The attached patch does so everywhere appropriate. One place where it's
>> not appropriate is the TAP-emitting functions in pg_regress, since those
>> call fprintf()
>
> I am not really following your argument with pg_regress.c and
> fprintf(). d6c55de1f99a should make that possible even in the case of
> emit_tap_output_v(), no?

The problem isn't that emit_tap_output_v() doesn't support %m, which it
does, but that it potentially calls fprintf() to output TAP protocol
elements such as "\n" and "# " before it calls vprintf(…, fmt, …), and
those calls might clobber errno. An option is to make it save errno at
the start and restore it before the vprintf() calls, as in the second
attached patch.

>> and other potentially errno-modifying functions before
>> evaluating the format string.
>
> Sure.

On closer look, fprintf() is actually the only errno-clobbering function
it calls, I was just hedging my bets in that statement.

- ilmari

Attachment Content-Type Size
v2-0001-Use-m-printf-format-instead-of-strerror-errno-whe.patch text/x-diff 43.3 KB
v2-0002-Save-errno-in-emit_tap_output_v-and-use-m-in-call.patch text/x-diff 7.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2024-03-11 11:31:12 Re: POC, WIP: OR-clause support for indexes
Previous Message Laurenz Albe 2024-03-11 11:18:01 Re: Reducing the log spam