Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fr7w5-00029h-Gb for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Aug 2018 20:35:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fr7w3-0002u5-Tz for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Aug 2018 20:34:59 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fr7w3-0002ty-Jf for pgsql-hackers@lists.postgresql.org; Sat, 18 Aug 2018 20:34:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fr7w0-0005lg-62 for pgsql-hackers@lists.postgresql.org; Sat, 18 Aug 2018 20:34:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w7IKYoui013184; Sat, 18 Aug 2018 16:34:50 -0400 From: Tom Lane To: Thomas Munro cc: Alvaro Herrera , PostgreSQL Hackers Subject: Re: Allowing printf("%m") only where it actually works In-reply-to: <1437.1534100930@sss.pgh.pa.us> References: <20180528150125.j2x3mp62ssbeg3h5@alvherre.pgsql> <2685.1527520461@sss.pgh.pa.us> <8770.1533931511@sss.pgh.pa.us> <16896.1533935042@sss.pgh.pa.us> <14925.1534040609@sss.pgh.pa.us> <1437.1534100930@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 12 Aug 2018 15:08:50 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13182.1534624490.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 18 Aug 2018 16:34:50 -0400 Message-ID: <13183.1534624490@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > Consider the following approach: > 1. Teach src/port/snprintf.c about %m. While I've not written a patch > for this, it looks pretty trivial. > 2. Teach configure to test for %m and if it's not there, use the > replacement snprintf. (Note: we're already forcing snprintf replacement > in cross-compiles, so the added run-time test isn't losing anything.) > 3. Get rid of elog.c's hand-made substitution of %m strings, and instead > just let it pass the correct errno value down. (We'd likely need to do > some fooling in appendStringInfoVA and related functions to preserve > call-time errno, but that's not complicated, nor expensive.) > 4. (Optional) Get rid of strerror(errno) calls in favor of %m, even in > frontend code. So I started to hack on this, and soon noticed that actually, what elog.c replaces %m with is *not* the result of strerror(), it's the result of useful_strerror(). Which, primarily, does this: /* * Some strerror()s return an empty string for out-of-range errno. Th= is * is ANSI C spec compliant, but not exactly useful. Also, we may get * back strings of question marks if libc cannot transcode the message= to * the codeset specified by LC_CTYPE. If we get nothing useful, first= try * get_errno_symbol(), and if that fails, print the numeric errno. */ I don't know offhand whether glibc's implementation delivers anything useful for out-of-range errno, but I do know that we've seen the transcoding problem with it, cf commit 8e68816cc which arose from this discussion: https://www.postgresql.org/message-id/flat/2782A2665E8342DF8695F396DBA80C8= 8%40maumau We could easily move useful_strerror() into snprintf.c, I think (might need to move pgwin32_socket_strerror there too). But then we'd lose its functionality when using glibc. So now I'm about ready to propose that we just *always* use snprintf.c, and forget all of the related configure probing. This'd have some advantages, notably that we'd get the useful_strerror() behavior in frontend as well as backend, assuming we converted all our frontend code to use %m. And we'd not exactly be the first project to decide that. But it's kind of a big move from where we are today. Thoughts? regards, tom lane