Implement %m in src/port/snprintf.c, and teach elog.c to rely on that.
Tom Lane <tgl@sss.pgh.pa.us>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/lib/stringinfo.c | modified | +6 −0 |
| src/backend/utils/error/elog.c | modified | +4 −66 |
| src/bin/pg_dump/pg_backup_archiver.c | modified | +4 −0 |
| src/bin/pg_dump/pg_backup_tar.c | modified | +2 −0 |
| src/common/psprintf.c | modified | +5 −0 |
| src/interfaces/libpq/pqexpbuffer.c | modified | +7 −0 |
| src/pl/plpython/plpy_elog.c | modified | +2 −0 |
| src/port/snprintf.c | modified | +27 −1 |
Discussion
- Allowing printf("%m") only where it actually works 50 messages · 2018-05-21 → 2018-10-09