pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Law <exclusion@gmail.com>
To: Noah Misch <noah@leadboat.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: Magnus Hagander <magnus@hagander.net>
Cc: Andrew Dunstan <andrew@dunslane.net>
Subject: Re: BUG #7493: Postmaster messages unreadable in a Windows console
Date: Wed, 20 Feb 2013 16:00:00 +0400
Message-ID: <5124BAC0.4060006@gmail.com> (raw)
In-Reply-To: <20130214225957.GA5626@tornado.leadboat.com>
References: <5100F3F6.3050107@2ndQuadrant.com>
	<51013C2C.5020703@dunslane.net>
	<20130124161954.GA2448@tornado.leadboat.com>
	<5101A1C4.3020407@dunslane.net>
	<5107656C.1050400@gmail.com>
	<28316.1359471244@sss.pgh.pa.us>
	<20130130015155.GD3524@tornado.leadboat.com>
	<5108B6E1.9070503@gmail.com>
	<20130210210259.GA7401@tornado.leadboat.com>
	<511C8E11.7090407@gmail.com>
	<20130214225957.GA5626@tornado.leadboat.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Hello,

15.02.2013 02:59, Noah Misch wrote:
>>> With your proposed change, the problem will resurface in an actual SQL_ASCII
>>> database.  At the problem's root is write_console()'s assumption that messages
>>> are in the database encoding.  pg_bind_textdomain_codeset() tries to make that
>>> so, but it only works for encodings with a pg_enc2gettext_tbl entry.  That
>>> excludes SQL_ASCII, MULE_INTERNAL, and others.  write_console() needs to
>>> behave differently in such cases.
>> Thank you for the notice. So it seems that "DatabaseEncoding" variable
>> alone can't present a database encoding (for communication with a
>> client) and current process messages encoding (for logging messages) at
>> once. There should be another variable, something like
>> CurrentProcessEncoding, that will be set to OS encoding at start and can
>> be changed to encoding of a connected database (if
>> bind_textdomain_codeset succeeded).
> I'd call it MessageEncoding unless it corresponds with similar rigor to a
> broader concept.
Please look at the next version of the patch.

Thanks,
Alexander

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

0001-Fix-postmaster-messages-encoding.patch (text/x-patch, 3.7K) download From 5bce21326d48761c6f86be8797432a69b2533dcd Mon Sep 17 00:00:00 2001 From: Alexander Lakhin <exclusion@gmail.com> Date: Wed, 20 Feb 2013 15:34:05 +0400 Subject: Fix postmaster messages encoding --- src/backend/main/main.c | 2 ++ src/backend/utils/error/elog.c | 4 ++-- src/backend/utils/mb/mbutils.c | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 1173bda..ed4067e 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -100,6 +100,8 @@ main(int argc, char *argv[]) set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("postgres")); + SetMessageEncoding(GetPlatformEncoding()); + #ifdef WIN32 /* diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 3a211bf..40f20f3 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -1868,7 +1868,7 @@ write_eventlog(int level, const char *line, int len) * Also verify that we are not on our way into error recursion trouble due * to error messages thrown deep inside pgwin32_toUTF16(). */ - if (GetDatabaseEncoding() != GetPlatformEncoding() && + if (GetMessageEncoding() != GetPlatformEncoding() && !in_error_recursion_trouble()) { utf16 = pgwin32_toUTF16(line, len, NULL); @@ -1915,7 +1915,7 @@ write_console(const char *line, int len) * through to writing unconverted if we have not yet set up * CurrentMemoryContext. */ - if (GetDatabaseEncoding() != GetPlatformEncoding() && + if (GetMessageEncoding() != GetPlatformEncoding() && !in_error_recursion_trouble() && !redirection_done && CurrentMemoryContext != NULL) diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index 287ff80..8b51b78 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -57,6 +57,7 @@ static FmgrInfo *ToClientConvProc = NULL; */ static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[PG_SQL_ASCII]; static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[PG_SQL_ASCII]; +static pg_enc2name *MessageEncoding = &pg_enc2name_tbl[PG_SQL_ASCII]; static pg_enc2name *PlatformEncoding = NULL; /* @@ -881,6 +882,16 @@ SetDatabaseEncoding(int encoding) Assert(DatabaseEncoding->encoding == encoding); } +void +SetMessageEncoding(int encoding) +{ + if (!PG_VALID_BE_ENCODING(encoding)) + elog(ERROR, "invalid message encoding: %d", encoding); + + MessageEncoding = &pg_enc2name_tbl[encoding]; + Assert(MessageEncoding->encoding == encoding); +} + /* * Bind gettext to the codeset equivalent with the database encoding. */ @@ -915,6 +926,8 @@ pg_bind_textdomain_codeset(const char *domainname) if (bind_textdomain_codeset(domainname, pg_enc2gettext_tbl[i].name) == NULL) elog(LOG, "bind_textdomain_codeset failed"); + else + SetMessageEncoding(encoding); break; } } @@ -964,6 +977,13 @@ GetPlatformEncoding(void) return PlatformEncoding->encoding; } +int +GetMessageEncoding(void) +{ + Assert(MessageEncoding); + return MessageEncoding->encoding; +} + #ifdef WIN32 /* @@ -977,7 +997,7 @@ pgwin32_toUTF16(const char *str, int len, int *utf16len) int dstlen; UINT codepage; - codepage = pg_enc2name_tbl[GetDatabaseEncoding()].codepage; + codepage = pg_enc2name_tbl[GetMessageEncoding()].codepage; /* * Use MultiByteToWideChar directly if there is a corresponding codepage, @@ -994,7 +1014,7 @@ pgwin32_toUTF16(const char *str, int len, int *utf16len) char *utf8; utf8 = (char *) pg_do_encoding_conversion((unsigned char *) str, - len, GetDatabaseEncoding(), PG_UTF8); + len, GetMessageEncoding(), PG_UTF8); if (utf8 != str) len = strlen(utf8); -- 1.7.10.4

view thread (19+ messages)  latest in thread

Message-ID: <5124BAC0.4060006@gmail.com>
Permalink:  ../5124BAC0.4060006@gmail.com/
Also on:    postgresql.org/message-id/5124BAC0.4060006@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com, noah@leadboat.com, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org, magnus@hagander.net, andrew@dunslane.net
  Subject: Re: BUG #7493: Postmaster messages unreadable in a Windows console
  In-Reply-To: <5124BAC0.4060006@gmail.com>
  References: <5100F3F6.3050107@2ndQuadrant.com> <51013C2C.5020703@dunslane.net> <20130124161954.GA2448@tornado.leadboat.com> <5101A1C4.3020407@dunslane.net> <5107656C.1050400@gmail.com> <28316.1359471244@sss.pgh.pa.us> <20130130015155.GD3524@tornado.leadboat.com> <5108B6E1.9070503@gmail.com> <20130210210259.GA7401@tornado.leadboat.com> <511C8E11.7090407@gmail.com> <20130214225957.GA5626@tornado.leadboat.com> <5124BAC0.4060006@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox