pgsql: Implement %m in src/port/snprintf.c, and teach elog.c to rely on

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Implement %m in src/port/snprintf.c, and teach elog.c to rely on
Date: 2018-09-26 17:32:03
Message-ID: E1g5DfP-00060w-DH@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Implement %m in src/port/snprintf.c, and teach elog.c to rely on that.

I started out with the idea that we needed to detect use of %m format specs
in contexts other than elog/ereport calls, because we couldn't rely on that
working in *printf calls. But a better answer is to fix things so that it
does work. Now that we're using snprintf.c all the time, we can implement
%m in that and we've fixed the problem.

This requires also adjusting our various printf-wrapping functions so that
they ensure "errno" is preserved when they call snprintf.c.

Remove elog.c's handmade implementation of %m, and let it rely on
snprintf to support the feature. That should provide some performance
gain, though I've not attempted to measure it.

There are a lot of places where we could now simplify 'printf("%s",
strerror(errno))' into 'printf("%m")', but I'm not in any big hurry
to make that happen.

Patch by me, reviewed by Michael Paquier

Discussion: https://postgr.es/m/2975.1526862605@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d6c55de1f99a9028540516316b95321a7b12a540

Modified Files
--------------
src/backend/lib/stringinfo.c | 6 ++++
src/backend/utils/error/elog.c | 70 +++---------------------------------
src/bin/pg_dump/pg_backup_archiver.c | 4 +++
src/bin/pg_dump/pg_backup_tar.c | 2 ++
src/common/psprintf.c | 5 +++
src/interfaces/libpq/pqexpbuffer.c | 7 ++++
src/pl/plpython/plpy_elog.c | 2 ++
src/port/snprintf.c | 28 ++++++++++++++-
8 files changed, 57 insertions(+), 67 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2018-09-26 18:04:39 Re: pgsql: Incorporate strerror_r() into src/port/snprintf.c, too.
Previous Message Tom Lane 2018-09-26 17:14:02 pgsql: Always use our own versions of *printf().