Re: Allowing printf("%m") only where it actually works

Поиск
Список
Период
Сортировка
От Thomas Munro
Тема Re: Allowing printf("%m") only where it actually works
Дата
Msg-id CAEepm=0oVAR8AOKjK-Yq34KoAMXqZbTHsF_rpZqA5skDXe95Rg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Allowing printf("%m") only where it actually works  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Allowing printf("%m") only where it actually works  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Sun, May 27, 2018 at 4:21 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> ...  So that seems like a rather high price to
> pay to deal with what, at present, is a purely hypothetical hazard.
> (Basically what this would protect against is elog_start changing errno,
> which it doesn't.)

Hmm.  It looks like errstart() preserves errno to protect %m not from
itself, but from the caller's other arguments to the elog facility.
That seems reasonable, but do we really need to prohibit direct use of
errno in expressions?  The only rogue actor likely to trash errno is
you, the caller.  I mean, if you call elog(LOG, "foo %d %d", errno,
fsync(bar)) it's obviously UB and your own fault, but who would do
anything like that?  Or maybe I misunderstood the motivation.

> Another approach we could consider is keeping exec.c's one-off approach
> to error handling and letting it redefine pg_prevent_errno_in_scope() as
> empty.  But that's ugly.
>
> Or we could make the affected call sites work like this:
>
>         int save_errno = errno;
>
>         log_error(_("could not identify current directory: %s"),
>                   strerror(save_errno));
>
> which on the whole might be the most expedient thing.

That was what I was going to propose, until I started wondering why we
need to do anything here.

-- 
Thomas Munro
http://www.enterprisedb.com


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: Redesigning the executor (async, JIT, memory efficiency)
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Allowing printf("%m") only where it actually works