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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Allowing printf("%m") only where it actually works
Дата
Msg-id 2685.1527520461@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Allowing printf("%m") only where it actually works  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Ответы Re: Allowing printf("%m") only where it actually works  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> This seems to say that we oughta assign GetLastError() to saved_errno
> during errstart, then use %m in the errmsg() instead.

No, because in some parts of the code, errno does mean something,
even in Windows builds.

I think the right fix is to leave %m alone, and instead:

(1) save GetLastError's result along with errno during errstart.

(2) provide a function, say errlastwinerror(), to be used where
elog/ereport calls currently call GetLastError():

    elog(ERROR, "something went wrong: error code %lu",
         errlastwinerror());

What it does, of course, is to reach into the current error stack
level and retrieve the saved result.

We could use some hack along the line of what Thomas suggested
to enforce that this function is used rather than GetLastError().

It's amusing to speculate about whether we could actually cause
GetLastError() appearing within elog/ereport to get mapped into
this function, thus removing the need to change any code in call
sites.  But I suspect there's no adequately compiler-independent
way to do that.

I wonder whether we need to back-patch this.  I don't recall
seeing any field reports of misleading Windows error codes,
but I wonder how many people even look those up ...

            regards, tom lane


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

Предыдущее
От: "Nishant, Fnu"
Дата:
Сообщение: Re: found xmin from before relfrozenxid on pg_catalog.pg_authid
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Problem while updating a foreign table pointing to a partitionedtable on foreign server